-
Notifications
You must be signed in to change notification settings - Fork 1.9k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
new approach for hiding Node.SecretID in the API, using
json
tag
documented this approach in the contributing guide refactored the JSON handlers with extensions modified event stream encoding to use the go-msgpack encoders with the extensions
- Loading branch information
Showing
5 changed files
with
28 additions
and
21 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
19 changes: 7 additions & 12 deletions
19
command/agent/json_encoding.go → nomad/structs/json_encoding.go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,37 +1,32 @@ | ||
package agent | ||
package structs | ||
|
||
import ( | ||
"reflect" | ||
|
||
"github.com/hashicorp/go-msgpack/codec" | ||
|
||
"github.com/hashicorp/nomad/nomad/structs" | ||
) | ||
|
||
// Special encoding for structs.Node, to perform the following: | ||
// 1. ensure that Node.SecretID is zeroed out | ||
// 2. provide backwards compatibility for the following fields: | ||
// 1. provide backwards compatibility for the following fields: | ||
// * Node.Drain | ||
type nodesExt struct{} | ||
|
||
// ConvertExt converts a structs.Node to an anonymous struct with the extra field, Drain | ||
func (n nodesExt) ConvertExt(v interface{}) interface{} { | ||
node := v.(*structs.Node) | ||
copy := node.Copy() | ||
copy.SecretID = "" | ||
node := v.(*Node) | ||
return struct { | ||
*structs.Node | ||
*Node | ||
Drain bool | ||
}{ | ||
Node: copy, | ||
Node: node, | ||
Drain: node.DrainStrategy != nil, | ||
} | ||
} | ||
|
||
// UpdateExt is not used | ||
func (n nodesExt) UpdateExt(_ interface{}, _ interface{}) {} | ||
|
||
func registerExtensions(h *codec.JsonHandle) *codec.JsonHandle { | ||
h.SetInterfaceExt(reflect.TypeOf(structs.Node{}), 1, nodesExt{}) | ||
func RegisterJSONEncodingExtensions(h *codec.JsonHandle) *codec.JsonHandle { | ||
h.SetInterfaceExt(reflect.TypeOf(Node{}), 1, nodesExt{}) | ||
return h | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters