Repository: datreeio/datree
Pull request #467 (2022-03-07 11:47:22)

feat: support-new-publish
Changed x-cli-id to x-token on request, need to approve cli-service and gateway before pushing this

shalev007: Approved by @shmuelsa 

Patch:
diff --git a/cmd/publish/main.go b/cmd/publish/main.go
index da7a81c..13f2ba1 100644
--- a/cmd/publish/main.go
+++ b/cmd/publish/main.go
@@ -24,7 +24,7 @@ type LocalConfig interface {
 }
 
 type CliClient interface {
-	PublishPolicies(policiesConfiguration files.UnknownStruct, cliId string) (*cliClient.PublishFailedResponse, error)
+	PublishPolicies(policiesConfiguration files.UnknownStruct, token string) (*cliClient.PublishFailedResponse, error)
 }
 
 type PublishCommandContext struct {
diff --git a/pkg/cliClient/publish.go b/pkg/cliClient/publish.go
index dc3d5ee..ee367b8 100644
--- a/pkg/cliClient/publish.go
+++ b/pkg/cliClient/publish.go
@@ -13,8 +13,8 @@ type PublishFailedResponse struct {
 	Payload []string `json:"payload"`
 }
 
-func (c *CliClient) PublishPolicies(policiesConfiguration files.UnknownStruct, cliId string) (*PublishFailedResponse, error) {
-	headers := map[string]string{"x-cli-id": cliId}
+func (c *CliClient) PublishPolicies(policiesConfiguration files.UnknownStruct, token string) (*PublishFailedResponse, error) {
+	headers := map[string]string{"x-datree-token": token}
 	res, publishErr := c.httpClient.Request(http.MethodPut, "/cli/policy/publish", policiesConfiguration, headers)
 	if publishErr != nil {
 		if res.StatusCode != 0 {


Test patch:
diff --git a/pkg/cliClient/cliClient_test.go b/pkg/cliClient/cliClient_test.go
index 0778cfa..8890449 100644
--- a/pkg/cliClient/cliClient_test.go
+++ b/pkg/cliClient/cliClient_test.go
@@ -103,7 +103,7 @@ type PublishPoliciesTestCase struct {
 	name string
 	args struct {
 		policiesConfiguration files.UnknownStruct
-		cliId                 string
+		token                 string
 	}
 	mockResponse struct {
 		status int
@@ -219,7 +219,7 @@ func TestPublishPolicies(t *testing.T) {
 				httpClient: &httpClientMock,
 			}
 
-			publishFailedResponse, err := client.PublishPolicies(tt.args.policiesConfiguration, tt.args.cliId)
+			publishFailedResponse, err := client.PublishPolicies(tt.args.policiesConfiguration, tt.args.token)
 			httpClientMock.AssertCalled(t, "Request", tt.expected.request.method, tt.expected.request.uri, tt.expected.request.body, tt.expected.request.headers)
 			assert.Equal(t, tt.expected.publishFailedResponse, publishFailedResponse)
 			assert.Equal(t, tt.expected.responseErr, err)
@@ -439,17 +439,17 @@ func test_createEvaluation_success() *CreateEvaluationTestCase {
 }
 
 func test_publishPolicies_success() *PublishPoliciesTestCase {
-	expectedPublishHeaders := map[string]string{"x-cli-id": "cli_id"}
+	expectedPublishHeaders := map[string]string{"x-datree-token": "token"}
 
 	requestPoliciesConfigurationArg := files.UnknownStruct{}
 	return &PublishPoliciesTestCase{
 		name: "success - publish policies",
 		args: struct {
 			policiesConfiguration files.UnknownStruct
-			cliId                 string
+			token                 string
 		}{
 			policiesConfiguration: requestPoliciesConfigurationArg,
-			cliId:                 "cli_id",
+			token:                 "token",
 		},
 		mockResponse: struct {
 			status int
@@ -492,17 +492,17 @@ func test_publishPolicies_success() *PublishPoliciesTestCase {
 }
 
 func test_publishPolicies_schemaError() *PublishPoliciesTestCase {
-	expectedPublishHeaders := map[string]string{"x-cli-id": "cli_id"}
+	expectedPublishHeaders := map[string]string{"x-datree-token": "token"}
 
 	requestPoliciesConfigurationArg := files.UnknownStruct{}
 	return &PublishPoliciesTestCase{
 		name: "schema error - publish policies",
 		args: struct {
 			policiesConfiguration files.UnknownStruct
-			cliId                 string
+			token                 string
 		}{
 			policiesConfiguration: requestPoliciesConfigurationArg,
-			cliId:                 "cli_id",
+			token:                 "token",
 		},
 		mockResponse: struct {
 			status int