Skip to content

Commit 1be058c

Browse files
authored
Refactor OIDC credential keys to remove 'oidc-' prefix for consistency (#99)
- Rename oidc-namespace to namespace - Rename oidc-service-slug to service-slug - Rename oidc-audience to audience - Add pull request template
1 parent 7180cde commit 1be058c

6 files changed

Lines changed: 115 additions & 87 deletions

File tree

.github/pull_request_template.md

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
### What are you trying to accomplish?
2+
3+
<!-- Provide both a what and a _why_ for the change. -->
4+
5+
<!-- What issues does this affect or fix? -->
6+
7+
### Anything you want to highlight for special attention from reviewers?
8+
9+
<!-- If there were multiple ways to approach the problem, why did you pick this one? -->
10+
11+
### How will you know you've accomplished your goal?
12+
13+
<!--
14+
* If you've reproduced an error, can you link to, or demonstrate the reproduction?
15+
* If you've added a new feature, how will you demonstrate it to others?
16+
* If you've refactored code, how will you demonstrate that the new code is functionally equivalent to the old code?
17+
-->
18+
19+
### Checklist
20+
21+
<!-- Before requesting review, please ensure that your pull request fulfills the following requirements: -->
22+
23+
- [ ] I have run the complete test suite to ensure all tests and linters pass.
24+
- [ ] I have thoroughly tested my code changes to ensure they work as expected, including adding additional tests for new functionality.
25+
- [ ] I have written clear and descriptive commit messages.
26+
- [ ] I have provided a detailed description of the changes in the pull request, including the problem it addresses, how it fixes the problem, and any relevant details about the implementation.
27+
- [ ] I have ensured that the code is well-documented and easy to understand.

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
/dependabot-proxy
22
/proxy
33
/config.json
4+
/tmp

internal/handlers/oidc_handling_test.go

Lines changed: 67 additions & 67 deletions
Original file line numberDiff line numberDiff line change
@@ -118,11 +118,11 @@ func TestOIDCURLsAreAuthenticated(t *testing.T) {
118118
},
119119
credentials: config.Credentials{
120120
config.Credential{
121-
"type": "cargo_registry",
122-
"url": "https://cloudsmith.example.com",
123-
"oidc-namespace": "space",
124-
"oidc-service-slug": "repo",
125-
"oidc-audience": "my-audience",
121+
"type": "cargo_registry",
122+
"url": "https://cloudsmith.example.com",
123+
"namespace": "space",
124+
"service-slug": "repo",
125+
"audience": "my-audience",
126126
},
127127
},
128128
urlMocks: []mockHttpRequest{},
@@ -213,11 +213,11 @@ func TestOIDCURLsAreAuthenticated(t *testing.T) {
213213
},
214214
credentials: config.Credentials{
215215
config.Credential{
216-
"type": "composer_repository",
217-
"registry": "https://cloudsmith.example.com",
218-
"oidc-namespace": "space",
219-
"oidc-service-slug": "repo",
220-
"oidc-audience": "my-audience",
216+
"type": "composer_repository",
217+
"registry": "https://cloudsmith.example.com",
218+
"namespace": "space",
219+
"service-slug": "repo",
220+
"audience": "my-audience",
221221
},
222222
},
223223
urlMocks: []mockHttpRequest{},
@@ -308,11 +308,11 @@ func TestOIDCURLsAreAuthenticated(t *testing.T) {
308308
},
309309
credentials: config.Credentials{
310310
config.Credential{
311-
"type": "docker_registry",
312-
"registry": "https://cloudsmith.example.com",
313-
"oidc-namespace": "space",
314-
"oidc-service-slug": "repo",
315-
"oidc-audience": "my-audience",
311+
"type": "docker_registry",
312+
"registry": "https://cloudsmith.example.com",
313+
"namespace": "space",
314+
"service-slug": "repo",
315+
"audience": "my-audience",
316316
},
317317
},
318318
urlMocks: []mockHttpRequest{},
@@ -402,11 +402,11 @@ func TestOIDCURLsAreAuthenticated(t *testing.T) {
402402
},
403403
credentials: config.Credentials{
404404
config.Credential{
405-
"type": "goproxy_server",
406-
"url": "https://cloudsmith.example.com",
407-
"oidc-namespace": "space",
408-
"oidc-service-slug": "repo",
409-
"oidc-audience": "my-audience",
405+
"type": "goproxy_server",
406+
"url": "https://cloudsmith.example.com",
407+
"namespace": "space",
408+
"service-slug": "repo",
409+
"audience": "my-audience",
410410
},
411411
},
412412
urlMocks: []mockHttpRequest{},
@@ -496,11 +496,11 @@ func TestOIDCURLsAreAuthenticated(t *testing.T) {
496496
},
497497
credentials: config.Credentials{
498498
config.Credential{
499-
"type": "helm_registry",
500-
"registry": "https://cloudsmith.example.com",
501-
"oidc-namespace": "space",
502-
"oidc-service-slug": "repo",
503-
"oidc-audience": "my-audience",
499+
"type": "helm_registry",
500+
"registry": "https://cloudsmith.example.com",
501+
"namespace": "space",
502+
"service-slug": "repo",
503+
"audience": "my-audience",
504504
},
505505
},
506506
urlMocks: []mockHttpRequest{},
@@ -590,11 +590,11 @@ func TestOIDCURLsAreAuthenticated(t *testing.T) {
590590
},
591591
credentials: config.Credentials{
592592
config.Credential{
593-
"type": "hex_repository",
594-
"url": "https://cloudsmith.example.com",
595-
"oidc-namespace": "space",
596-
"oidc-service-slug": "repo",
597-
"oidc-audience": "my-audience",
593+
"type": "hex_repository",
594+
"url": "https://cloudsmith.example.com",
595+
"namespace": "space",
596+
"service-slug": "repo",
597+
"audience": "my-audience",
598598
},
599599
},
600600
urlMocks: []mockHttpRequest{},
@@ -684,11 +684,11 @@ func TestOIDCURLsAreAuthenticated(t *testing.T) {
684684
},
685685
credentials: config.Credentials{
686686
config.Credential{
687-
"type": "maven_repository",
688-
"url": "https://cloudsmith.example.com",
689-
"oidc-namespace": "space",
690-
"oidc-service-slug": "repo",
691-
"oidc-audience": "my-audience",
687+
"type": "maven_repository",
688+
"url": "https://cloudsmith.example.com",
689+
"namespace": "space",
690+
"service-slug": "repo",
691+
"audience": "my-audience",
692692
},
693693
},
694694
urlMocks: []mockHttpRequest{},
@@ -778,11 +778,11 @@ func TestOIDCURLsAreAuthenticated(t *testing.T) {
778778
},
779779
credentials: config.Credentials{
780780
config.Credential{
781-
"type": "npm_registry",
782-
"url": "https://cloudsmith.example.com",
783-
"oidc-namespace": "space",
784-
"oidc-service-slug": "repo",
785-
"oidc-audience": "my-audience",
781+
"type": "npm_registry",
782+
"url": "https://cloudsmith.example.com",
783+
"namespace": "space",
784+
"service-slug": "repo",
785+
"audience": "my-audience",
786786
},
787787
},
788788
urlMocks: []mockHttpRequest{},
@@ -896,11 +896,11 @@ func TestOIDCURLsAreAuthenticated(t *testing.T) {
896896
},
897897
credentials: config.Credentials{
898898
config.Credential{
899-
"type": "nuget_feed",
900-
"url": "https://cloudsmith.example.com/v3/index.json",
901-
"oidc-namespace": "space",
902-
"oidc-service-slug": "repo",
903-
"oidc-audience": "my-audience",
899+
"type": "nuget_feed",
900+
"url": "https://cloudsmith.example.com/v3/index.json",
901+
"namespace": "space",
902+
"service-slug": "repo",
903+
"audience": "my-audience",
904904
},
905905
},
906906
urlMocks: []mockHttpRequest{
@@ -998,11 +998,11 @@ func TestOIDCURLsAreAuthenticated(t *testing.T) {
998998
},
999999
credentials: config.Credentials{
10001000
config.Credential{
1001-
"type": "pub_repository",
1002-
"url": "https://cloudsmith.example.com",
1003-
"oidc-namespace": "space",
1004-
"oidc-service-slug": "repo",
1005-
"oidc-audience": "my-audience",
1001+
"type": "pub_repository",
1002+
"url": "https://cloudsmith.example.com",
1003+
"namespace": "space",
1004+
"service-slug": "repo",
1005+
"audience": "my-audience",
10061006
},
10071007
},
10081008
urlMocks: []mockHttpRequest{},
@@ -1092,11 +1092,11 @@ func TestOIDCURLsAreAuthenticated(t *testing.T) {
10921092
},
10931093
credentials: config.Credentials{
10941094
config.Credential{
1095-
"type": "python_index",
1096-
"url": "https://cloudsmith.example.com",
1097-
"oidc-namespace": "space",
1098-
"oidc-service-slug": "repo",
1099-
"oidc-audience": "my-audience",
1095+
"type": "python_index",
1096+
"url": "https://cloudsmith.example.com",
1097+
"namespace": "space",
1098+
"service-slug": "repo",
1099+
"audience": "my-audience",
11001100
},
11011101
},
11021102
urlMocks: []mockHttpRequest{},
@@ -1187,12 +1187,12 @@ func TestOIDCURLsAreAuthenticated(t *testing.T) {
11871187
},
11881188
credentials: config.Credentials{
11891189
config.Credential{
1190-
"type": "rubygems_server",
1191-
"url": "https://cloudsmith.example.com",
1192-
"host": "https://cloudsmith.example.com",
1193-
"oidc-namespace": "space",
1194-
"oidc-service-slug": "repo",
1195-
"oidc-audience": "my-audience",
1190+
"type": "rubygems_server",
1191+
"url": "https://cloudsmith.example.com",
1192+
"host": "https://cloudsmith.example.com",
1193+
"namespace": "space",
1194+
"service-slug": "repo",
1195+
"audience": "my-audience",
11961196
},
11971197
},
11981198
urlMocks: []mockHttpRequest{},
@@ -1282,11 +1282,11 @@ func TestOIDCURLsAreAuthenticated(t *testing.T) {
12821282
},
12831283
credentials: config.Credentials{
12841284
config.Credential{
1285-
"type": "terraform_registry",
1286-
"url": "https://cloudsmith.example.com",
1287-
"oidc-namespace": "space",
1288-
"oidc-service-slug": "repo",
1289-
"oidc-audience": "my-audience",
1285+
"type": "terraform_registry",
1286+
"url": "https://cloudsmith.example.com",
1287+
"namespace": "space",
1288+
"service-slug": "repo",
1289+
"audience": "my-audience",
12901290
},
12911291
},
12921292
urlMocks: []mockHttpRequest{},
@@ -1352,7 +1352,7 @@ func TestOIDCURLsAreAuthenticated(t *testing.T) {
13521352
"expires_in": 3600
13531353
}`))
13541354
case "cloudsmith":
1355-
namespace := tc.credentials[0]["oidc-namespace"]
1355+
namespace := tc.credentials[0]["namespace"]
13561356
httpmock.RegisterResponder("POST", fmt.Sprintf("https://api.cloudsmith.io/openid/%s/", namespace),
13571357
httpmock.NewStringResponder(200, `{
13581358
"token": "__test_token__"

internal/oidc/oidc_credential.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -98,9 +98,9 @@ func CreateOIDCCredential(cred config.Credential) (*OIDCCredential, error) {
9898
domainOwner := cred.GetString("domain-owner")
9999

100100
// cloudsmith values
101-
orgName := cred.GetString("oidc-namespace")
102-
serviceSlug := cred.GetString("oidc-service-slug")
103-
cloudsmithAudience := cred.GetString("oidc-audience")
101+
orgName := cred.GetString("namespace")
102+
serviceSlug := cred.GetString("service-slug")
103+
cloudsmithAudience := cred.GetString("audience")
104104

105105
switch {
106106
case tenantID != "" && clientID != "":

internal/oidc/oidc_credential_test.go

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -271,9 +271,9 @@ func TestTryCreateOIDCCredential(t *testing.T) {
271271
{
272272
"cloudsmith",
273273
config.Credential{
274-
"oidc-namespace": "my-org",
275-
"oidc-service-slug": "my-service",
276-
"oidc-audience": "my-audience",
274+
"namespace": "my-org",
275+
"service-slug": "my-service",
276+
"audience": "my-audience",
277277
},
278278
&CloudsmithOIDCParameters{
279279
OrgName: "my-org",
@@ -285,10 +285,10 @@ func TestTryCreateOIDCCredential(t *testing.T) {
285285
{
286286
"cloudsmith with explicit values",
287287
config.Credential{
288-
"oidc-namespace": "my-org",
289-
"oidc-service-slug": "my-service",
290-
"api-host": "api.example.com",
291-
"oidc-audience": "my-audience",
288+
"namespace": "my-org",
289+
"service-slug": "my-service",
290+
"api-host": "api.example.com",
291+
"audience": "my-audience",
292292
},
293293
&CloudsmithOIDCParameters{
294294
OrgName: "my-org",
@@ -300,23 +300,23 @@ func TestTryCreateOIDCCredential(t *testing.T) {
300300
{
301301
"looks like cloudsmith but missing service slug and audience",
302302
config.Credential{
303-
"oidc-namespace": "my-org",
303+
"namespace": "my-org",
304304
},
305305
nil,
306306
},
307307
{
308308
"looks like cloudsmith but missing service slug",
309309
config.Credential{
310-
"oidc-namespace": "my-org",
311-
"oidc-audience": "my-audience",
310+
"namespace": "my-org",
311+
"audience": "my-audience",
312312
},
313313
nil,
314314
},
315315
{
316316
"looks like cloudsmith but missing audience",
317317
config.Credential{
318-
"oidc-namespace": "my-org",
319-
"oidc-service-slug": "my-service",
318+
"namespace": "my-org",
319+
"service-slug": "my-service",
320320
},
321321
nil,
322322
},

internal/oidc/oidc_registry_test.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -382,11 +382,11 @@ func mockCloudsmithOIDC(t *testing.T, namespace, token string) {
382382

383383
func cloudsmithCred(namespace, serviceSlug, audience, url string) config.Credential {
384384
return config.Credential{
385-
"type": "test_registry",
386-
"oidc-namespace": namespace,
387-
"oidc-service-slug": serviceSlug,
388-
"oidc-audience": audience,
389-
"url": url,
385+
"type": "test_registry",
386+
"namespace": namespace,
387+
"service-slug": serviceSlug,
388+
"audience": audience,
389+
"url": url,
390390
}
391391
}
392392

0 commit comments

Comments
 (0)