Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions CHANGELOG.rst
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,12 @@ Fixed
Reported by Carlos.
* Fix action-alias execute response to show execution id and matching action-alias #3231 (bug fix)
Reported by Carlos.
* Fix ``st2 apikey load`` command to update an existing entry if items in input file contain ``id``
attribute and item already exists on the server. This way the behavior is consistent with
``st2 key load`` command and the command is idempotent if each item contains ``id`` attribute.
#3748 #3786

Reported by Christopher Baklid.

2.4.1 - September 12, 2017
--------------------------
Expand Down
23 changes: 20 additions & 3 deletions st2client/st2client/commands/auth.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,9 @@
import json
import logging

import requests
from six.moves.configparser import ConfigParser
from six.moves import http_client

from st2client.base import BaseCLIApp
from st2client import config_parser
Expand Down Expand Up @@ -339,14 +341,29 @@ def run(self, args, **kwargs):
instances = []
for res in resources:
# pick only the meaningful properties.
instance = {
data = {
'user': res['user'], # required
'key_hash': res['key_hash'], # required
'metadata': res.get('metadata', {}),
'enabled': res.get('enabled', False)
}
instance = self.resource.deserialize(instance)
instances.append(self.manager.create(instance, **kwargs))

if 'id' in res:
data['id'] = res['id']

instance = self.resource.deserialize(data)

try:
result = self.manager.update(instance, **kwargs)
except requests.exceptions.HTTPError as e:
if e.response.status_code == http_client.NOT_FOUND:
instance = self.resource.deserialize(data)
# Key doesn't exist yet, create it instead
result = self.manager.create(instance, **kwargs)
else:
raise e

instances.append(result)
return instances

def run_and_print(self, args, **kwargs):
Expand Down