From 6456badbbfc77253ef693da88e83dabe6ba1d515 Mon Sep 17 00:00:00 2001 From: Jorge Aguilera Date: Sat, 2 Mar 2024 12:06:07 +0100 Subject: [PATCH 1/3] secure nomad api calls using the provided apiToken Signed-off-by: Jorge Aguilera --- .../nomad/executor/NomadService.groovy | 4 ++ .../nomad/executor/NomadServiceSpec.groovy | 39 +++++++++++++++++++ 2 files changed, 43 insertions(+) diff --git a/plugins/nf-nomad/src/main/nextflow/nomad/executor/NomadService.groovy b/plugins/nf-nomad/src/main/nextflow/nomad/executor/NomadService.groovy index e210645..edd527a 100644 --- a/plugins/nf-nomad/src/main/nextflow/nomad/executor/NomadService.groovy +++ b/plugins/nf-nomad/src/main/nextflow/nomad/executor/NomadService.groovy @@ -21,6 +21,7 @@ import groovy.transform.CompileStatic import groovy.util.logging.Slf4j import io.nomadproject.client.ApiClient import io.nomadproject.client.api.JobsApi +import io.nomadproject.client.auth.ApiKeyAuth import io.nomadproject.client.models.Job import io.nomadproject.client.models.JobRegisterRequest import io.nomadproject.client.models.JobRegisterResponse @@ -48,6 +49,9 @@ class NomadService implements Closeable{ this.config = config ApiClient apiClient = new ApiClient() apiClient.basePath = config.clientOpts.address + if( config.clientOpts.token ){ + apiClient.apiKey = config.clientOpts.token + } this.jobsApi = new JobsApi(apiClient); } diff --git a/plugins/nf-nomad/src/test/nextflow/nomad/executor/NomadServiceSpec.groovy b/plugins/nf-nomad/src/test/nextflow/nomad/executor/NomadServiceSpec.groovy index 9fdbc73..3cba2c9 100644 --- a/plugins/nf-nomad/src/test/nextflow/nomad/executor/NomadServiceSpec.groovy +++ b/plugins/nf-nomad/src/test/nextflow/nomad/executor/NomadServiceSpec.groovy @@ -187,4 +187,43 @@ class NomadServiceSpec extends Specification{ state == "Starting" } + + void "should send the token"(){ + given: + def config = new NomadConfig( + client:[ + address : "http://${mockWebServer.hostName}:${mockWebServer.port}", + token: "1234" + ], + jobs:[ + dockerVolume:'test' + ] + ) + def service = new NomadService(config) + + String id = "theId" + String name = "theName" + String image = "theImage" + List args = ["theCommand", "theArgs"] + String workingDir = "a/b/c" + Mapenv = [test:"test"] + + mockWebServer.enqueue(new MockResponse() + .setBody(JsonOutput.toJson(["EvalID":"test"]).toString()) + .addHeader("Content-Type", "application/json")); + when: + + def idJob = service.submitTask(id, name, image, args, workingDir,env) + def recordedRequest = mockWebServer.takeRequest(); + def body = new JsonSlurper().parseText(recordedRequest.body.readUtf8()) + + then: + idJob + + and: + recordedRequest.method == "POST" + recordedRequest.path == "/v1/jobs" + recordedRequest.headers.values('X-Nomad-Token').first()=='1234' + } + } From da8385edefbbe3690d73eb927222f16ef84a65bd Mon Sep 17 00:00:00 2001 From: Jorge Aguilera Date: Sat, 2 Mar 2024 12:07:25 +0100 Subject: [PATCH 2/3] secure nomad api calls using the provided apiToken Signed-off-by: Jorge Aguilera --- .../src/main/nextflow/nomad/executor/NomadService.groovy | 1 - 1 file changed, 1 deletion(-) diff --git a/plugins/nf-nomad/src/main/nextflow/nomad/executor/NomadService.groovy b/plugins/nf-nomad/src/main/nextflow/nomad/executor/NomadService.groovy index edd527a..bd5c7e3 100644 --- a/plugins/nf-nomad/src/main/nextflow/nomad/executor/NomadService.groovy +++ b/plugins/nf-nomad/src/main/nextflow/nomad/executor/NomadService.groovy @@ -21,7 +21,6 @@ import groovy.transform.CompileStatic import groovy.util.logging.Slf4j import io.nomadproject.client.ApiClient import io.nomadproject.client.api.JobsApi -import io.nomadproject.client.auth.ApiKeyAuth import io.nomadproject.client.models.Job import io.nomadproject.client.models.JobRegisterRequest import io.nomadproject.client.models.JobRegisterResponse From ea0e1e304d4c02f7f2027cbae936fff9f5065db4 Mon Sep 17 00:00:00 2001 From: Abhinav Sharma Date: Sun, 3 Mar 2024 19:13:43 -0300 Subject: [PATCH 3/3] update the version, add logs and update license [ci skip] --- gradle.properties | 2 +- plugins/build.gradle | 5 ++--- .../src/main/nextflow/nomad/NomadConfig.groovy | 4 ++-- .../nomad/executor/NomadExecutor.groovy | 17 ++++++++++++++++- .../nomad/executor/NomadScriptLauncher.groovy | 17 +++++++++++++++++ .../nextflow/nomad/executor/NomadService.groovy | 4 ++-- .../nomad/executor/NomadTaskHandler.groovy | 17 ++++++++++++++++- .../src/test/nextflow/nomad/NomadDSLSpec.groovy | 2 ++ 8 files changed, 58 insertions(+), 10 deletions(-) diff --git a/gradle.properties b/gradle.properties index 8766f31..c623543 100644 --- a/gradle.properties +++ b/gradle.properties @@ -1 +1 @@ -version=0.0.2-rc1 \ No newline at end of file +version=0.0.2 \ No newline at end of file diff --git a/plugins/build.gradle b/plugins/build.gradle index 6b08277..644098c 100644 --- a/plugins/build.gradle +++ b/plugins/build.gradle @@ -1,8 +1,7 @@ /* + * Copyright 2023-, Stellenbosch University, South Africa * Copyright 2024, Evaluacion y Desarrollo de Negocios, Spain - * Copyright 2023, Stellenbosch University, South Africa - * Copyright 2022, Center for Medical Genetics, Ghent - * + * 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 diff --git a/plugins/nf-nomad/src/main/nextflow/nomad/NomadConfig.groovy b/plugins/nf-nomad/src/main/nextflow/nomad/NomadConfig.groovy index 624efc2..bf6bacf 100644 --- a/plugins/nf-nomad/src/main/nextflow/nomad/NomadConfig.groovy +++ b/plugins/nf-nomad/src/main/nextflow/nomad/NomadConfig.groovy @@ -1,6 +1,6 @@ /* - * Copyright 2023, Stellenbosch University, South Africa - * Copyright 2022, Center for Medical Genetics, Ghent + * Copyright 2023-, Stellenbosch University, South Africa + * Copyright 2024, Evaluacion y Desarrollo de Negocios, Spain * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. diff --git a/plugins/nf-nomad/src/main/nextflow/nomad/executor/NomadExecutor.groovy b/plugins/nf-nomad/src/main/nextflow/nomad/executor/NomadExecutor.groovy index a7115f4..d4e59bb 100644 --- a/plugins/nf-nomad/src/main/nextflow/nomad/executor/NomadExecutor.groovy +++ b/plugins/nf-nomad/src/main/nextflow/nomad/executor/NomadExecutor.groovy @@ -1,4 +1,19 @@ - +/* + * Copyright 2023-, Stellenbosch University, South Africa + * Copyright 2024, Evaluacion y Desarrollo de Negocios, Spain + * + * 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.nomad.executor import groovy.transform.CompileStatic diff --git a/plugins/nf-nomad/src/main/nextflow/nomad/executor/NomadScriptLauncher.groovy b/plugins/nf-nomad/src/main/nextflow/nomad/executor/NomadScriptLauncher.groovy index 2a8b693..1f37061 100644 --- a/plugins/nf-nomad/src/main/nextflow/nomad/executor/NomadScriptLauncher.groovy +++ b/plugins/nf-nomad/src/main/nextflow/nomad/executor/NomadScriptLauncher.groovy @@ -1,3 +1,20 @@ +/* + * Copyright 2023-, Stellenbosch University, South Africa + * Copyright 2024, Evaluacion y Desarrollo de Negocios, Spain + * + * 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.nomad.executor diff --git a/plugins/nf-nomad/src/main/nextflow/nomad/executor/NomadService.groovy b/plugins/nf-nomad/src/main/nextflow/nomad/executor/NomadService.groovy index 8cf84a4..ba73970 100644 --- a/plugins/nf-nomad/src/main/nextflow/nomad/executor/NomadService.groovy +++ b/plugins/nf-nomad/src/main/nextflow/nomad/executor/NomadService.groovy @@ -1,7 +1,6 @@ /* + * Copyright 2023-, Stellenbosch University, South Africa * Copyright 2024, Evaluacion y Desarrollo de Negocios, Spain - * Copyright 2023, Stellenbosch University, South Africa - * Copyright 2022, Center for Medical Genetics, Ghent * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -52,6 +51,7 @@ class NomadService implements Closeable{ ApiClient apiClient = new ApiClient() apiClient.basePath = config.clientOpts.address if( config.clientOpts.token ){ + log.debug "[NOMAD BATCH] Creating Nomad connection using token: ${config.clientOpts.token?.substring(0,5)}.." apiClient.apiKey = config.clientOpts.token } this.jobsApi = new JobsApi(apiClient); diff --git a/plugins/nf-nomad/src/main/nextflow/nomad/executor/NomadTaskHandler.groovy b/plugins/nf-nomad/src/main/nextflow/nomad/executor/NomadTaskHandler.groovy index 0ed6259..3390b4d 100644 --- a/plugins/nf-nomad/src/main/nextflow/nomad/executor/NomadTaskHandler.groovy +++ b/plugins/nf-nomad/src/main/nextflow/nomad/executor/NomadTaskHandler.groovy @@ -1,4 +1,19 @@ - +/* + * Copyright 2023-, Stellenbosch University, South Africa + * Copyright 2024, Evaluacion y Desarrollo de Negocios, Spain + * + * 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.nomad.executor diff --git a/plugins/nf-nomad/src/test/nextflow/nomad/NomadDSLSpec.groovy b/plugins/nf-nomad/src/test/nextflow/nomad/NomadDSLSpec.groovy index 02410ca..72a83bc 100644 --- a/plugins/nf-nomad/src/test/nextflow/nomad/NomadDSLSpec.groovy +++ b/plugins/nf-nomad/src/test/nextflow/nomad/NomadDSLSpec.groovy @@ -1,4 +1,6 @@ /* + * Copyright 2023-, Stellenbosch University, South Africa + * Copyright 2024, Evaluacion y Desarrollo de Negocios, Spain* * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License.