codeartifact-gradle-plugin icon indicating copy to clipboard operation
codeartifact-gradle-plugin copied to clipboard

The token caching does not seem to work (at least not when using the plugin for allprojects from init.gradle.kts)

Open lestephane opened this issue 4 years ago • 2 comments

From looking at your code, I could see you intended to cache tokens for the lifetime of the plugin. But it seems that, despite the gradle daemon staying around, the plugin instance does not.

To test the hypothesis, I ran the same command twice, and expected the second one to not output anything (ie. no GetAuthorization, because the token from the first one is not expired yet).

$ gradle build --debug | grep "/v1/authorization-token"
2021-09-17T13:12:28.564+0200 [DEBUG] [software.amazon.awssdk.request] Sending Request: DefaultSdkHttpFullRequest(httpMethod=POST, protocol=https, host=codeartifact.eu-central-1.amazonaws.com, encodedPath=/v1/authorization-token, headers=[amz-sdk-invocation-id, User-Agent], queryParameters=[domain, domain-owner])
2021-09-17T13:12:28.674+0200 [DEBUG] [org.apache.http.impl.execchain.MainClientExec] Executing request POST /v1/authorization-token?domain=SCRUBBED&domain-owner=411628588745 HTTP/1.1
2:17
$ gradle build --debug | grep "/v1/authorization-token"
2021-09-17T13:12:34.989+0200 [DEBUG] [software.amazon.awssdk.request] Sending Request: DefaultSdkHttpFullRequest(httpMethod=POST, protocol=https, host=codeartifact.eu-central-1.amazonaws.com, encodedPath=/v1/authorization-token, headers=[amz-sdk-invocation-id, User-Agent], queryParameters=[domain, domain-owner])
2021-09-17T13:12:35.107+0200 [DEBUG] [org.apache.http.impl.execchain.MainClientExec] Executing request POST /v1/authorization-token?domain=SCRUBBED&domain-owner=411628588745 HTTP/1.1

lestephane avatar Sep 17 '21 11:09 lestephane

The intention of the plugin is just to reuse the token during the life of a command. Reuse the token in multiple references to the same repository.

I my experience using codeartifact, there is no problem in creating new tokens for each command execution (apart from the time taken to perform authentication).

We don't know how to reuse this information via Gradle daemon. Do you have experience?

jerolba avatar Sep 19 '21 09:09 jerolba

We don't know how to reuse this information via Gradle daemon. Do you have experience?

Unfortunately no. In the past I myself would export a code artifact token as environment variable through direnv's .envrc, so as to only generate one per shell lifetime, and I would start the IDE from that shell.

I'm indeed worried about potential request throttling. Time will tell.

lestephane avatar Sep 19 '21 13:09 lestephane