Skip to content

Commit f355c66

Browse files
pditommasoclaude
andauthored
Rename authToken to apiKey and add configuration fallbacks (#9)
Co-authored-by: Claude <[email protected]>
1 parent 256b986 commit f355c66

File tree

4 files changed

+101
-11
lines changed

4 files changed

+101
-11
lines changed

README.md

Lines changed: 40 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -38,13 +38,50 @@ nextflowPlugin {
3838
3939
publishing {
4040
registry {
41-
url = 'https://plugins.nextflow.io/api'
42-
authToken = project.findProperty('registry_access_token')
41+
// Registry URL (optional, defaults to plugin-registry.seqera.io/api)
42+
url = 'https://plugin-registry.seqera.io/api'
43+
44+
// API key for authentication (required)
45+
apiKey = project.findProperty('npr.apiKey')
4346
}
4447
}
4548
}
4649
```
4750

51+
### Registry Configuration
52+
53+
The registry publishing configuration supports multiple ways to provide the URL and API key:
54+
55+
#### Registry URL
56+
The registry URL can be configured via (in order of priority):
57+
1. `nextflowPlugin.publishing.registry.url` in build.gradle
58+
2. Gradle property: `-Pnpr.apiUrl=https://your-registry.com/api`
59+
3. Environment variable: `NPR_API_URL=https://your-registry.com/api`
60+
4. Default: `https://plugin-registry.seqera.io/api`
61+
62+
#### API Key
63+
The API key can be configured via (in order of priority):
64+
1. `nextflowPlugin.publishing.registry.apiKey` in build.gradle
65+
2. Gradle property: `-Pnpr.apiKey=your-api-key`
66+
3. Environment variable: `NPR_API_KEY=your-api-key`
67+
68+
**Note:** The API key is required for publishing. If none is provided, the plugin will show an error with configuration instructions.
69+
70+
#### Example Configurations
71+
72+
Using gradle.properties:
73+
```properties
74+
npr.apiUrl=https://my-custom-registry.com/api
75+
npr.apiKey=your-secret-api-key
76+
```
77+
78+
Using environment variables:
79+
```bash
80+
export NPR_API_URL=https://my-custom-registry.com/api
81+
export NPR_API_KEY=your-secret-api-key
82+
./gradlew releasePlugin
83+
```
84+
4885
This will add some useful tasks to your Gradle build:
4986
* `assemble` - Compile the Nextflow plugin code and assemble it into a zip file
5087
* `installPlugin` - Copy the assembled plugin into your local Nextflow plugins dir
@@ -92,5 +129,5 @@ Then use this command:
92129

93130

94131
```
95-
./gradlew publishPlugins
132+
./gradlew releasePlugins
96133
```

src/main/groovy/io/nextflow/gradle/registry/RegistryClient.groovy

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,18 +15,18 @@ class RegistryClient {
1515
private final Gson gson = new Gson()
1616

1717
private final URI url
18-
private final String authToken
18+
private final String apiKey
1919

20-
RegistryClient(URI url, String authToken) {
20+
RegistryClient(URI url, String apiKey) {
2121
this.url = !url.toString().endsWith("/")
2222
? URI.create(url.toString() + "/")
2323
: url
24-
this.authToken = authToken
24+
this.apiKey = apiKey
2525
}
2626

2727
def publish(String id, String version, File file) {
2828
def req = new HttpPost(url.resolve("publish"))
29-
req.addHeader("Authorization", "Bearer ${authToken}")
29+
req.addHeader("Authorization", "Bearer ${apiKey}")
3030
req.setEntity(MultipartEntityBuilder.create()
3131
.addTextBody("id", id)
3232
.addTextBody("version", version)

src/main/groovy/io/nextflow/gradle/registry/RegistryPublishConfig.groovy

Lines changed: 56 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,14 +10,67 @@ class RegistryPublishConfig {
1010
/**
1111
* Location of the registry api
1212
*/
13-
String url = 'https://plugins.nextflow.io/api'
13+
String url
1414

1515
/**
16-
* Registry authentication token
16+
* Registry API key
1717
*/
18-
String authToken
18+
String apiKey
1919

2020
RegistryPublishConfig(Project project) {
2121
this.project = project
2222
}
23+
24+
/**
25+
* Get the registry URL, checking fallbacks if not explicitly set
26+
*/
27+
String getResolvedUrl() {
28+
// If explicitly set, use it
29+
if (url) {
30+
return url
31+
}
32+
33+
// Try gradle property
34+
def gradleProp = project.findProperty('npr.apiUrl')
35+
if (gradleProp) {
36+
return gradleProp.toString()
37+
}
38+
39+
// Try environment variable
40+
def envVar = System.getenv('NPR_API_URL')
41+
if (envVar) {
42+
return envVar
43+
}
44+
45+
// Default URL
46+
return 'https://plugin-registry.seqera.io/api'
47+
}
48+
49+
/**
50+
* Get the API key, checking fallbacks if not explicitly set
51+
*/
52+
String getResolvedApiKey() {
53+
// If explicitly set, use it
54+
if (apiKey) {
55+
return apiKey
56+
}
57+
58+
// Try gradle property
59+
def gradleProp = project.findProperty('npr.apiKey')
60+
if (gradleProp) {
61+
return gradleProp.toString()
62+
}
63+
64+
// Try environment variable
65+
def envVar = System.getenv('NPR_API_KEY')
66+
if (envVar) {
67+
return envVar
68+
}
69+
70+
// No API key found
71+
throw new RuntimeException('Registry API key not provided. Set it via:\n' +
72+
' - nextflowPlugin.publishing.registry.apiKey in build.gradle\n' +
73+
' - gradle property: npr.apiKey\n' +
74+
' - environment variable: NPR_API_KEY')
75+
}
2376
}

src/main/groovy/io/nextflow/gradle/registry/RegistryUploadTask.groovy

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ class RegistryUploadTask extends DefaultTask {
3030
final plugin = project.extensions.getByType(NextflowPluginConfig)
3131
final config = plugin.publishing.registry
3232

33-
def client = new RegistryClient(new URI(config.url), config.authToken)
33+
def client = new RegistryClient(new URI(config.getResolvedUrl()), config.getResolvedApiKey())
3434
client.publish(project.name, version, project.file(zipFile))
3535
}
3636
}

0 commit comments

Comments
 (0)