-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Iteration on Nomad/Variables <-> Nextflow/Secrets (#75)
* first iteration in secrets implementation Signed-off-by: Jorge Aguilera <[email protected]> * tweak the start-nomad script for different platforms [ci skip] * nomad secrets, add get set and list commands Signed-off-by: Jorge Aguilera <[email protected]> * delete nomad with stop command [ci skip] * tweak the sun-nomadlab config to accommodate variables [ci skip] * update the sun-nomadlab config for config level secret vars [ci skip] * enable nomad secrets via nextflow config if false use Local implementation Signed-off-by: Jorge Aguilera <[email protected]> * add test Signed-off-by: Jorge Aguilera <[email protected]> * fix small bug Signed-off-by: Jorge Aguilera <[email protected]> * improve local testing env [ci skip] * test with sun-nomadlab and localsecretstore [ci skip] * rename enable -> enabled to comply with standard * use the functional config for sun-nomadlab [ci skip] * update authors [ci skip] --------- Signed-off-by: Jorge Aguilera <[email protected]> Co-authored-by: Jorge Aguilera <[email protected]>
- Loading branch information
Showing
17 changed files
with
497 additions
and
19 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -18,26 +18,50 @@ | |
package nextflow.nomad | ||
|
||
import groovy.transform.CompileStatic | ||
import groovy.util.logging.Slf4j | ||
import nextflow.cli.PluginAbstractExec | ||
import nextflow.nomad.secrets.NomadSecretCmd | ||
import nextflow.nomad.executor.TaskDirectives | ||
import nextflow.plugin.BasePlugin | ||
import nextflow.script.ProcessConfig | ||
import nextflow.secret.SecretsLoader | ||
import org.pf4j.PluginWrapper | ||
|
||
/** | ||
* Nextflow plugin for Nomad executor | ||
* | ||
* @author Abhinav Sharma <[email protected]> | ||
* @author : matthdsm <[email protected]> | ||
* @author Jorge Aguilera <[email protected]> | ||
*/ | ||
@CompileStatic | ||
class NomadPlugin extends BasePlugin { | ||
@Slf4j | ||
class NomadPlugin extends BasePlugin implements PluginAbstractExec{ | ||
|
||
NomadPlugin(PluginWrapper wrapper) { | ||
super(wrapper) | ||
addCustomDirectives() | ||
SecretsLoader.instance.reset() | ||
} | ||
|
||
private static void addCustomDirectives() { | ||
ProcessConfig.DIRECTIVES.addAll(TaskDirectives.ALL) | ||
} | ||
|
||
@Override | ||
List<String> getCommands() { | ||
return ['secrets'] | ||
} | ||
|
||
@Override | ||
int exec(String cmd, List<String> args) { | ||
return switch (cmd){ | ||
case 'secrets'-> secrets(args.first(), args.drop(1)) | ||
default -> -1 | ||
} | ||
} | ||
|
||
int secrets(String action, List<String>args){ | ||
NomadSecretCmd nomadSecretCmd = new NomadSecretCmd() | ||
nomadSecretCmd.runCommand( session.config , action, args) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
13 changes: 13 additions & 0 deletions
13
plugins/nf-nomad/src/main/nextflow/nomad/config/NomadSecretOpts.groovy
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
package nextflow.nomad.config | ||
|
||
class NomadSecretOpts { | ||
|
||
final Boolean enabled | ||
final String path | ||
|
||
NomadSecretOpts(Map map){ | ||
this.enabled = map.containsKey('enabled') ? map.get('enabled') as boolean : false | ||
this.path = map.path ?: "secrets/nf-nomad" | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
79 changes: 79 additions & 0 deletions
79
plugins/nf-nomad/src/main/nextflow/nomad/secrets/NomadSecretCmd.groovy
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,79 @@ | ||
package nextflow.nomad.secrets | ||
|
||
import groovy.util.logging.Slf4j | ||
import nextflow.exception.AbortOperationException | ||
import nextflow.nomad.config.NomadConfig | ||
import nextflow.nomad.executor.NomadService | ||
import nextflow.plugin.Priority | ||
import nextflow.secret.Secret | ||
import nextflow.secret.SecretImpl | ||
import nextflow.secret.SecretsProvider | ||
|
||
@Slf4j | ||
class NomadSecretCmd { | ||
|
||
protected NomadService service | ||
protected NomadConfig nomadConfig | ||
|
||
int runCommand(Map config, String action, List<String> args){ | ||
nomadConfig = new NomadConfig((config.nomad ?: Collections.emptyMap()) as Map) | ||
service = new NomadService(nomadConfig) | ||
return switch (action){ | ||
case 'get' ->execGetSecretNames(args.removeAt(0).toString()) | ||
case 'set' ->execSetSecretNames(args.removeAt(0).toString(),args.removeAt(0).toString()) | ||
case 'list'->execListSecretsNames() | ||
case 'delete'->execDeleteSecretNames(args.removeAt(0).toString()) | ||
default -> -1 | ||
} | ||
} | ||
|
||
int execListSecretsNames(){ | ||
def list = listSecretsNames() | ||
println list.join('\n') | ||
return 0 | ||
} | ||
|
||
int execGetSecretNames(String name){ | ||
if(!name){ | ||
throw new AbortOperationException("Wrong number of arguments") | ||
} | ||
def secret = getSecret(name) | ||
println secret | ||
return 0 | ||
} | ||
|
||
int execSetSecretNames(String name, String value){ | ||
if(!name){ | ||
throw new AbortOperationException("Wrong number of arguments") | ||
} | ||
setSecret(name, value) | ||
return 0 | ||
} | ||
|
||
int execDeleteSecretNames(String name){ | ||
if(!name){ | ||
throw new AbortOperationException("Wrong number of arguments") | ||
} | ||
deleteSecret(name) | ||
return 0 | ||
} | ||
|
||
String getSecret(String name) { | ||
String value = service.getVariableValue(name) | ||
if( !value ) | ||
throw new AbortOperationException("Missing secret name") | ||
value | ||
} | ||
|
||
Set<String> listSecretsNames() { | ||
service.variablesList | ||
} | ||
|
||
void setSecret(String name, String value) { | ||
service.setVariableValue(name, value) | ||
} | ||
|
||
void deleteSecret(String name){ | ||
service.deleteVariable(name) | ||
} | ||
} |
Oops, something went wrong.