Skip to content

Commit

Permalink
Sara's GithubCode
Browse files Browse the repository at this point in the history
  • Loading branch information
Eric Denekamp committed May 3, 2022
1 parent d6d02df commit 29e7420
Showing 1 changed file with 32 additions and 0 deletions.
32 changes: 32 additions & 0 deletions mwddevopsdemo_ext/extension.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,35 +23,45 @@ def approve_asset_request(self, request, template_id):
}
)
self.logger.info(f"Approved request {request['id']}")

def process_asset_purchase_request(self, request):
self.logger.info(f"Obtained request from company {request['asset']['tiers']['customer']['name']}")
company = request['asset']['tiers']['customer']['name']

self.logger.info(
f"Received event for request {request['id']} in status {request['status']}"
)

if request['status'] == 'pending':
for param in request['asset']['params']:
if (param['id'] == 'unitofmeasure'):
unitofmeasure = param['value']

citieslimit = 0
for item in request['asset']['items']:
if (item['mpn'] == 'citieslimit'):
citieslimit = item['quantity']

newCompany = {
'name': company,
'unitofmeasure': unitofmeasure,
'citieslimit': citieslimit
}

session = requests.Session()
session.headers.update({'content-type': 'application/json', 'x-provider-token': 'osamwd'})
vendorDataResponse = session.post('http://myweatherdemo.learn-cloudblue.com/api/company/', data = json.dumps(newCompany))

self.logger.info(
f"Received vendor response as: {vendorDataResponse.content}"
)

vendorData = vendorDataResponse.json()

self.logger.info(
f"Received event for request id {vendorData['token']} with username {vendorData['username']} and password {vendorData['password']}"
)

self.client.requests[request['id']].update(
{
"asset": {
Expand All @@ -74,37 +84,47 @@ def process_asset_purchase_request(self, request):
)
self.logger.info("Updating fulfillment parameters as follows:"
f"name to {company}, unitofmeasure to {unitofmeasure} and citieslimit to {citieslimit}")

template_id = self.config['ASSET_REQUEST_APPROVE_TEMPLATE_ID']
self.approve_asset_request(request, template_id)

return ProcessingResponse.done()

def process_asset_change_request(self, request):
for item in request['asset']['items']:
if (item['mpn'] == 'citieslimit'):
citieslimit = item['quantity']

if (citieslimit == 0):
#reason = 'it is not allowed to set 0 for the citieslimit'
reason = {
'it is not allowed to set 0 for the citieslimit'
}

session = requests.Session()
session.headers.update({'content-type': 'application/json', 'ApiKey SU-328-329-171': 'dd6bcfceca89405ac54140ca485316f4edb2c618'})
session.post('https://api.connect.cloudblue.com/public/v1/requests/'+request["id"]+'/fail', data = json.dumps(reason))

for param in request['asset']['params']:
if (param['id'] == 'id'):
companyid = param['value']

self.logger.info(
f"The company id is: {companyid}"
)

limit = {
'citieslimit': citieslimit
}

self.logger.info(
f"The new limit is: {limit}"
)

session = requests.Session()
session.headers.update({'content-type': 'application/json', 'x-provider-token': 'osamwd'})
vendorResponse = session.put('http://myweatherdemo.learn-cloudblue.com/api/company/'+companyid, data = json.dumps(limit))

self.logger.info(
f"Received vendor response as: {vendorResponse.content}"
)
Expand All @@ -114,33 +134,45 @@ def process_asset_change_request(self, request):
if (vendorData['citieslimit'] == citieslimit):
template_id = self.config['ASSET_REQUEST_APPROVE_TEMPLATE_ID']
self.approve_asset_request(request, template_id)

return ProcessingResponse.done()

def process_asset_cancel_request(self, request):
self.logger.info(
f"Received event for request {request['id']} "
f"in status {request['status']}"
)

if request['status'] == 'pending':
for param in request['asset']['params']:
if (param['id'] == 'id'):
companyid = param['value']

self.logger.info(
f"The company id is: {companyid}"
)

company = {

}

self.logger.info(
f"The company to delete is: {company}"
)

template_id = self.config['ASSET_REQUEST_APPROVE_TEMPLATE_ID']
self.approve_asset_request(request, template_id)

session = requests.Session()
session.headers.update({'content-type': 'application/json', 'x-provider-token': 'osamwd'})
vendorResponse = session.delete('http://myweatherdemo.learn-cloudblue.com/api/company/'+companyid, data = json.dumps(company))

return ProcessingResponse.done()

def validate_asset_purchase_request(self, request):
self.logger.info(f"Obtained request with id {request['id']}")
return ValidationResponse.done(request)

def validate_asset_change_request(self, request):
self.logger.info(f"Obtained request with id {request['id']}")
return ValidationResponse.done(request)

0 comments on commit 29e7420

Please sign in to comment.