-
Notifications
You must be signed in to change notification settings - Fork 660
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by: Paolo Di Tommaso <[email protected]>
- Loading branch information
1 parent
52f4c5d
commit 902e5b3
Showing
10 changed files
with
274 additions
and
84 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
28 changes: 28 additions & 0 deletions
28
modules/nextflow/src/main/groovy/nextflow/fusion/FusionEnv.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,28 @@ | ||
/* | ||
* Copyright 2020-2022, Seqera Labs | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
* | ||
*/ | ||
|
||
package nextflow.fusion | ||
|
||
/** | ||
* Allow importing platform specific env variables in the Fusion context | ||
* | ||
* @author Paolo Di Tommaso <[email protected]> | ||
*/ | ||
interface FusionEnv { | ||
|
||
Map<String,String> getEnvironment(String scheme, FusionConfig config) | ||
} |
40 changes: 40 additions & 0 deletions
40
modules/nextflow/src/main/groovy/nextflow/fusion/FusionEnvProvider.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,40 @@ | ||
/* | ||
* Copyright 2020-2022, Seqera Labs | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
* | ||
*/ | ||
|
||
package nextflow.fusion | ||
|
||
import nextflow.Global | ||
import nextflow.SysEnv | ||
import nextflow.plugin.Plugins | ||
/** | ||
* Provider strategy for {@link FusionEnv} | ||
* | ||
* @author Paolo Di Tommaso <[email protected]> | ||
*/ | ||
class FusionEnvProvider { | ||
|
||
Map<String,String> getEnvironment(String scheme) { | ||
final config = new FusionConfig(Global.config.fusion as Map ?: Collections.emptyMap(), SysEnv.get()) | ||
final list = Plugins.getExtensions(FusionEnv) | ||
final result = new HashMap<String,String>() | ||
for( FusionEnv it : list ) { | ||
final env = it.getEnvironment(scheme,config) | ||
if( env ) result.putAll(env) | ||
} | ||
return result | ||
} | ||
} |
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
50 changes: 50 additions & 0 deletions
50
plugins/nf-amazon/src/main/nextflow/cloud/aws/fusion/AwsFusionEnv.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,50 @@ | ||
/* | ||
* Copyright 2020-2022, Seqera Labs | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
* | ||
*/ | ||
|
||
package nextflow.cloud.aws.fusion | ||
|
||
import groovy.transform.CompileStatic | ||
import nextflow.Global | ||
import nextflow.fusion.FusionConfig | ||
import nextflow.fusion.FusionEnv | ||
import org.pf4j.Extension | ||
/** | ||
* Implements {@link FusionEnv} for AWS cloud | ||
* | ||
* @author Paolo Di Tommaso <[email protected]> | ||
*/ | ||
@Extension | ||
@CompileStatic | ||
class AwsFusionEnv implements FusionEnv { | ||
|
||
@Override | ||
Map<String, String> getEnvironment(String scheme, FusionConfig config) { | ||
if( scheme!='s3' ) | ||
return Collections.<String,String>emptyMap() | ||
|
||
final result = new HashMap<String,String>() | ||
final endpoint = Global.getAwsS3Endpoint() | ||
final creds = config.exportAwsAccessKeys() ? Global.getAwsCredentials() : Collections.<String>emptyList() | ||
if( creds ) { | ||
result.AWS_ACCESS_KEY_ID = creds[0] | ||
result.AWS_SECRET_ACCESS_KEY = creds[1] | ||
} | ||
if( endpoint ) | ||
result.AWS_S3_ENDPOINT = endpoint | ||
return result | ||
} | ||
} |
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
60 changes: 60 additions & 0 deletions
60
plugins/nf-amazon/src/test/nextflow/cloud/aws/fusion/AwsFusionEnvTest.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,60 @@ | ||
/* | ||
* Copyright 2020-2022, Seqera Labs | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
* | ||
*/ | ||
|
||
package nextflow.cloud.aws.fusion | ||
|
||
import nextflow.SysEnv | ||
import nextflow.fusion.FusionConfig | ||
import spock.lang.Specification | ||
/** | ||
* | ||
* @author Paolo Di Tommaso <[email protected]> | ||
*/ | ||
class AwsFusionEnvTest extends Specification { | ||
|
||
def 'should return empty env' () { | ||
given: | ||
def provider = new AwsFusionEnv() | ||
when: | ||
def env = provider.getEnvironment('az', Mock(FusionConfig)) | ||
then: | ||
env == Collections.emptyMap() | ||
} | ||
|
||
def 'should return env environment' () { | ||
given: | ||
SysEnv.push([AWS_ACCESS_KEY_ID: 'x1', AWS_SECRET_ACCESS_KEY: 'y1', AWS_S3_ENDPOINT: 'http://my-host.com']) | ||
and: | ||
|
||
when: | ||
def config = Mock(FusionConfig) | ||
def env = new AwsFusionEnv().getEnvironment('s3', Mock(FusionConfig)) | ||
then: | ||
env == [AWS_S3_ENDPOINT:'http://my-host.com'] | ||
|
||
when: | ||
config = Mock(FusionConfig) { exportAwsAccessKeys() >> true } | ||
env = new AwsFusionEnv().getEnvironment('s3', config) | ||
then: | ||
env == [AWS_ACCESS_KEY_ID: 'x1', | ||
AWS_SECRET_ACCESS_KEY: 'y1', | ||
AWS_S3_ENDPOINT:'http://my-host.com'] | ||
|
||
cleanup: | ||
SysEnv.pop() | ||
} | ||
} |
Oops, something went wrong.