import urllib, urllib2, base64, socket, smtplib, ssl, sys, cookielib, json, os, re from tools.format import readable_json from tools.auth_token import get_csrf_token from tools.apis import upload_file_to_dropbox, create_api_with_file, get_apis_list, create_api, create_new_api_version # Get csrf token csrfToken = get_csrf_token('Akana_svc', 'Pass2017') apiGuid = 'aeb532b5-8daf-46db-93e5-85d9266420b5.travelportAPI' apiName = 'v2' apiDescription = 'New version 2 of jeffreys_api1_v1_live' sourceApiVersionId = 'e3d37d7f-c2ff-447c-b7ab-6ba98db3152a.travelportAPI' createNewApiVersionResp, createNewApiVersionContent = create_new_api_version( csrfToken, apiGuid, apiName, apiDescription, sourceApiVersionId) if createNewApiVersionResp == 200: print 'New API Version created successfully.' print 'createNewApiVersionContent = \n', readable_json( createNewApiVersionContent) else: print 'New API Version creation failed.'
def create_api(token, swaggerFilePath, apiName, apiDescription): ''' INPUT 1. token (string) - Cross site request forgery token used to make rest calls to Akana API. 2. swaggerFilePath (string) - File path of swagger document to upload. OUTPUT None ''' # Update swagger with new name and description swaggerJsonFile = json.load(open(swaggerFilePath)) swaggerJsonFile['info']['title'] = apiName swaggerJsonFile['info']['description'] = apiDescription updatedSwaggerFile = open(swaggerFilePath, 'w+') updatedSwaggerFile.write(json.dumps(swaggerJsonFile)) updatedSwaggerFile.close() fileUploadedResp, uploadedContent = upload_file_to_dropbox( token, swaggerFilePath) dropboxFileId = uploadedContent['DropboxFileId'] serviceName = uploadedContent['ServiceDescriptorDocument'][0][ 'ServiceName'][0] if fileUploadedResp == 200: print 'File uploaded successfully.' descriptorBody = { "DLDescriptor": { "ServiceDescriptorReference": { "ServiceName": "{}".format(serviceName), "FileName": "{}.swagger".format(serviceName), "DropboxFileId": dropboxFileId } } } descriptorBody = json.dumps(descriptorBody) # Create api from uploaded file in dropbox apiCreatedResp, apiCreatedContent = create_api_with_file( token, descriptorBody) if apiCreatedResp == 200: print 'API created successfully.' print 'apiCreatedContent = \n', readable_json(apiCreatedContent) # Add default policies defaultPolicies = [ 'BasicAuditing', 'Travelport AppID', 'Travelport LDAP Authentication', 'Travelport Tracking ID' ] apiName = apiCreatedContent['Name'] apiVersionId = apiCreatedContent['LatestVersionID'] # Display list of all policies policiesList = get_policies_list(token) # Build json policy list to add to api requestedPolicy = {"Policy": []} for policy in policiesList: formattedPolicy = policy_attach_format(policy) if len(defaultPolicies) > 0: for targetPolicy in defaultPolicies: if formattedPolicy["Name"] == targetPolicy: requestedPolicy["Policy"].append(formattedPolicy) # Attach policy to API rawData = json.dumps(requestedPolicy) policyAttachResp = attach_policy_to_api(token, rawData, apiVersionId, 'live') if policyAttachResp == 200: print 'Policy attached to API successfully.' else: print 'Policy attachment to API failed.' # Create sandbox implementation postCreateSandboxImplResp, postCreateSandboxImplContent = create_sandbox_impl( token, apiVersionId) if postCreateSandboxImplResp == 200: print 'Sandbox implementation created successfully.' else: print 'Sandbox implementation creation failed.' else: print 'API creation failed.' print 'File upload successfull.' else: print 'File upload failed.'
# } # ] # }, # "BusinessID":businessId # } # licenseData = json.dumps(licenseData) # addLicenseResp, addLicenseContent = add_licenses(csrfToken, licenseData) # print 'addLicenseResp = ', addLicenseResp # print 'addLicenseContent = ', readable_json(addLicenseContent) # Add scope mapping to API apiVersionId = '23aeb8fb-d857-44b4-a2bc-36db0e29f98b.travelportAPI' scopeMappingData = { "OperationResource": [{ "OperationName": "Silver access", "ResourceID": ["93b0b138-6515-4c08-99a0-27b6db19f1b0.travelportAPI"] }] } scopeMappingData = json.dumps(scopeMappingData) addScopeMappingResp, addScopeMappingContent = add_scope_mapping_to_api( csrfToken, apiVersionId, scopeMappingData) if addScopeMappingResp == 200: print 'Scope added to API successfully.' print 'addScopeMappingContent = ', readable_json(addScopeMappingContent) else: print 'Scope addition to API failed.'
fileUploadedResp, uploadedContent = upload_file_to_dropbox(csrfToken, filePath) dropboxFileId = uploadedContent['DropboxFileId'] serviceName = uploadedContent['ServiceDescriptorDocument'][0]['ServiceName'][0] if fileUploadedResp == 200: print 'File uploaded successfully.' descriptorBody = { "DLDescriptor": { "ServiceDescriptorReference": { "ServiceName": "{}".format(serviceName), "FileName": "{}.swagger".format(serviceName), "DropboxFileId": dropboxFileId } } } descriptorBody = json.dumps(descriptorBody) # Create api from uploaded file in dropbox apiCreatedResp, apiCreatedContent = create_api_with_file( csrfToken, descriptorBody) if apiCreatedResp == 200: print 'API created successfully.' print 'apiCreatedContent = \n', readable_json(apiCreatedContent) else: print 'API creation failed.' else: print 'File upload failed.'
import urllib, urllib2, base64, socket, smtplib, ssl, sys, cookielib, json, os from tools.apis import get_apis_list, get_api_info, get_policies_for_api, get_swagger_doc_for_api from tools.auth_token import get_csrf_token from tools.format import readable_json # Get csrf token csrfToken = get_csrf_token('Akana_svc', 'Pass2017') apiList = get_apis_list(csrfToken) for api in range(len(apiList)): apiInfo = get_api_info(csrfToken, apiList[api]['guid']['value']) swaggerDoc = get_swagger_doc_for_api(csrfToken, apiInfo['LatestVersionID']) print '\n\n' + readable_json(swaggerDoc)
import urllib, urllib2, base64, socket, smtplib, ssl, sys, cookielib, json, os from tools.apis import get_apis_list, get_policies_for_api from tools.auth_token import get_csrf_token from tools.format import readable_json # Get csrf token csrfToken = get_csrf_token('Akana_svc', 'Pass2017') apiList = get_apis_list(csrfToken) print readable_json(apiList)