Skip to content
This repository has been archived by the owner on Jan 22, 2025. It is now read-only.

Commit

Permalink
Merge pull request #124 from girder/girder-api-key
Browse files Browse the repository at this point in the history
Add support for passing GC info to a docker job.
  • Loading branch information
manthey authored Nov 10, 2020
2 parents 061ff70 + bb93cc0 commit e88667f
Show file tree
Hide file tree
Showing 13 changed files with 112 additions and 9 deletions.
2 changes: 2 additions & 0 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,8 @@ The XML must conform to the `Slicer Execution Schema <https://www.slicer.org/w/i

- Some input types (``image``, ``file``, ``item``, ``directory``) can have ``defaultNameMatch`` and ``defaultPathMatch`` properties. These are regular expressions designed to give a UI a value to match to prepopulate default values from files or paths that match the regex. ``defaultNameMatch`` is intended to match the final path element, whereas ``defaultPathMatch`` is used on the entire path as a combined string.

- There are some special string parameters that, if unspecified or blank, are autopopulated. String parameters with the names of ``girderApiUrl`` and ``girderApiKey`` are populated with the appropriate url and token so that a running job could use girder_client to communicate with Girder.


.. |build-status| image:: https://circleci.com/gh/girder/slicer_cli_web.svg?style=svg
:target: https://circleci.com/gh/girder/slicer_cli_web
Expand Down
4 changes: 4 additions & 0 deletions slicer_cli_web/cli_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -77,3 +77,7 @@ def get_flag(p):

def is_on_girder(param):
return param.typ in SLICER_TYPE_TO_GIRDER_MODEL_MAP


def is_girder_api(param):
return param.name in {'girderApiUrl', 'girderApiKey'}
11 changes: 11 additions & 0 deletions slicer_cli_web/girder_worker_plugin/direct_docker_run.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
from girder_worker.docker.transforms.girder import GirderFileIdToVolume
from girder_worker.docker.tasks import _docker_run, DockerTask
from girder_worker_utils import _walk_obj
from girder_worker_utils.transforms.girder_io import GirderClientTransform


def _get_basename(filename, direct_path):
Expand Down Expand Up @@ -43,6 +44,16 @@ def transform(self, **kwargs):
return super(DirectGirderFileIdToVolume, self).transform(**kwargs)


class GirderApiUrl(GirderClientTransform):
def transform(self, **kwargs):
return self.gc.urlBase


class GirderApiKey(GirderClientTransform):
def transform(self, **kwargs):
return self.gc.token


def _resolve_direct_file_paths(args, kwargs):
extra_volumes = []

Expand Down
19 changes: 18 additions & 1 deletion slicer_cli_web/prepare_task.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
from girder.models.setting import Setting

from .cli_utils import \
SLICER_TYPE_TO_GIRDER_MODEL_MAP, is_on_girder, return_parameter_file_name
SLICER_TYPE_TO_GIRDER_MODEL_MAP, is_on_girder, is_girder_api, return_parameter_file_name


OPENAPI_DIRECT_TYPES = set(['boolean', 'integer', 'float', 'double', 'string'])
Expand Down Expand Up @@ -42,6 +42,18 @@ def _to_file_volume(param, model):
return GirderFileIdToVolume(model['_id'], filename=model['name'])


def _to_girder_api(param, value):
from .girder_worker_plugin.direct_docker_run import GirderApiUrl, GirderApiKey

if value:
return value
if param.name == 'girderApiUrl':
return GirderApiUrl()
elif param.name == 'girderApiKey':
return GirderApiKey()
return value


def _parseParamValue(param, value, user, token):
if isinstance(value, six.binary_type):
value = value.decode('utf8')
Expand Down Expand Up @@ -86,6 +98,9 @@ def _add_optional_input_param(param, args, user, token):
if is_on_girder(param):
# Bindings
container_args.append(_to_file_volume(param, value))
elif is_girder_api(param):
# Bindings
container_args.append(_to_girder_api(param, value))
else:
container_args.append(value)
return container_args
Expand Down Expand Up @@ -128,6 +143,8 @@ def _add_indexed_input_param(param, args, user, token):
if is_on_girder(param):
# Bindings
return _to_file_volume(param, value), value['name']
if is_girder_api(param):
return _to_girder_api(param, value), value['name']
return value, None


Expand Down
4 changes: 2 additions & 2 deletions slicer_cli_web/web_client/models/WidgetModel.js
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,7 @@ const WidgetModel = Backbone.Model.extend({
// make sure value is approximately an integer number
// of "steps" larger than "min"
min = min || 0;
const mod = (value - min) / step;
const mod = (value - min) / (step || 1);
if (step > 0 && Math.abs(Math.round(mod) - mod) > eps) {
return 'Value does not satisfy step "' + step + '"';
}
Expand Down Expand Up @@ -214,7 +214,7 @@ const WidgetModel = Backbone.Model.extend({
// make sure value is approximately an integer number
// of "steps" larger than "min"
min = min || 0;
if ((value - min) % step) {
if (step > 0 && ((value - min) % (step || 1))) {
return `Value does not satisfy step "${step}"`;
}
},
Expand Down
4 changes: 2 additions & 2 deletions small-docker/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@ RUN chmod a+x /usr/local/bin/groupadd
RUN touch /usr/local/bin/useradd
RUN chmod a+x /usr/local/bin/useradd

# We need ctk-cli to parse inputs
RUN pip install ctk-cli
# We need either ctk-cli or our equivalent to parse inputs
RUN pip install --pre girder-slicer-cli-web
COPY . $PWD

ENTRYPOINT ["python", "./cli_list.py"]
25 changes: 24 additions & 1 deletion small-docker/Example1/Example1.json
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,29 @@
}
]
},
{
"advanced": true,
"label": "Girder API URL and Key",
"description": "A Girder API URL and token for Girder client",
"parameters": [
{
"type": "string",
"name": "girderApiUrl",
"longflag": "api-url",
"label": "Girder API URL",
"description": "A Girder API URL (e.g., https://girder.example.com:443/api/v1)",
"default": ""
},
{
"type": "string",
"name": "girderApiKey",
"longflag": "api-key",
"label": "Girder API Key",
"description": "A Girder token",
"default": ""
}
]
},
{
"label": "Boolean Parameters",
"description": "Variations on boolean parameters",
Expand Down Expand Up @@ -247,7 +270,7 @@
{
"type": "string",
"name": "astringreturn",
"label": "A string point return value",
"label": "A string return value",
"channel": "output",
"default": "Hello",
"description": "An example of a string return type"
Expand Down
9 changes: 9 additions & 0 deletions small-docker/Example1/Example1.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,18 @@
import pprint

from slicer_cli_web import ctk_cli_adjustment # noqa - imported for side effects
from ctk_cli import CLIArgumentParser


def main(args):
print('>> parsed arguments')
print('%r' % args)
pprint.pprint(vars(args), width=1000)
with open(args.returnParameterFile, 'w') as f:
f.write('>> parsed arguments\n')
f.write('%r\n' % args)
with open(args.arg1, 'w') as f:
f.write('example\n')


if __name__ == '__main__':
Expand Down
20 changes: 19 additions & 1 deletion small-docker/Example1/Example1.xml
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,24 @@
<element>Will</element>
</string-enumeration>
</parameters>
<parameters advanced="true">
<label>Girder API URL and Key</label>
<description>A Girder API URL and token for Girder client</description>
<string>
<name>girderApiUrl</name>
<longflag>api-url</longflag>
<label>Girder API URL</label>
<description>A Girder API URL (e.g., https://girder.example.com:443/api/v1)</description>
<default></default>
</string>
<string>
<name>girderApiKey</name>
<longflag>api-key</longflag>
<label>Girder API Key</label>
<description>A Girder token</description>
<default></default>
</string>
</parameters>
<parameters>
<label>Boolean Parameters</label>
<description><![CDATA[Variations on boolean parameters]]></description>
Expand Down Expand Up @@ -194,7 +212,7 @@
</double>
<string>
<name>astringreturn</name>
<label>A string point return value</label>
<label>A string return value</label>
<channel>output</channel>
<default>Hello</default>
<description><![CDATA[An example of a string return type]]></description>
Expand Down
18 changes: 17 additions & 1 deletion small-docker/Example1/Example1.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,22 @@ parameter_groups:
- Ross
- Steve
- Will
- advanced: true
description: A Girder API URL and token for Girder client
label: Girder API URL and Key
parameters:
- type: string
name: girderApiUrl
longflag: api-url
label: Girder API URL
description: A Girder API URL (e.g., https://girder.example.com:443/api/v1)
default: ''
- type: string
name: girderApiKey
longflag: api-key
label: Girder API Key
description: A Girder token
default: ''
- description: Variations on boolean parameters
label: Boolean Parameters
parameters:
Expand Down Expand Up @@ -181,7 +197,7 @@ parameter_groups:
description: An example of a double return type
- type: string
name: astringreturn
label: A string point return value
label: A string return value
channel: output
default: Hello
description: An example of a string return type
Expand Down
3 changes: 2 additions & 1 deletion small-docker/Example3/Example3.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,8 @@
"channel": "input",
"constraints": {
"minimum": 0.0,
"maximum": 1.0
"maximum": 1.0,
"step": 0.0
}
}
]
Expand Down
1 change: 1 addition & 0 deletions small-docker/Example3/Example3.xml
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
<constraints>
<minimum>0</minimum>
<maximum>1</maximum>
<step>0</step>
</constraints>
</float>
</parameters>
Expand Down
1 change: 1 addition & 0 deletions small-docker/Example3/Example3.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -18,3 +18,4 @@ parameter_groups:
constraints:
minimum: 0.0
maximum: 1.0
step: 0.0

0 comments on commit e88667f

Please sign in to comment.