def get_service_by_name(service_name, alias_arg="", params_file_path="", kvp_str=""): service = None if service_name: reg_key = service_name + YAC_SERVICE_SUFFIX # look in remote registry service_contents = get_remote_value(reg_key) if service_contents: # load into dictionary serialized_service = json.loads(service_contents) service = Service(serialized_service, "", alias_arg, params_file_path, kvp_str) return service
def test_clear_fail(self): # create a random value to put into registry original_value = "test-value-" + str(random.randint(1, 1000)) test_key = "test-key-" + str(random.randint(1, 1000)) challenge_phrase = 'test-challenge' + str(random.randint(1, 1000)) set_remote_string_w_challenge(test_key, original_value, challenge_phrase) new_value = "test-value-" + str(random.randint(1, 1000)) try: # attempt clear with a different phrase clear_entry_w_challenge(test_key, challenge_phrase + 'deviation') except RegError as e: # we expect to get an error print(e.msg) # pull value back out returned_value = get_remote_value(test_key) # test that the original value remains self.assertTrue(returned_value == original_value)
def get_file_from_registry(file_key): file_contents = "" reg_key = get_file_reg_key(file_key) # get file from registry file_contents = get_remote_value(reg_key) return file_contents
def test_register(self): # create a random value to put into registry test_value = "test-value-" + str(random.randint(1, 1000)) test_key = "test-key-" + str(random.randint(1, 1000)) # create a key/value pair in registry with a challenge phrase challenge_phrase = 'test' set_remote_string_w_challenge(test_key, test_value, challenge_phrase) # pull value back out returned_value = get_remote_value(test_key) # clean up test key clear_entry_w_challenge(test_key, challenge_phrase) # test that the create was successful self.assertTrue(test_value == returned_value)
def test_clear(self): # create a random value to put into registry test_value = "test-value-" + str(random.randint(1, 1000)) test_key = "test-key-" + str(random.randint(1, 1000)) challenge_phrase = 'test' set_remote_string_w_challenge(test_key, test_value, challenge_phrase) test_value = "test-value-" + str(random.randint(1, 1000)) # clear the value in registry clear_entry_w_challenge(test_key, challenge_phrase) # pull value back out returned_value = get_remote_value(test_key) # test that the clear was successful self.assertTrue(not returned_value)
def get_file_contents(file_key_or_path, servicefile_path=""): file_contents = "" # if file is in registry if file_in_registry(file_key_or_path): file_contents = get_remote_value(file_key_or_path) # if file exists locally elif os.path.exists(file_key_or_path): with open(file_key_or_path) as file_arg_fp: file_contents = file_arg_fp.read() # if file exists relative to the servicefile path elif os.path.exists(os.path.join(servicefile_path, file_key_or_path)): with open(os.path.join(servicefile_path, file_key_or_path)) as file_arg_fp: file_contents = file_arg_fp.read() return file_contents
def localize_file(file_key_or_path, servicefile_path=""): localized_file = "" # if file is in registry if file_in_registry(file_key_or_path): # convert the file to a local version file_contents = get_remote_value(file_key_or_path) localized_file = create_customization_file(file_key_or_path, file_contents) # if file exists locally elif os.path.exists(file_key_or_path): localized_file = file_key_or_path # if file exists relative to the service descriptor elif os.path.exists(os.path.join(servicefile_path, file_key_or_path)): localized_file = os.path.join(servicefile_path, file_key_or_path) return localized_file