def push_apiproducts(self, file): apiproduct = read_file(file, type='json') self._apiproduct_name = apiproduct['name'] try: self.get_api_product() console.echo(f'Updating {self._apiproduct_name}') console.echo(self.update_api_product(body).text) except HTTPError as e: if e.response.status_code != 404: raise e console.echo(f'Creating {self._apiproduct_name}') console.echo(self.create_api_product(body).text)
def push_targetserver(self, environment, file): targetserver = read_file(file, type='json') self._targetserver_name = targetserver['name'] try: self.get_targetserver(environment) console.echo(f'Updating {self._targetserver_name}') console.echo(self.update_a_targetserver(environment, body).text) except HTTPError as e: if e.response.status_code != 404: raise e console.echo(f'Creating {self._targetserver_name}') console.echo(self.create_a_targetserver(environment, body).text)
def decrypt_file(symmetric_key, file, verbose, silent): contents = read_file(file, type='json') decrypted_count = 0 console.echo('Decrypting... ', end='', flush=True) contents, decrypted_count = Keyvaluemaps.encrypt_decrypt_keyvaluemap( contents, symmetric_key, encrypt=False) if decrypted_count: write_file(contents, file, indent=2) console.echo('Done') return contents console.echo('None') return ''
def push_data_masks_for_an_api_proxy(self, file): maskconfig = read_file(file, type='json') maskconfig_name = maskconfig['name'] try: self.get_data_mask_details_for_an_api_proxy(maskconfig_name) console.echo(f'Updating {maskconfig_name} for {self._api_name}') console.echo(self.create_data_masks_for_an_api_proxy(body).text) except HTTPError as e: if e.response.status_code != 404: raise e console.echo(f'Creating {maskconfig_name} for {self._api_name}') console.echo(self.create_data_masks_for_an_api_proxy(body).text)
def push_cache(self, environment, file): cache = read_file(file, type='json') self._cache_name = cache['name'] try: self.get_information_about_a_cache(environment) console.echo(f'Updating {self._cache_name}') console.echo( self.update_a_cache_in_an_environment(environment, body).text) except HTTPError as e: if e.response.status_code != 404: raise e console.echo(f'Creating {self._cache_name}') console.echo( self.create_a_cache_in_an_environment(environment, body).text)
def push_keyvaluemap(self, environment, file, secret=None): local_map = read_file(file, type='json') if secret: console.echo('Decrypting... ', end='', flush=True) local_map, decrypted_count = KeyvaluemapsSerializer( ).encrypt_decrypt_keyvaluemap(local_map, secret, encrypt=False) if decrypted_count: console.echo('Done') else: console.echo('None') self._map_name = local_map['name'] try: remote_map = self.get_keyvaluemap_in_an_environment( environment).json() _, deleted_keys = KeyvaluemapsSerializer().diff_kvms( local_map, remote_map) local_map_updated = { 'entry': [ entry for entry in local_map['entry'] if entry not in remote_map['entry'] ] } if deleted_keys: self._Keyvaluemaps__delete_entries(environment, deleted_keys) console.echo('Removed entries.') if local_map_updated['entry']: for entry in tqdm(local_map_updated['entry'], **TQDM_KWARGS('Updating')): self._Keyvaluemaps__create_or_update_entry( environment, entry) console.echo('Updated entries.') if not deleted_keys and not local_map_updated['entry']: console.echo('All entries up-to-date.') except HTTPError as e: if e.response.status_code != 404: raise e console.echo(f'Creating {self._map_name}') console.echo( self.create_keyvaluemap_in_an_environment( environment, json.dumps(local_map)).text)