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

process-user-data: move logic in pkgs #1674

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
64 changes: 36 additions & 28 deletions cmd/process-user-data/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,22 @@ import (
"os"

cmdUtil "github.com/confidential-containers/cloud-api-adaptor/cmd"
"github.com/confidential-containers/cloud-api-adaptor/pkg/agent"
daemon "github.com/confidential-containers/cloud-api-adaptor/pkg/forwarder"
"github.com/confidential-containers/cloud-api-adaptor/pkg/userdata"
"github.com/spf13/cobra"
)

const (
programName = "process-user-data"
providerAzure = "azure"
providerAws = "aws"

defaultAgentConfigPath = "/etc/agent-config.toml"
defaultAuthJsonPath = "/run/peerpod/auth.json"
)

var versionFlag bool
var rootCmd = &cobra.Command{
Use: programName,
Short: "A program to process user data and update agent config file",
Expand All @@ -23,40 +35,36 @@ var rootCmd = &cobra.Command{
},
}

var versionFlag bool
var provisionFilesCmd = &cobra.Command{
Use: "provision-files",
Short: "Provision required files based on user data",
RunE: provisionFiles,
SilenceUsage: true, // Silence usage on error
}

var updateAgentConfigCmd = &cobra.Command{
Use: "update-agent-config",
Short: "Update the agent configuration file",
RunE: updateAgentConfig,
SilenceUsage: true, // Silence usage on error
}

var cfg Config

func init() {
// set a fixed value for authJsonPath
cfg.authJsonPath = defaultAuthJsonFilePath
var agentConfigPath, daemonConfigPath string
var fetchTimeout int

rootCmd.PersistentFlags().BoolVarP(&versionFlag, "version", "v", false, "Print the version")
// Add a flag to specify the daemonConfigPath
rootCmd.PersistentFlags().StringVarP(&cfg.daemonConfigPath, "daemon-config-path", "d", daemon.DefaultConfigPath, "Path to a daemon config file")

// Add a flag to specify the timeout for fetching user data
provisionFilesCmd.Flags().IntVarP(&cfg.userDataFetchTimeout, "user-data-fetch-timeout", "t", 180, "Timeout (in secs) for fetching user data")
rootCmd.PersistentFlags().StringVarP(&daemonConfigPath, "daemon-config-path", "d", daemon.DefaultConfigPath, "Path to a daemon config file")

var provisionFilesCmd = &cobra.Command{
Use: "provision-files",
Short: "Provision required files based on user data",
RunE: func(_ *cobra.Command, _ []string) error {
cfg := userdata.NewConfig(defaultAuthJsonPath, daemonConfigPath, fetchTimeout)
return userdata.ProvisionFiles(cfg)
},
SilenceUsage: true, // Silence usage on error
}
provisionFilesCmd.Flags().IntVarP(&fetchTimeout, "user-data-fetch-timeout", "t", 180, "Timeout (in secs) for fetching user data")
rootCmd.AddCommand(provisionFilesCmd)

// Add a flag to specify the agentConfigPath to updateAgentConfigCmd subcommand
updateAgentConfigCmd.Flags().StringVarP(&cfg.agentConfigPath, "agent-config-file", "a", defaultAgentConfigPath, "Path to a agent config file")

var updateAgentConfigCmd = &cobra.Command{
Use: "update-agent-config",
Short: "Update the agent configuration file",
RunE: func(_ *cobra.Command, _ []string) error {
cfg := agent.NewConfig(agentConfigPath, defaultAuthJsonPath, daemonConfigPath)
return agent.UpdateConfig(cfg)
},
SilenceUsage: true, // Silence usage on error
}
updateAgentConfigCmd.Flags().StringVarP(&agentConfigPath, "agent-config-file", "a", defaultAgentConfigPath, "Path to a agent config file")
rootCmd.AddCommand(updateAgentConfigCmd)

}

func main() {
Expand Down
Loading
Loading