diff --git a/internal/command/delta.go b/internal/command/delta.go index 9d8a55e..2848a07 100644 --- a/internal/command/delta.go +++ b/internal/command/delta.go @@ -39,7 +39,7 @@ func init() { deltaCmd.MarkFlagRequired("env") deltaCmd.Flags().StringArrayVarP(&overrideParams, "property", "p", nil, "Overrides selected property value") - deltaCmd.Flags().StringVar(&message, "message", "m", messageDefault, "Message") + deltaCmd.Flags().StringVarP(&message, "message", "m", messageDefault, "Message") deltaCmd.Flags().BoolVar(&deploy, "deploy", false, "Trigger a new delta deployment at the end") deltaCmd.Flags().BoolVar(&retry, "retry", false, "Retry deployments when a deployment is currently in progress") diff --git a/internal/command/run.go b/internal/command/run.go index 798e657..c8dc2c9 100644 --- a/internal/command/run.go +++ b/internal/command/run.go @@ -39,7 +39,7 @@ func init() { runCmd.MarkFlagRequired("env") runCmd.Flags().StringArrayVarP(&overrideParams, "property", "p", nil, "Overrides selected property value") - runCmd.Flags().StringVar(&message, "message", "m", messageDefault, "Message") + runCmd.Flags().StringVarP(&message, "message", "m", messageDefault, "Message") runCmd.Flags().BoolVar(&skipValidation, "skip-validation", false, "DEPRECATED: Disables Score file schema validation.") runCmd.Flags().BoolVar(&verbose, "verbose", false, "Enable diagnostic messages (written to STDERR)") diff --git a/internal/humanitec_go/client/client.go b/internal/humanitec_go/client/client.go index 3feaf47..05cb3a0 100644 --- a/internal/humanitec_go/client/client.go +++ b/internal/humanitec_go/client/client.go @@ -8,14 +8,21 @@ The Apache Software Foundation (http://www.apache.org/). package client import ( + "fmt" "net/http" + "github.com/score-spec/score-humanitec/internal/version" "github.com/sendgrid/rest" ) +var ( + ScoreUserAgent = fmt.Sprintf("score-humanitec/%s", version.Version) +) + type apiClient struct { - baseUrl string - token string + baseUrl string + token string + humanitecUserAgent string client *rest.Client } @@ -23,8 +30,9 @@ type apiClient struct { // NewClient constructs new Humanitec API client. func NewClient(url, token string, httpClient *http.Client) (Client, error) { return &apiClient{ - baseUrl: url, - token: token, + baseUrl: url, + token: token, + humanitecUserAgent: fmt.Sprintf("app %s; sdk %s", ScoreUserAgent, ScoreUserAgent), client: &rest.Client{ HTTPClient: httpClient, diff --git a/internal/humanitec_go/client/deltas.go b/internal/humanitec_go/client/deltas.go index 9ba7a55..29703b5 100644 --- a/internal/humanitec_go/client/deltas.go +++ b/internal/humanitec_go/client/deltas.go @@ -32,9 +32,10 @@ func (api *apiClient) CreateDelta(ctx context.Context, orgID, appID string, delt Method: http.MethodPost, BaseURL: api.baseUrl + apiPath, Headers: map[string]string{ - "Authorization": "Bearer " + api.token, - "Content-Type": "application/json", - "Accept": "application/json", + "Authorization": "Bearer " + api.token, + "Content-Type": "application/json", + "Accept": "application/json", + "Humanitec-User-Agent": api.humanitecUserAgent, }, Body: data, } @@ -76,9 +77,10 @@ func (api *apiClient) UpdateDelta(ctx context.Context, orgID string, appID strin Method: http.MethodPatch, BaseURL: api.baseUrl + apiPath, Headers: map[string]string{ - "Authorization": "Bearer " + api.token, - "Content-Type": "application/json", - "Accept": "application/json", + "Authorization": "Bearer " + api.token, + "Content-Type": "application/json", + "Accept": "application/json", + "Humanitec-User-Agent": api.humanitecUserAgent, }, Body: buf.Bytes(), } diff --git a/internal/humanitec_go/client/deltas_test.go b/internal/humanitec_go/client/deltas_test.go index 4016bd7..1df7870 100644 --- a/internal/humanitec_go/client/deltas_test.go +++ b/internal/humanitec_go/client/deltas_test.go @@ -57,7 +57,7 @@ func TestCreateDelta(t *testing.T) { Response: []byte(`{ "id": "qwe...rty", "metadata": { "env_id": "test", "name": "Test delta" }, - "modules": { + "modules": { "add": { "module-01": { "image": "busybox", "variables": { "TEST": "" } } } } }`), @@ -111,6 +111,7 @@ func TestCreateDelta(t *testing.T) { assert.Equal(t, []string{"Bearer " + apiToken}, r.Header["Authorization"]) assert.Equal(t, []string{"application/json"}, r.Header["Accept"]) assert.Equal(t, []string{"application/json"}, r.Header["Content-Type"]) + assert.Equal(t, []string{"app score-humanitec/0.0.0; sdk score-humanitec/0.0.0"}, r.Header["Humanitec-User-Agent"]) if tt.Data != nil { var body humanitec.CreateDeploymentDeltaRequest @@ -168,6 +169,7 @@ func TestUpdateDelta_success(t *testing.T) { assert.Equal(t, []string{"Bearer " + apiToken}, r.Header["Authorization"]) assert.Equal(t, []string{"application/json"}, r.Header["Accept"]) assert.Equal(t, []string{"application/json"}, r.Header["Content-Type"]) + assert.Equal(t, []string{"app score-humanitec/0.0.0; sdk score-humanitec/0.0.0"}, r.Header["Humanitec-User-Agent"]) var body []*humanitec.UpdateDeploymentDeltaRequest var dec = json.NewDecoder(r.Body) assert.NoError(t, dec.Decode(&body)) diff --git a/internal/humanitec_go/client/deployments.go b/internal/humanitec_go/client/deployments.go index b30a475..812afb5 100644 --- a/internal/humanitec_go/client/deployments.go +++ b/internal/humanitec_go/client/deployments.go @@ -35,9 +35,10 @@ func (api *apiClient) StartDeployment(ctx context.Context, orgID, appID, envID s Method: http.MethodPost, BaseURL: api.baseUrl + apiPath, Headers: map[string]string{ - "Authorization": "Bearer " + api.token, - "Content-Type": "application/json", - "Accept": "application/json", + "Authorization": "Bearer " + api.token, + "Content-Type": "application/json", + "Accept": "application/json", + "Humanitec-User-Agent": api.humanitecUserAgent, }, Body: data, } diff --git a/internal/humanitec_go/client/deployments_test.go b/internal/humanitec_go/client/deployments_test.go index 3f338f2..c4970eb 100644 --- a/internal/humanitec_go/client/deployments_test.go +++ b/internal/humanitec_go/client/deployments_test.go @@ -149,6 +149,7 @@ func TestStartDeployment(t *testing.T) { assert.Equal(t, []string{"Bearer " + apiToken}, r.Header["Authorization"]) assert.Equal(t, []string{"application/json"}, r.Header["Accept"]) assert.Equal(t, []string{"application/json"}, r.Header["Content-Type"]) + assert.Equal(t, []string{"app score-humanitec/0.0.0; sdk score-humanitec/0.0.0"}, r.Header["Humanitec-User-Agent"]) if tt.Data != nil { var body humanitec.StartDeploymentRequest diff --git a/internal/humanitec_go/client/resources.go b/internal/humanitec_go/client/resources.go index bcb3b05..6a052e7 100644 --- a/internal/humanitec_go/client/resources.go +++ b/internal/humanitec_go/client/resources.go @@ -25,8 +25,9 @@ func (api *apiClient) ListResourceTypes(ctx context.Context, orgID string) ([]hu Method: http.MethodGet, BaseURL: api.baseUrl + apiPath, Headers: map[string]string{ - "Authorization": "Bearer " + api.token, - "Accept": "application/json", + "Authorization": "Bearer " + api.token, + "Accept": "application/json", + "Humanitec-User-Agent": api.humanitecUserAgent, }, } diff --git a/internal/humanitec_go/client/resources_test.go b/internal/humanitec_go/client/resources_test.go index 3b953bc..aaf1e20 100644 --- a/internal/humanitec_go/client/resources_test.go +++ b/internal/humanitec_go/client/resources_test.go @@ -111,6 +111,7 @@ func TestListResourceTypes(t *testing.T) { } assert.Equal(t, []string{"Bearer " + apiToken}, r.Header["Authorization"]) assert.Equal(t, []string{"application/json"}, r.Header["Accept"]) + assert.Equal(t, []string{"app score-humanitec/0.0.0; sdk score-humanitec/0.0.0"}, r.Header["Humanitec-User-Agent"]) w.WriteHeader(tt.StatusCode) if len(tt.Response) > 0 {