def update(config, application_id, key_val_pairs): '''Update a single application kio app up APPLICATION_ID KEY1=VAL1 ..''' url = get_url(config) token = get_token() r = request(url, '/apps/{}'.format(application_id), token) r.raise_for_status() data = r.json() for key_val in key_val_pairs: key, sep, val = key_val.partition('=') if key not in data: raise click.UsageError('Field "{}" does not exist'.format(key)) if not val: raise click.UsageError('Value missing for field "{}". You must provide KEY=VAL pairs.'.format(key)) if isinstance(data[key], bool): val = val == 'true' data[key] = val # remove fields which we can't update for key in ('id', 'last_modified', 'last_modified_by', 'criticality_level', 'created', 'created_by'): del data[key] with Action('Updating application {}..'.format(application_id)): r = session.put('{}/apps/{}'.format(url, application_id), headers={'Authorization': 'Bearer {}'.format(token), 'Content-Type': 'application/json'}, timeout=10, data=json.dumps(data)) r.raise_for_status()
def create_version(config, application_id, version, artifact, notes): '''Create a new application version''' url = get_url(config) token = get_token(['uid', 'application.write']) data = {'artifact': artifact, 'notes': notes} with Action('Creating version {} {}..'.format(application_id, version)): r = session.put('{}/apps/{}/versions/{}'.format(url, application_id, version), headers={'Authorization': 'Bearer {}'.format(token), 'Content-Type': 'application/json'}, timeout=10, data=json.dumps(data)) r.raise_for_status()