From fc51bb6791530683d6c79f0edd4ee9fda052ce82 Mon Sep 17 00:00:00 2001 From: Sergei Trofimov Date: Tue, 29 Aug 2023 11:35:55 +0100 Subject: [PATCH] cocli: allow specifying api-server via config file Make api-server configurable via the config file, as well as the command line flag. This removes the need to specify --api-server flag on each corim submit sub-command invocation (given that this setting is going to be fairly static for a particular setup). Signed-off-by: Sergei Trofimov --- cocli/cmd/corimSubmit.go | 16 ++++++++++------ cocli/data/config/example-config.yaml | 3 +++ 2 files changed, 13 insertions(+), 6 deletions(-) diff --git a/cocli/cmd/corimSubmit.go b/cocli/cmd/corimSubmit.go index 86e262b1..f231d18e 100644 --- a/cocli/cmd/corimSubmit.go +++ b/cocli/cmd/corimSubmit.go @@ -16,8 +16,8 @@ import ( var ( corimFile *string - apiServer *string mediaType *string + apiServer string ) var ( @@ -54,7 +54,7 @@ func NewCorimSubmitCmd(submitter ISubmitter) *cobra.Command { return fmt.Errorf("read CoRIM payload failed: %w", err) } - if err = provisionData(data, submitter, *apiServer, *mediaType); err != nil { + if err = provisionData(data, submitter, apiServer, *mediaType); err != nil { return fmt.Errorf("submit CoRIM payload failed reason: %w", err) } return nil @@ -62,9 +62,9 @@ func NewCorimSubmitCmd(submitter ISubmitter) *cobra.Command { } corimFile = cmd.Flags().StringP("corim-file", "f", "", "name of the CoRIM file in CBOR format") - apiServer = cmd.Flags().StringP("api-server", "s", "", "API server where to submit the corim file") mediaType = cmd.Flags().StringP("media-type", "m", "", "media type of the CoRIM file") + cmd.Flags().StringP("api-server", "s", "", "API server where to submit the corim file") cmd.Flags().VarP(&authMethod, "auth", "a", `authentication method, must be one of "none"/"passthrough", "basic", "oauth2"`) cmd.Flags().StringP("client-id", "C", "", "OAuth2 client ID") @@ -73,7 +73,9 @@ func NewCorimSubmitCmd(submitter ISubmitter) *cobra.Command { cmd.Flags().StringP("username", "U", "", "service username") cmd.Flags().StringP("password", "P", "", "service password") - err := viper.BindPFlag("auth", cmd.Flags().Lookup("auth")) + err := viper.BindPFlag("api_server", cmd.Flags().Lookup("api-server")) + cobra.CheckErr(err) + err = viper.BindPFlag("auth", cmd.Flags().Lookup("auth")) cobra.CheckErr(err) err = viper.BindPFlag("client_id", cmd.Flags().Lookup("client-id")) cobra.CheckErr(err) @@ -93,10 +95,12 @@ func checkSubmitArgs() error { if corimFile == nil || *corimFile == "" { return errors.New("no CoRIM input file supplied") } - if apiServer == nil || *apiServer == "" { + + apiServer = viper.GetString("api_server") + if apiServer == "" { return errors.New("no API server supplied") } - u, err := url.Parse(*apiServer) + u, err := url.Parse(apiServer) if err != nil || !u.IsAbs() { return fmt.Errorf("malformed API server URL") } diff --git a/cocli/data/config/example-config.yaml b/cocli/data/config/example-config.yaml index 6b1c47f8..d067efbc 100644 --- a/cocli/data/config/example-config.yaml +++ b/cocli/data/config/example-config.yaml @@ -4,6 +4,9 @@ # do not need this configuration for creating or manipulating corims/corim and # related objects locally. +# API Server submit endpoint URL. +api_server: https://veraison.example/endorsement-provisioning/v1/submit + # Authentication method used by the remote service. auth: none # may also be "basic" or "oauth2"