def add_project_token(args): check_project_is_set(args) url = args.url + api_projects_endpoint_url + args.project_id + '/tokens' data = { 'description': args.description, #TODO<Steffen> when scope push/pull functionality is implemented, # delete following 2 lines and uncomment next 2 lines 'scope_push': True, 'scope_pull': True #'scope_push': args.scope_push, #'scope_pull': args.scope_pull } response = post(url, data, get_user_headers(), verify=args.ca_bundle, timeout=60) if response.status_code != 200: logger.error(response.json()['message']) return # Print project token to the CLI logger.info('Authentication Token:' + '\nPlease save your token at a secure place. We will not show it to you again.\n') logger.log(response.json()['data']['token'], print_header=False) return response
def get_project_tokens(args): check_project_is_set(args) url = args.url + api_projects_endpoint_url + args.project_id + '/tokens' response = get(url, get_user_headers(), verify=args.ca_bundle, timeout=60) return response
def get_projects(args): infraboxcli.env.check_env_url(args) url = args.url + api_projects_endpoint_url response = get(url, get_user_headers(), verify=args.ca_bundle, timeout=60) return response
def delete_project_token_by_id(args): check_project_is_set(args) url = args.url + api_projects_endpoint_url + args.project_id + '/tokens/' + args.id response = delete(url, get_user_headers(), verify=args.ca_bundle, timeout=60) logger.info(response.json()['message']) return response
def add_secret(args): check_project_is_set(args) url = args.url + api_projects_endpoint_url + args.project_id + '/secrets' data = {'name': args.name, 'value': args.value} response = post(url, data, get_user_headers(), verify=args.ca_bundle, timeout=60) logger.info(response.json()['message']) return response
def delete_project_by_id(args): infraboxcli.env.check_env_url(args) url = args.url + api_projects_endpoint_url + args.id response = delete(url, headers=get_user_headers(), verify=args.ca_bundle, timeout=60) if response.status_code != 200: logger.error(response.json()['message']) else: logger.info(response.json()['message']) return response
def remove_collaborator(args): check_project_is_set(args) all_project_collaborators = get_collaborators(args).json() collaborator_id = None for collaborator in all_project_collaborators: if collaborator['username'] == args.username: collaborator_id = collaborator['id'] break if collaborator_id is None: logger.info('Specified user is not in collaborators list.') return url = args.url + api_projects_endpoint_url + args.project_id + '/collaborators/' + collaborator_id response = delete(url, get_user_headers(), verify=args.ca_bundle, timeout=60) logger.info(response.json()['message']) return response
def create_project(args): infraboxcli.env.check_env_url(args) if not args.private and not args.public: logger.error('Specify if your project is going to be public or private, please.') return if args.private and args.public: logger.error('Project can\'t be public and private simultaneously. ' + 'Choose only one option, please.') return is_private_project = True if args.public: is_private_project = False args.type = args.type.lower() if args.type not in allowed_project_types: logger.error('Provided project type is not supported.' + '\nAllowed project types are: [ {allowed_types} ]' .format(allowed_types=', '.join(allowed_project_types))) return url = args.url + api_projects_endpoint_url data = { 'name': args.name, 'type': args.type, 'private': is_private_project } response = post(url, data=data, headers=get_user_headers(), verify=args.ca_bundle, timeout=60) if response.status_code != 200: logger.error(response.json()['message']) else: logger.info(response.json()['message']) return response