Skip to content

Commit

Permalink
Merge pull request #81 from ingrammicro/fix-operation-detection-mecha…
Browse files Browse the repository at this point in the history
…nism

Improved operation detection mechanism
  • Loading branch information
vgrebenschikov authored Apr 15, 2020
2 parents 0e4b5d8 + 25bb08b commit 8939bc7
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 11 deletions.
2 changes: 1 addition & 1 deletion VERSION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
19.1.3
19.1.4
2 changes: 1 addition & 1 deletion apsconnectcli/apsconnect.py
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ def install_frontend(self, source, oauth_key, oauth_secret, backend_url, setting
connection = hub.get_connections(package.product_id)
print("Detected connection {} for this Hub and product {}".format(connection['id'],
package.product_id))
operation = hub.check_package_operation(package, experimental)
operation = hub.check_package_operation(package)
update_rts = False
if operation == "install":
print("Importing connector {} version {}.{}".format(package.connector_id,
Expand Down
27 changes: 18 additions & 9 deletions apsconnectcli/hub.py
Original file line number Diff line number Diff line change
Expand Up @@ -178,24 +178,33 @@ def aps_devel_mode(self, disable=False):
osaapi_raise_for_status(r)
print("APS Development mode {}.".format('DISABLED' if disable else 'ENABLED'))

def check_package_operation(self, package, experimental):
url = '/aps/2/types?implementing({}/app)'.format(package.connector_id)
def check_package_operation(self, package):
app_id = self.get_application_id(package.connector_id)
if app_id is None:
print("INFO: package is not installed")
return "install"
app_instances = self.get_application_instances(int(app_id))
if len(app_instances) == 0:
return "install"
url = '/aps/2/resources/{}'.format(app_instances[0]['application_resource_id'])
r = self.aps.get(url)
try:
data = json.loads(r.content.decode('utf-8'))
except ValueError:
print("APSController provided non-json format")
sys.exit(1)
if len(data) == 0:
if 'aps' not in data:
print("INFO: package is not installed")
return "install"
latest = 0
for type in data:
match = re.match(r'{}/app/(?P<major>\d+)\.0'.format(package.connector_id), type['id'])
if match:
major = int(match.groupdict()['major'])
if int(latest) < major:
latest = major
match = re.match(r'{}/app/(?P<major>\d+)\.0'.format(
package.connector_id),
data['aps']['type']
)
if match:
major = int(match.groupdict()['major'])
if int(latest) < major:
latest = major
if int(latest) == int(package.version):
return "createRTs"
elif int(latest) > int(package.version):
Expand Down

0 comments on commit 8939bc7

Please sign in to comment.