def download(powerapps_rp, settings, destination): """ Download operation. """ # Prepare folders directory = _prepare_directory( destination=destination, connector_id=settings.connector_id) api_registration = powerapps_rp.get_connector( environment=settings.environment, connector_id=settings.connector_id) if _PROPERTIES not in api_registration: raise CLIError('Properties not present in the api registration information.') api_properties = api_registration[_PROPERTIES] # Save the settings SettingsSerializer.to_json(settings, 'settings.json') # Property whitelist property_keys_whitelist = [ _CONNECTION_PARAMETERS, _ICON_BRAND_COLOR, _CAPABILITIES, _POLICY_TEMPLATE_INSTANCES ] # Remove the keys that aren't present in the property JSON properties_present = list( filter(lambda prop: prop in api_properties, property_keys_whitelist) ) # Only output the white listed properties that are present in the property JSON api_properties_selected = {_PROPERTIES: {}} api_properties_selected[_PROPERTIES] = { prop: api_properties[prop] for prop in properties_present } # Write the api properties open(settings.api_properties, mode='w').write(format_json(api_properties_selected)) # Write the open api definition, # either from swagger URL when available or from swagger property. if _API_DEFINITIONS in api_properties and _ORIGINAL_SWAGGER_URL in api_properties[_API_DEFINITIONS]: original_swagger_url = api_properties[_API_DEFINITIONS][_ORIGINAL_SWAGGER_URL] response = requests.get(original_swagger_url, allow_redirects=True) response_string = response.content.decode('utf-8-sig') swagger = format_json(json.loads(response_string)) open(settings.api_definition, mode='w').write(swagger) # Write the icon if _ICON_URI in api_properties: icon_url = api_properties[_ICON_URI] response = requests.get(icon_url, allow_redirects=True) open(settings.icon, mode='wb').write(response.content) return directory
def get_settings(environment, settings_file, connector_id, powerapps_url, powerapps_version, api_properties, api_definition, icon, client_id=None, tenant=None, authority_url=None, resource=None): """ Loads settings into a settings object. """ # Load from settings file if it is available if settings_file: settings = SettingsSerializer.from_json(settings_file) else: settings = Settings(connector_id=connector_id, environment=environment, powerapps_url=powerapps_url, powerapps_api_version=powerapps_version, api_properties=api_properties, api_definition=api_definition, icon=icon, client_id=client_id, tenant=tenant, authority_url=authority_url, resource=resource) return settings
def write_settings(settings, overwrite): filename = SETTINGS_FILE settings_json = SettingsSerializer.to_json_string(settings) write_with_prompt(filename=filename, mode='w', content=settings_json, overwrite=overwrite)
def get_settings(environment, settings_file, connector_id, powerapps_url, powerapps_version, command_context, api_properties, api_definition, icon): """ Loads settings into a settings object. """ # Load from settings file if it is available if settings_file: settings = SettingsSerializer.from_json(settings_file) else: settings = Settings(connector_id=connector_id, environment=environment, powerapps_url=powerapps_url, powerapps_api_version=powerapps_version, api_properties=api_properties, api_definition=api_definition, icon=icon) return settings