Skip to content

Commit b46d647

Browse files
chore: expose token provider / release 1.0.2
1 parent 5c4580b commit b46d647

File tree

4 files changed

+25
-7
lines changed

4 files changed

+25
-7
lines changed

README.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,12 @@ limit role permissions to those required for CodeArtifact.
8585
|--------------------------------------------------------------|--------------------------------------------------------------|---------------------------------------------------------------------------------------------|
8686
| codeartifact.domains | CODEARTIFACT_DOMAINS | Regex of domains to provide authentication for (defaults to all domains) |
8787

88+
## Obtaining CodeArtifact tokens for other (non-Maven repository) uses
89+
90+
If you wish to use CodeArtifact tokens elsehwere, for example configuring `.npmrc` for CodeArtifact npm repositories, you can obtain a token provider using `ProviderFactory.codeArtifactToken(endpoint)`.
91+
92+
```shell
93+
8894
## Advanced use
8995

9096
### As a Gradle plugin / custom Gradle distribution

gradle.properties

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ description=CodeArtifact settings plugin for Gradle
33
kotlin.code.style=official
44

55
group=io.cloudshiftdev.codeartifact
6-
version=1.0.1
6+
version=1.0.2
77

88
org.gradle.jvmargs=-Dfile.encoding\=UTF-8
99
org.gradle.vfs.watch=true

src/main/kotlin/io/cloudshiftdev/gradle/codeartifact/CodeArtifactEndpoint.kt

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ public interface CodeArtifactEndpoint {
1212
public val domainOwner: String
1313
public val region: String
1414
public val repository: String
15+
public val type: String
1516
public val url: URI
1617
public val name: String
1718
get() = "${domain}-${repository}".toPascalCase()
@@ -25,11 +26,12 @@ public interface CodeArtifactEndpoint {
2526
val urlString = url.toString()
2627
val match = regex.matchEntire(urlString) ?: return null
2728
return CodeArtifactEndpointImpl(
28-
match.groups["domain"]!!.value,
29-
match.groups["domainOwner"]!!.value,
30-
match.groups["region"]!!.value,
31-
match.groups["repository"]!!.value,
32-
URI(urlString),
29+
domain = match.groups["domain"]!!.value,
30+
domainOwner = match.groups["domainOwner"]!!.value,
31+
region = match.groups["region"]!!.value,
32+
repository = match.groups["repository"]!!.value,
33+
type = match.groups["type"]!!.value,
34+
url = URI(urlString),
3335
)
3436
}
3537

@@ -45,7 +47,7 @@ public interface CodeArtifactEndpoint {
4547

4648
// https://env-production-123456789012.d.codeartifact.eu-west-1.amazonaws.com/maven/env-data/com/abcd/xyz-sdk/1.22.3/xyz-sdk-1.22.3.pom
4749
private val regex =
48-
"""^https://(?<domain>.*?)-(?<domainOwner>[0-9].*?).d.codeartifact.(?<region>.+?).amazonaws.com/.+?/(?<repository>.+?)(?:/|\?.*|/\?.*)?$"""
50+
"""^https://(?<domain>.*?)-(?<domainOwner>[0-9].*?).d.codeartifact.(?<region>.+?).amazonaws.com/(?<type>.+?)/(?<repository>.+?)(?:/|\?.*|/\?.*)?$"""
4951
.toRegex()
5052
}
5153
}
@@ -59,6 +61,7 @@ internal data class CodeArtifactEndpointImpl(
5961
override val region: String,
6062
override val repository: String,
6163
override val url: URI,
64+
override val type: String,
6265
) : Serializable, CodeArtifactEndpoint {
6366

6467
@get:JsonIgnore

src/test/kotlin/io/cloudshiftdev/gradle/codeartifact/CodeArtifactEndpointTest.kt

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,5 +40,14 @@ class CodeArtifactEndpointTest : FunSpec() {
4040

4141
unmarshalledEndpoint.shouldBe(endpoint)
4242
}
43+
44+
test("url parsing works") {
45+
val endpoint = "https://my_domain-111122223333.d.codeartifact.us-west-2.amazonaws.com/npm/my_repo/".toCodeArtifactEndpoint()
46+
endpoint.domain.shouldBe("my_domain")
47+
endpoint.domainOwner.shouldBe("111122223333")
48+
endpoint.region.shouldBe("us-west-2")
49+
endpoint.repository.shouldBe("my_repo")
50+
endpoint.type.shouldBe("npm")
51+
}
4352
}
4453
}

0 commit comments

Comments
 (0)