MCPcopy Create free account
hub / github.com/StackStorm/st2 / run

Method run

st2client/st2client/commands/keyvalue.py:438–508  ·  view source on GitHub ↗
(self, args, **kwargs)

Source from the content-addressed store, hash-verified

436
437 @resource.add_auth_token_to_kwargs_from_cli
438 def run(self, args, **kwargs):
439 # normalize the file path to allow for relative files to be specified
440 file_path = os.path.normpath(pjoin(os.getcwd(), args.file))
441
442 # load the data (JSON/YAML) from the file
443 kvps = resource.load_meta_file(file_path)
444
445 instances = []
446 # bail out if file was empty
447 if not kvps:
448 return instances
449
450 # if the data is not a list (ie. it's a single entry)
451 # then make it a list so our process loop is generic
452 if not isinstance(kvps, list):
453 kvps = [kvps]
454
455 for item in kvps:
456 # parse required KeyValuePair properties
457 name = item["name"]
458 value = item["value"]
459
460 # parse optional KeyValuePair properties
461 scope = item.get("scope", DEFAULT_CUD_SCOPE)
462 user = item.get("user", None)
463 encrypted = item.get("encrypted", False)
464 secret = item.get("secret", False)
465 ttl = item.get("ttl", None)
466
467 # if the value is not a string, convert it to JSON
468 # all keys in the datastore must strings
469 if not isinstance(value, six.string_types):
470 if args.convert:
471 value = json.dumps(value)
472 else:
473 raise ValueError(
474 (
475 "Item '%s' has a value that is not a string."
476 " Either pass in the -c/--convert option to convert"
477 " non-string types to JSON strings automatically, or"
478 " convert the data to a string in the file"
479 )
480 % name
481 )
482
483 # create the KeyValuePair instance
484 instance = KeyValuePair()
485 instance.id = name # TODO: refactor and get rid of id
486 instance.name = name
487 instance.value = value
488 instance.scope = scope
489
490 if user:
491 instance.user = user
492 if encrypted:
493 instance.encrypted = encrypted
494 if secret:
495 instance.secret = secret

Callers 1

run_and_printMethod · 0.95

Calls 3

KeyValuePairClass · 0.90
getMethod · 0.45
updateMethod · 0.45

Tested by

no test coverage detected