Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[FSN-13] feat(nf-tower): Retrieve and set Fusion license tokens in a process environment #5614

Open
wants to merge 12 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ class FusionConfig {

final static public String FUSION_PATH = '/usr/bin/fusion'

final static private PRODUCT_NAME = 'fusion'
final static private Pattern VERSION_JSON = ~/https:\/\/.*\/releases\/v(\d+(?:\.\w+)*)-(\w*)\.json$/

final private Boolean enabled
Expand Down Expand Up @@ -122,6 +123,17 @@ class FusionConfig {
return null
}

/**
* Return the Fusion SKU string
*
* @return A string representing the Fusion SKU
*/
String sku() {
return enabled
? PRODUCT_NAME
: null
}

String version() {
return enabled
? retrieveFusionVersion(this.containerConfigUrl ?: DEFAULT_FUSION_AMD64_URL)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
package nextflow.platform

import groovy.transform.CompileStatic

/**
* Helper methods for Platform-related operations
*
* @author Alberto Miranda <[email protected]>
*/
@CompileStatic
class PlatformHelper {

/**
* Get the configured Platform API endpoint: if the endpoint is not provided in the configuration, we fallback to the
* environment variable `TOWER_API_ENDPOINT`. If neither is provided, we fallback to the default endpoint.
*
* @param opts the configuration options for Platform (e.g. `session.config.navigate('tower')`)
* @param env the applicable environment variables
* @return the Platform API endpoint
*/
static String getEndpoint(Map opts, Map<String,String> env) {
def result = opts.endpoint as String
if( !result || result=='-' )
result = env.get('TOWER_API_ENDPOINT') ?: 'https://api.cloud.seqera.io'
return result.stripEnd('/')
}

/**
* Return the configured Platform access token: if `TOWER_WORKFLOW_ID` is provided in the environment, it means
* we are running in a Platform-made run and we should ONLY retrieve the token from the environment. Otherwise,
* check the configuration or fallback to the environment. If no token is found, return null.
*
* @param opts the configuration options for Platform (e.g. `session.config.navigate('tower')`)
* @param env the applicable environment variables
* @return the Platform access token
*/
static String getAccessToken(Map opts, Map<String,String> env) {
def token = env.get('TOWER_WORKFLOW_ID')
? env.get('TOWER_ACCESS_TOKEN')
: opts.containsKey('accessToken') ? opts.accessToken as String : env.get('TOWER_ACCESS_TOKEN')
return token
}

/**
* Return the configured Platform refresh token: if `TOWER_WORKFLOW_ID` is provided in the environment, it means
* we are running in a Platform-made run and we should ONLY retrieve the token from the environment. Otherwise,
* check the configuration or fallback to the environment. If no token is found, return null.
*
* @param opts the configuration options for Platform (e.g. `session.config.navigate('tower')`)
* @param env the applicable environment variables
* @return the Platform refresh token
*/
static String getRefreshToken(Map opts, Map<String,String> env) {
def token = env.get('TOWER_WORKFLOW_ID')
? env.get('TOWER_REFRESH_TOKEN')
: opts.containsKey('refreshToken') ? opts.refreshToken as String : env.get('TOWER_REFRESH_TOKEN')
return token
}

/**
* Return the Platform Workspace ID: if `TOWER_WORKFLOW_ID` is provided in the environment, it means we are running
* in a Platform-made run and we should ONLY retrieve the workspace ID from the environment. Otherwise, check the
* configuration or fallback to the environment. If no workspace ID is found, return null.
* @param opts
* @param env
* @return
*/
static String getWorkspaceId(Map opts, Map<String,String> env) {
def workspaceId = env.get('TOWER_WORKFLOW_ID')
? env.get('TOWER_WORKSPACE_ID')
: opts.workspaceId as Long ?: env.get('TOWER_WORKSPACE_ID') as Long
return workspaceId
}
}
2 changes: 2 additions & 0 deletions plugins/nf-tower/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -39,4 +39,6 @@ dependencies {
testImplementation(testFixtures(project(":nextflow")))
testImplementation "org.apache.groovy:groovy:4.0.24"
testImplementation "org.apache.groovy:groovy-nio:4.0.24"
// wiremock required by TowerFusionEnvTest
testImplementation "org.wiremock:wiremock:3.5.4"
}
Loading
Loading