feat: agent metadata with custom collectors
This commit is contained in:
@ -26,7 +26,7 @@ func UpdateCommand() *cli.Command {
|
||||
},
|
||||
&cli.StringFlag{
|
||||
Name: "spec-data",
|
||||
Usage: "use `DATA` as spec data",
|
||||
Usage: "use `DATA` as spec data, '-' to read from STDIN",
|
||||
},
|
||||
&cli.BoolFlag{
|
||||
Name: "no-patch",
|
||||
@ -94,7 +94,17 @@ func UpdateCommand() *cli.Command {
|
||||
revision = specificRevision
|
||||
}
|
||||
|
||||
spec, err := client.UpdateAgentSpec(ctx.Context, agentID, specName, revision, specData)
|
||||
rawSpec := &spec.RawSpec{
|
||||
Name: specName,
|
||||
Revision: revision,
|
||||
Data: specData,
|
||||
}
|
||||
|
||||
if err := spec.Validate(ctx.Context, rawSpec); err != nil {
|
||||
return errors.WithStack(apierr.Wrap(err))
|
||||
}
|
||||
|
||||
spec, err := client.UpdateAgentSpec(ctx.Context, agentID, rawSpec)
|
||||
if err != nil {
|
||||
return errors.WithStack(apierr.Wrap(err))
|
||||
}
|
||||
@ -122,23 +132,30 @@ func assertSpecName(ctx *cli.Context) (spec.Name, error) {
|
||||
return spec.Name(specName), nil
|
||||
}
|
||||
|
||||
func assertSpecData(ctx *cli.Context) (any, error) {
|
||||
func assertSpecData(ctx *cli.Context) (map[string]any, error) {
|
||||
rawSpecData := ctx.String("spec-data")
|
||||
|
||||
if rawSpecData == "" {
|
||||
return nil, errors.New("flag 'spec-data' is required")
|
||||
}
|
||||
|
||||
var specData any
|
||||
var specData map[string]any
|
||||
|
||||
if err := json.Unmarshal([]byte(rawSpecData), &specData); err != nil {
|
||||
return nil, errors.WithStack(err)
|
||||
if rawSpecData == "-" {
|
||||
decoder := json.NewDecoder(os.Stdin)
|
||||
if err := decoder.Decode(&specData); err != nil {
|
||||
return nil, errors.WithStack(err)
|
||||
}
|
||||
} else {
|
||||
if err := json.Unmarshal([]byte(rawSpecData), &specData); err != nil {
|
||||
return nil, errors.WithStack(err)
|
||||
}
|
||||
}
|
||||
|
||||
return specData, nil
|
||||
}
|
||||
|
||||
func applyPatch(origin any, patch any) (any, error) {
|
||||
func applyPatch(origin any, patch any) (map[string]any, error) {
|
||||
originJSON, err := json.Marshal(origin)
|
||||
if err != nil {
|
||||
return nil, errors.WithStack(err)
|
||||
@ -154,7 +171,7 @@ func applyPatch(origin any, patch any) (any, error) {
|
||||
return nil, errors.WithStack(err)
|
||||
}
|
||||
|
||||
var specData any
|
||||
var specData map[string]any
|
||||
|
||||
if err := json.Unmarshal(result, &specData); err != nil {
|
||||
}
|
||||
|
Reference in New Issue
Block a user