Beispiel #1
0
def login(args):
    if args.remote_url:
        args.url = args.remote_url

    if args.remote_url and not validate_url(args.remote_url):
        logger.error('Invalid url.')
        exit(1)

    infraboxcli.env.check_env_url(args)

    email = args.email
    password = args.password

    if not email:
        email = raw_input("Email: ")
        # Don't allow to pass password without email
        password = None

    if not password:
        password = getpass.getpass('Password: '******'account/login'
    response = post(url,
                    data,
                    cookies_handler=save_user_token,
                    verify=args.ca_bundle)

    return response
Beispiel #2
0
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
Beispiel #3
0
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
Beispiel #4
0
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