Skip to content

Commit 28a3be8

Browse files
authored
Merge pull request #1176 from CircleCI-Public/change-policy-url
updates policy urls to use public endpoints at circleci.com
2 parents d4caa93 + 9983f4b commit 28a3be8

13 files changed

+66
-66
lines changed

api/policy/policy.go

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ func (c Client) CreatePolicyBundle(ownerID string, context string, request Creat
4848
return nil, fmt.Errorf("failed to encode policy payload: %w", err)
4949
}
5050

51-
req, err := http.NewRequest(http.MethodPost, fmt.Sprintf("%s/api/v1/owner/%s/context/%s/policy-bundle", c.serverUrl, ownerID, context), bytes.NewReader(data))
51+
req, err := http.NewRequest(http.MethodPost, fmt.Sprintf("%s/api/v2/owner/%s/context/%s/policy-bundle", c.serverUrl, ownerID, context), bytes.NewReader(data))
5252
if err != nil {
5353
return nil, fmt.Errorf("failed to construct request: %v", err)
5454
}
@@ -87,7 +87,7 @@ func (c Client) CreatePolicyBundle(ownerID string, context string, request Creat
8787
// If policyName is empty, the full policy bundle would be fetched for given ownerID+context
8888
// If a policyName is provided, only that matching policy would be fetched for given ownerID+context+policyName
8989
func (c Client) FetchPolicyBundle(ownerID, context, policyName string) (interface{}, error) {
90-
req, err := http.NewRequest("GET", fmt.Sprintf("%s/api/v1/owner/%s/context/%s/policy-bundle/%s", c.serverUrl, ownerID, context, policyName), nil)
90+
req, err := http.NewRequest("GET", fmt.Sprintf("%s/api/v2/owner/%s/context/%s/policy-bundle/%s", c.serverUrl, ownerID, context, policyName), nil)
9191
if err != nil {
9292
return nil, fmt.Errorf("failed to construct request: %v", err)
9393
}
@@ -126,7 +126,7 @@ type DecisionQueryRequest struct {
126126
// GetDecisionLogs calls the GET decision query API of policy-service. The endpoint accepts multiple filter values as
127127
// path query parameters (start-time, end-time, branch-name, project-id and offset).
128128
func (c Client) GetDecisionLogs(ownerID string, context string, request DecisionQueryRequest) ([]interface{}, error) {
129-
req, err := http.NewRequest("GET", fmt.Sprintf("%s/api/v1/owner/%s/context/%s/decision", c.serverUrl, ownerID, context), nil)
129+
req, err := http.NewRequest("GET", fmt.Sprintf("%s/api/v2/owner/%s/context/%s/decision", c.serverUrl, ownerID, context), nil)
130130
if err != nil {
131131
return nil, fmt.Errorf("failed to construct request: %v", err)
132132
}
@@ -178,7 +178,7 @@ func (c Client) GetDecisionLogs(ownerID string, context string, request Decision
178178
// GetDecisionLog calls the GET decision query API of policy-service for a DecisionID.
179179
// It also accepts a policyBundle bool param; If set to true will return only the policy bundle corresponding to that decision log.
180180
func (c Client) GetDecisionLog(ownerID string, context string, decisionID string, policyBundle bool) (interface{}, error) {
181-
path := fmt.Sprintf("%s/api/v1/owner/%s/context/%s/decision/%s", c.serverUrl, ownerID, context, decisionID)
181+
path := fmt.Sprintf("%s/api/v2/owner/%s/context/%s/decision/%s", c.serverUrl, ownerID, context, decisionID)
182182
if policyBundle {
183183
path += "/policy-bundle"
184184
}
@@ -218,7 +218,7 @@ type DecisionRequest struct {
218218

219219
// GetSettings calls the GET decision-settings API of policy-service.
220220
func (c Client) GetSettings(ownerID string, context string) (interface{}, error) {
221-
path := fmt.Sprintf("%s/api/v1/owner/%s/context/%s/decision/settings", c.serverUrl, ownerID, context)
221+
path := fmt.Sprintf("%s/api/v2/owner/%s/context/%s/decision/settings", c.serverUrl, ownerID, context)
222222
req, err := http.NewRequest("GET", path, nil)
223223
if err != nil {
224224
return nil, fmt.Errorf("failed to construct request: %v", err)
@@ -257,7 +257,7 @@ func (c Client) SetSettings(ownerID string, context string, request DecisionSett
257257
if err != nil {
258258
return nil, fmt.Errorf("failed to marshal request: %w", err)
259259
}
260-
path := fmt.Sprintf("%s/api/v1/owner/%s/context/%s/decision/settings", c.serverUrl, ownerID, context)
260+
path := fmt.Sprintf("%s/api/v2/owner/%s/context/%s/decision/settings", c.serverUrl, ownerID, context)
261261
req, err := http.NewRequest("PATCH", path, bytes.NewReader(payload))
262262
if err != nil {
263263
return nil, fmt.Errorf("failed to construct request: %v", err)
@@ -292,7 +292,7 @@ func (c Client) MakeDecision(ownerID string, context string, req DecisionRequest
292292
return nil, fmt.Errorf("failed to marshal request: %w", err)
293293
}
294294

295-
endpoint := fmt.Sprintf("%s/api/v1/owner/%s/context/%s/decision", c.serverUrl, ownerID, context)
295+
endpoint := fmt.Sprintf("%s/api/v2/owner/%s/context/%s/decision", c.serverUrl, ownerID, context)
296296

297297
request, err := http.NewRequest("POST", endpoint, bytes.NewReader(payload))
298298
if err != nil {

api/policy/policy_test.go

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ func TestClientFetchPolicyBundle(t *testing.T) {
2626
assert.Equal(t, r.Header.Get("circle-token"), "testtoken")
2727

2828
assert.Equal(t, r.Method, "GET")
29-
assert.Equal(t, r.URL.Path, "/api/v1/owner/ownerId/context/config/policy-bundle/my_policy")
29+
assert.Equal(t, r.URL.Path, "/api/v2/owner/ownerId/context/config/policy-bundle/my_policy")
3030

3131
w.WriteHeader(http.StatusOK)
3232
_, err := w.Write([]byte("{}"))
@@ -147,7 +147,7 @@ func TestClientCreatePolicy(t *testing.T) {
147147
assert.Equal(t, r.Header.Get("circle-token"), "testtoken")
148148

149149
assert.Equal(t, r.Method, "POST")
150-
assert.Equal(t, r.URL.Path, "/api/v1/owner/ownerId/context/config/policy-bundle")
150+
assert.Equal(t, r.URL.Path, "/api/v2/owner/ownerId/context/config/policy-bundle")
151151

152152
var actual CreatePolicyBundleRequest
153153
assert.NilError(t, json.NewDecoder(r.Body).Decode(&actual))
@@ -179,7 +179,7 @@ func TestClientCreatePolicy(t *testing.T) {
179179
assert.Equal(t, r.Header.Get("circle-token"), "testtoken")
180180

181181
assert.Equal(t, r.Method, "POST")
182-
assert.Equal(t, r.URL.Path, "/api/v1/owner/ownerId/context/config/policy-bundle")
182+
assert.Equal(t, r.URL.Path, "/api/v2/owner/ownerId/context/config/policy-bundle")
183183
assert.Equal(t, r.URL.RawQuery, "dry=true")
184184

185185
var actual CreatePolicyBundleRequest
@@ -225,8 +225,8 @@ func TestClientGetDecisionLogs(t *testing.T) {
225225
assert.Equal(t, r.Header.Get("circle-token"), "testtoken")
226226

227227
assert.Equal(t, r.Method, "GET")
228-
assert.Equal(t, r.URL.Path, "/api/v1/owner/ownerId/context/config/decision")
229-
assert.Equal(t, r.URL.String(), "/api/v1/owner/ownerId/context/config/decision")
228+
assert.Equal(t, r.URL.Path, "/api/v2/owner/ownerId/context/config/decision")
229+
assert.Equal(t, r.URL.String(), "/api/v2/owner/ownerId/context/config/decision")
230230

231231
w.WriteHeader(http.StatusOK)
232232
_, err := w.Write([]byte("[]"))
@@ -250,7 +250,7 @@ func TestClientGetDecisionLogs(t *testing.T) {
250250
assert.Equal(t, r.Header.Get("circle-token"), "testtoken")
251251

252252
assert.Equal(t, r.Method, "GET")
253-
assert.Equal(t, r.URL.Path, "/api/v1/owner/ownerId/context/config/decision")
253+
assert.Equal(t, r.URL.Path, "/api/v2/owner/ownerId/context/config/decision")
254254
assert.Equal(t, r.URL.RawQuery, "project_id=projectIDValue")
255255

256256
w.WriteHeader(http.StatusOK)
@@ -277,7 +277,7 @@ func TestClientGetDecisionLogs(t *testing.T) {
277277
assert.Equal(t, r.Header.Get("circle-token"), "testtoken")
278278

279279
assert.Equal(t, r.Method, "GET")
280-
assert.Equal(t, r.URL.Path, "/api/v1/owner/ownerId/context/config/decision")
280+
assert.Equal(t, r.URL.Path, "/api/v2/owner/ownerId/context/config/decision")
281281
assert.Equal(
282282
t,
283283
r.URL.RawQuery,
@@ -423,8 +423,8 @@ func TestClientGetDecisionLog(t *testing.T) {
423423
assert.Equal(t, r.Header.Get("circle-token"), "testtoken")
424424

425425
assert.Equal(t, r.Method, "GET")
426-
assert.Equal(t, r.URL.Path, "/api/v1/owner/ownerId/context/config/decision/decisionID")
427-
assert.Equal(t, r.URL.String(), "/api/v1/owner/ownerId/context/config/decision/decisionID")
426+
assert.Equal(t, r.URL.Path, "/api/v2/owner/ownerId/context/config/decision/decisionID")
427+
assert.Equal(t, r.URL.String(), "/api/v2/owner/ownerId/context/config/decision/decisionID")
428428

429429
w.WriteHeader(http.StatusOK)
430430
_, err := w.Write([]byte("[]"))
@@ -448,8 +448,8 @@ func TestClientGetDecisionLog(t *testing.T) {
448448
assert.Equal(t, r.Header.Get("circle-token"), "testtoken")
449449

450450
assert.Equal(t, r.Method, "GET")
451-
assert.Equal(t, r.URL.Path, "/api/v1/owner/ownerId/context/config/decision/decisionID/policy-bundle")
452-
assert.Equal(t, r.URL.String(), "/api/v1/owner/ownerId/context/config/decision/decisionID/policy-bundle")
451+
assert.Equal(t, r.URL.Path, "/api/v2/owner/ownerId/context/config/decision/decisionID/policy-bundle")
452+
assert.Equal(t, r.URL.String(), "/api/v2/owner/ownerId/context/config/decision/decisionID/policy-bundle")
453453

454454
w.WriteHeader(http.StatusOK)
455455
_, err := w.Write([]byte("[]"))
@@ -567,7 +567,7 @@ func TestMakeDecision(t *testing.T) {
567567
Input: "test-input",
568568
},
569569
Handler: func(w http.ResponseWriter, r *http.Request) {
570-
assert.Equal(t, r.URL.Path, "/api/v1/owner/test-owner/context/config/decision")
570+
assert.Equal(t, r.URL.Path, "/api/v2/owner/test-owner/context/config/decision")
571571
assert.Equal(t, r.Method, "POST")
572572
assert.Equal(t, r.Header.Get("Circle-Token"), "test-token")
573573

@@ -645,7 +645,7 @@ func TestGetSettings(t *testing.T) {
645645
Name: "gets expected response",
646646
OwnerID: "test-owner",
647647
Handler: func(w http.ResponseWriter, r *http.Request) {
648-
assert.Equal(t, r.URL.Path, "/api/v1/owner/test-owner/context/config/decision/settings")
648+
assert.Equal(t, r.URL.Path, "/api/v2/owner/test-owner/context/config/decision/settings")
649649
assert.Equal(t, r.Method, "GET")
650650
assert.Equal(t, r.Header.Get("Circle-Token"), "test-token")
651651
_ = json.NewEncoder(w).Encode(interface{}(`{"enabled": true}`))
@@ -718,7 +718,7 @@ func TestSetSettings(t *testing.T) {
718718
OwnerID: "test-owner",
719719
Settings: DecisionSettings{Enabled: &trueVar},
720720
Handler: func(w http.ResponseWriter, r *http.Request) {
721-
assert.Equal(t, r.URL.Path, "/api/v1/owner/test-owner/context/config/decision/settings")
721+
assert.Equal(t, r.URL.Path, "/api/v2/owner/test-owner/context/config/decision/settings")
722722
assert.Equal(t, r.Method, "PATCH")
723723
assert.Equal(t, r.Header.Get("Circle-Token"), "test-token")
724724
var payload map[string]interface{}
@@ -736,7 +736,7 @@ func TestSetSettings(t *testing.T) {
736736
OwnerID: "test-owner",
737737
Settings: DecisionSettings{Enabled: &falseVar},
738738
Handler: func(w http.ResponseWriter, r *http.Request) {
739-
assert.Equal(t, r.URL.Path, "/api/v1/owner/test-owner/context/config/decision/settings")
739+
assert.Equal(t, r.URL.Path, "/api/v2/owner/test-owner/context/config/decision/settings")
740740
assert.Equal(t, r.Method, "PATCH")
741741
assert.Equal(t, r.Header.Get("Circle-Token"), "test-token")
742742
var payload map[string]interface{}
@@ -754,7 +754,7 @@ func TestSetSettings(t *testing.T) {
754754
OwnerID: "test-owner",
755755
Settings: DecisionSettings{Enabled: nil},
756756
Handler: func(w http.ResponseWriter, r *http.Request) {
757-
assert.Equal(t, r.URL.Path, "/api/v1/owner/test-owner/context/config/decision/settings")
757+
assert.Equal(t, r.URL.Path, "/api/v2/owner/test-owner/context/config/decision/settings")
758758
assert.Equal(t, r.Method, "PATCH")
759759
assert.Equal(t, r.Header.Get("Circle-Token"), "test-token")
760760
var payload map[string]interface{}

cmd/policy/policy.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ func NewCommand(globalConfig *settings.Config, preRunE validator.Validator) *cob
5151
This group of commands allows the management of polices to be verified against build configs.`,
5252
}
5353

54-
policyBaseURL := cmd.PersistentFlags().String("policy-base-url", "https://internal.circleci.com", "base url for policy api")
54+
policyBaseURL := cmd.PersistentFlags().String("policy-base-url", "https://circleci.com", "base url for policy api")
5555

5656
push := func() *cobra.Command {
5757
var ownerID, context string

0 commit comments

Comments
 (0)