Example #1
0
def main():
    parser = argparse.ArgumentParser()

    parser.add_argument('-u', '--username', type=str, required=True)
    parser.add_argument('-p', '--password', type=str, required=True)
    parser.add_argument('--ssl', default=False, action='store_true')

    subparsers = parser.add_subparsers()
    config_parser = subparsers.add_parser('config')
    config_parser.add_argument('-c', '--config', type=str, required=True)
    config_parser.add_argument('-i',
                               '--iaas',
                               type=str,
                               required=True,
                               choices=['aws', 'azure', 'openstack'])

    debug_parser = subparsers.add_parser('debug')
    debug_parser.add_argument('--print-agent-env',
                              default=True,
                              action='store_true')

    kwargs = parser.parse_args()

    headers = {'Authorization': 'Basic ' + base64_encode('{user}:{password}'.format(user=kwargs.username,password=kwargs.password))}
    cfy_client = CloudifyClient(host='localhost', port=443, protocol='https', headers=headers, trust_all=True)

    if 'print_agent_env' in kwargs:
        print_agent_env(cfy_client)
    else:
        configure_manager(cfy_client,
                          kwargs.iaas,
                          kwargs.config)
Example #2
0
    def to_url(self, value):
        """Object ID converter to url.

        Returns:
          Base64
        """
        return base64_encode(value.binary)
Example #3
0
def create_auth_header(username, password):
    header = None

    if username and password:
        credentials = '{0}:{1}'.format(username, password)
        header = {CLOUDIFY_AUTHENTICATION_HEADER: base64_encode(credentials)}

    return header
Example #4
0
def get_auth_header(username=None, password=None, token=None):
    header = {}
    if username and password:
        credentials = '{0}:{1}'.format(username, password)
        header[CLOUDIFY_AUTHORIZATION_HEADER] = base64_encode(credentials)
    elif token:
        header[CLOUDIFY_AUTH_TOKEN_HEADER] = token
    return header
 def test_invalid_one_part_header(self):
     credentials = 'alice'
     header = {
         CLOUDIFY_AUTH_HEADER:
             BASIC_AUTH_PREFIX + base64_encode(credentials)
     }
     client = self.create_client(headers=header)
     self.assertRaises(UserUnauthorizedError, client.deployments.list)
Example #6
0
def get_auth_header(username, password):
    header = None

    if username and password:
        credentials = '{0}:{1}'.format(username, password)
        header = {
            constants.CLOUDIFY_AUTHENTICATION_HEADER:
                constants.BASIC_AUTH_PREFIX + ' ' + base64_encode(credentials)}

    return header
    def create_auth_header(username=None, password=None, token=None):
        header = None
        # using or to allow testing of username without password and vice-versa
        if username or password:
            credentials = "{0}:{1}".format(username, password)
            header = {CLOUDIFY_AUTH_HEADER: BASIC_AUTH_PREFIX + base64_encode(credentials)}
        elif token:
            header = {CLOUDIFY_AUTH_TOKEN_HEADER: token}

        return header
Example #8
0
def get_rest_client(security_enabled,
                    rest_host,
                    rest_protocol,
                    rest_port,
                    rest_username=None,
                    rest_password=None,
                    rest_token=None,
                    verify_rest_certificate=False,
                    ssl_cert_path=None,
                    bypass_maintenance_mode=False):

    headers = {}
    if bypass_maintenance_mode:
        headers['X-BYPASS-MAINTENANCE'] = 'true'

    if not security_enabled:
        return CloudifyClient(host=rest_host,
                              protocol=rest_protocol,
                              port=rest_port,
                              headers=headers)

    if (not rest_username or not rest_password) and not rest_token:
        raise ValueError('REST credentials are missing! Either username and '
                         'password, or an auth token are required to create '
                         'a REST client for a secured manager [{0}]'
                         .format(rest_host))

    if rest_token:
        headers['Authentication-Token'] = rest_token
    else:
        credentials = '{0}:{1}'.format(rest_username, rest_password)
        headers['Authorization'] = 'Basic ' + base64_encode(credentials)

    if verify_rest_certificate:
        if not ssl_cert_path:
            raise ValueError('missing ssl_cert_path, verifying REST '
                             'certificate cannot be performed'.
                             format(rest_host))
        trust_all = False
    else:
        trust_all = True
        ssl_cert_path = None

    rest_client = CloudifyClient(host=rest_host,
                                 protocol=rest_protocol,
                                 port=rest_port,
                                 headers=headers,
                                 trust_all=trust_all,
                                 cert=ssl_cert_path)

    return rest_client
