Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[v2] Add component spec command to validate component specifications #510

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions internal/pkg/agent/cmd/common.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ func NewCommandWithArgs(args []string, streams *cli.IOStreams) *cobra.Command {
cmd.AddCommand(newContainerCommand(args, streams))
cmd.AddCommand(newStatusCommand(args, streams))
cmd.AddCommand(newDiagnosticsCommand(args, streams))
cmd.AddCommand(newComponentCommandWithArgs(args, streams))

// windows special hidden sub-command (only added on windows)
reexec := newReExecWindowsCommand(args, streams)
Expand Down
23 changes: 23 additions & 0 deletions internal/pkg/agent/cmd/component.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
// Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
// or more contributor license agreements. Licensed under the Elastic License;
// you may not use this file except in compliance with the Elastic License.

package cmd

import (
"github.com/spf13/cobra"

"github.com/elastic/elastic-agent/internal/pkg/cli"
)

func newComponentCommandWithArgs(args []string, streams *cli.IOStreams) *cobra.Command {
cmd := &cobra.Command{
Use: "component <subcommand>",
Short: "Tools to work on components",
Long: "Tools for viewing current component information and developing new components for Elastic Agent",
}

cmd.AddCommand(newComponentSpecCommandWithArgs(args, streams))

return cmd
}
39 changes: 39 additions & 0 deletions internal/pkg/agent/cmd/component_spec.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
// Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
// or more contributor license agreements. Licensed under the Elastic License;
// you may not use this file except in compliance with the Elastic License.

package cmd

import (
"fmt"
"io/ioutil"

"github.com/spf13/cobra"

"github.com/elastic/elastic-agent/pkg/component"

"github.com/elastic/elastic-agent/internal/pkg/cli"
)

func newComponentSpecCommandWithArgs(_ []string, streams *cli.IOStreams) *cobra.Command {
cmd := &cobra.Command{
Use: "spec [file]",
Short: "Validates a component specification",
Long: "Validates a component specification that instructs the Elastic Agent how it should be ran.",
Args: cobra.ExactArgs(1),
RunE: func(c *cobra.Command, args []string) error {
data, err := ioutil.ReadFile(args[0])
if err != nil {
return err
}
_, err = component.LoadSpec(data)
if err != nil {
return err
}
fmt.Fprintln(streams.Out, "Component specification is valid")
return nil
},
}

return cmd
}