-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
nomad secrets, add get set and list commands
Signed-off-by: Jorge Aguilera <[email protected]>
- Loading branch information
Showing
6 changed files
with
166 additions
and
11 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -18,6 +18,9 @@ | |
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 | ||
|
@@ -31,7 +34,8 @@ import org.pf4j.PluginWrapper | |
* @author : matthdsm <[email protected]> | ||
*/ | ||
@CompileStatic | ||
class NomadPlugin extends BasePlugin { | ||
@Slf4j | ||
class NomadPlugin extends BasePlugin implements PluginAbstractExec{ | ||
|
||
NomadPlugin(PluginWrapper wrapper) { | ||
super(wrapper) | ||
|
@@ -42,4 +46,23 @@ class NomadPlugin extends BasePlugin { | |
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) | ||
return 0 | ||
} | ||
} |
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) | ||
} | ||
} |
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