def get_rest_client():
    """
    :returns: A REST client configured to connect to the manager in context
    :rtype: cloudify_rest_client.CloudifyClient
    """
    rest_host = utils.get_manager_rest_service_host()
    rest_port = utils.get_manager_rest_service_port()
    rest_protocol = constants.DEFAULT_PROTOCOL

    # handle maintenance mode
    headers = {}
    if utils.get_is_bypass_maintenance():
        headers['X-BYPASS-MAINTENANCE'] = 'True'

    # handle security
    if not utils.is_security_enabled():
        rest_client = CloudifyClient(rest_host,
                                     rest_port,
                                     rest_protocol,
                                     headers=headers)
    else:
        # security enabled
        token = utils.get_rest_token()
        if token is None:
            credentials = '{0}:{1}'.format(utils.get_rest_username(),
                                           utils.get_rest_password())
            auth_header = {
                constants.CLOUDIFY_AUTHENTICATION_HEADER:
                constants.BASIC_AUTH_PREFIX + ' ' + base64_encode(credentials)}
        else:
            auth_header = {
                constants.CLOUDIFY_TOKEN_AUTHENTICATION_HEADER: token
            }
        headers.update(auth_header)
        rest_port = utils.get_manager_rest_service_port()
        rest_protocol = utils.get_manager_rest_service_protocol()

        if utils.is_verify_rest_certificate():
            trust_all = False
            cert_path = utils.get_local_rest_certificate()
        else:
            trust_all = True
            cert_path = None

        rest_client = CloudifyClient(host=rest_host, port=rest_port,
                                     protocol=rest_protocol, headers=headers,
                                     cert=cert_path, trust_all=trust_all)

    return rest_client
Example #10
0
def request_reset_password():
    email = request.form.get('email')
    info = db['users'].find_one(email=email)
    if info is None:
        return render_template('reset_password_sent.html')
    token = base64_encode(signer.sign(email))

    msg = MIMEText(render_template('reset_password.email', token=token))
    msg['Subject'] = _('Password reset')
    msg['From'] = RESET_PASSWORD_EMAIL
    msg['To'] = email

    s = smtplib.SMTP(SMTP_ADDRESS, SMTP_PORT)
    s.starttls()
    s.login(SMTP_USER_NAME, SMTP_PASSWORD)
    s.sendmail(RESET_PASSWORD_EMAIL, [email], msg.as_string())
    s.quit()

    return render_template('reset_password_sent.html')
Example #11
0
 def to_url(self, value):
     """Object ID converter to url
         Returns:
             Base64
     """
     return base64_encode(value.binary)
Example #12
0
 def to_url(self, value):
     """
     """
     return base64_encode(value.binary)
Example #13
0
 def generate_subscription_token(company_name, from_date, to_date):
     serializer = JSONSerializer(current_app.config['SECRET_KEY'])
     obj = {'company': company_name, 'from': from_date.isoformat(),
            'to': to_date.isoformat()}
     return base64_encode(serializer.dumps(obj)).decode('utf-8')
Example #14
0
 def encrypt(self, textData):  # encrypt data method
     padData = pad(textData.encode('utf-8'), AES.block_size)
     encData = self.cipher.encrypt(padData)
     b64EncData = str(base64_encode(encData), 'utf-8')
     print('encryptData:', b64EncData)
     return b64EncData
Example #15
0
 def generate_auth_token(user_id):
     """ Generates an authentication token """
     return base64_encode(Secure.__timed_serializer.dumps(
         {"id": user_id})).decode("utf-8")
Example #16
0
def nicefy(uglytext):
    "Convert a mongodb _id as a nice plain text"
    return base64_encode(str(uglytext)).decode()
Example #17
0
 def serialize_id(cls, pk):
     s = URLSafeSerializer(settings.SECRET_KEY)
     hashed_pk = s.dumps(pk)
     return base64_encode(hashed_pk).decode('utf-8')
Example #18
0
def encode(value):
    return base64_encode(value)
Example #19
0
 def to_url(self, value):
     return base64_encode(value.binary).decode('utf-8')
Example #20
0
 def to_url(self, value):
     return base64_encode(value.binary)
Example #21
0
def base64_encode_param(endpoint_or_url, qparams=None):
    param = get_url(endpoint_or_url, qparams)
    return base64_encode(param).decode('utf-8')