-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
LITE-28130 Add capability to Install/Update product in CBC using PLM API
- Loading branch information
1 parent
bbe6dd2
commit 75fa8f4
Showing
14 changed files
with
498 additions
and
64 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,15 @@ | ||
from requests import Response | ||
|
||
|
||
class ClientError(RuntimeError): | ||
def __init__( | ||
self, | ||
message: str, | ||
status_code: int = None, | ||
response: Response = None, | ||
cause: Exception = None, | ||
): | ||
self.message = message | ||
self.response = response | ||
self.status_code = status_code | ||
self.cause = cause |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
from connect_ext_ppr.models.cbc_extenstion import HubCredential | ||
|
||
from sqlalchemy import text | ||
|
||
|
||
HUB_CREDENTIAL_QUERY = ''' | ||
SELECT DISTINCT h.hub_id, | ||
g.app_instance_id, | ||
h.controller_uri, | ||
c.oauth_key, | ||
c.oauth_secret | ||
FROM hub_instances h | ||
INNER JOIN global_app_configuration g ON g.hub_uuid = h.extension_resource_uid | ||
INNER JOIN configuration c ON c.product_id = g.hub_uuid | ||
WHERE h.hub_id = :hub_id | ||
''' | ||
|
||
|
||
def get_hub_credentials(hub_id, db): | ||
|
||
query = text(HUB_CREDENTIAL_QUERY) | ||
|
||
query = query.columns( | ||
HubCredential.hub_id, | ||
HubCredential.app_id, | ||
HubCredential.controller_url, | ||
HubCredential.oauth_key, | ||
HubCredential.oauth_secret, | ||
) | ||
|
||
return db.query( | ||
HubCredential, | ||
).from_statement( | ||
query, | ||
).params( | ||
hub_id=hub_id, | ||
).first() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
from connect_ext_ppr.client import CBCClient | ||
from connect_ext_ppr.models.cbc_extenstion import HubCredential | ||
|
||
|
||
class CBCService: | ||
|
||
PLM_TYPE = 'http://com.odin.platform/inhouse-products/application' | ||
SUBSCRIPTION_TYPE = 'http://parallels.com/aps/types/pa/subscription' | ||
|
||
def __init__(self, hub_credential: HubCredential, verify_certificate: bool = False): | ||
assert hub_credential, 'HubCredential can not be None!' | ||
assert hub_credential.controller_url, 'Controller URL can not be empty!' | ||
assert hub_credential.oauth_key, 'OAuth Key can not be empty!' | ||
assert hub_credential.oauth_secret, 'OAuth Secret can not be empty!' | ||
|
||
self.hub_credential = hub_credential | ||
self.client = CBCClient( | ||
endpoint=hub_credential.controller_url, | ||
oauth_key=hub_credential.oauth_key, | ||
oauth_secret=hub_credential.oauth_secret, | ||
app_id=hub_credential.app_id, | ||
verify_certificate=verify_certificate, | ||
) | ||
|
||
self.__primary_subscription_id = None | ||
self.__subscription_service = None | ||
self.__plm_service = None | ||
|
||
@property | ||
def primary_subscription_id(self): | ||
if not self.__primary_subscription_id: | ||
subscriptions = self.subscription_service.get( | ||
subscriptionId=1, | ||
) | ||
self.__primary_subscription_id = subscriptions[0]['aps']['id'] | ||
|
||
return self.__primary_subscription_id | ||
|
||
@property | ||
def plm_service(self): | ||
if not self.__plm_service: | ||
self.__plm_service = self.client(self.PLM_TYPE) | ||
|
||
return self.__plm_service | ||
|
||
@property | ||
def subscription_service(self): | ||
if not self.__subscription_service: | ||
self.__subscription_service = self.client(self.SUBSCRIPTION_TYPE) | ||
|
||
return self.__subscription_service | ||
|
||
def get_product_details(self, product_id: str): | ||
return self.plm_service.appDetails[product_id].get( | ||
fulfillmentSystem='connect', | ||
) | ||
|
||
def install_product(self, product_id: str): | ||
self.plm_service.appDetails[product_id].action( | ||
name='import', | ||
payload={ | ||
'subscriptionId': self.primary_subscription_id, | ||
'fulfillmentSystem': 'connect', | ||
}, | ||
) | ||
|
||
def update_product(self, product_id: str): | ||
return self.plm_service.appDetails[product_id].action( | ||
name='upgrade', | ||
payload={ | ||
'subscriptionId': self.primary_subscription_id, | ||
'fulfillmentSystem': 'connect', | ||
}, | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.