How to use the blackduck.HubRestApi.CreateFailedAlreadyExists function in blackduck

To help you get started, we’ve selected a few blackduck examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github blackducksoftware / hub-rest-api-python / blackduck / HubRestApi.py View on Github external
# whereas v3 returns the newly created object in the response json
        if response.status_code == 201:
            if "location" in response.headers:
                return response.headers["location"]
            else:
                try:
                    response_json = response.json()
                except json.decoder.JSONDecodeError:
                    logging.warning('did not receive any json data back')
                else:
                    if '_meta' in response_json and 'href' in response_json['_meta']:
                        return response_json['_meta']['href']
                    else:
                        return response_json
        elif response.status_code == 412:
            raise CreateFailedAlreadyExists("Failed to create the object because it already exists - url {}, body {}, response {}".format(url, json_body, response))
        else:
            raise CreateFailedUnknown("Failed to create the object for an unknown reason - url {}, body {}, response {}".format(url, json_body, response))
github blackducksoftware / hub-rest-api-python / examples / upload_policies.py View on Github external
args.dest_username,
	args.dest_password,
	write_config_flag=False,
	insecure=True)

f =  open(args.policies_file, 'r')
policies_to_copy = json.load(f)

if not policies_to_copy:
	logging.debug("No policies to copy, sure you used the right file?")
	
for policy_info in policies_to_copy:
	new_policy_result = {}
	try:
		new_policy_result = dest_hub.create_policy(policy_info)
	except CreateFailedAlreadyExists:
		logging.warning("policy with name {} already exists".format(policy_info['name']))
	except:
		logging.error("Unknown error occurred while attempting to add policy {}".format(
			policy_info['name']), exc_info=True)
	else:
		logging.info("Created new policy, details {}".format(new_policy_result))
github blackducksoftware / hub-rest-api-python / blackduck / HubRestApi.py View on Github external
# whereas v3 returns the newly created object in the response json
        if response.status_code == 201:
            if "location" in response.headers:
                return response.headers["location"]
            else:
                try:
                    response_json = response.json()
                except json.decoder.JSONDecodeError:
                    logging.warning('did not receive any json data back')
                else:
                    if '_meta' in response_json and 'href' in response_json['_meta']:
                        return response_json['_meta']['href']
                    else:
                        return response_json
        elif response.status_code == 412:
            raise CreateFailedAlreadyExists("Failed to create the object because it already exists - url {}, body {}, response {}".format(url, json_body, response))
        else:
            raise CreateFailedUnknown("Failed to create the object for an unknown reason - url {}, body {}, response {}".format(url, json_body, response))