Set up nova credentials
355785
def _auth(profile=None, **kwargs):
    '''
    
    '''
    keystone_api_args = None
    if kwargs is not None:
        if kwargs.get('keystone_api_args') is not None:
            keystone_api_args = kwargs['keystone_api_args']

    if profile:
        credentials = __salt__['config.option'](profile)
        user = credentials['keystone.user']
        password = credentials['keystone.password']
        tenant = credentials['keystone.tenant']
        auth_url = credentials['keystone.auth_url']
        region_name = credentials.get('keystone.region_name', None)
        api_key = credentials.get('keystone.api_key', None)
        os_auth_system = credentials.get('keystone.os_auth_system', None)
        use_keystoneauth = credentials.get('keystone.use_keystoneauth', False)
    else:
        user = __salt__['config.option']('keystone.user')
        password = __salt__['config.option']('keystone.password')
        tenant = __salt__['config.option']('keystone.tenant')
        auth_url = __salt__['config.option']('keystone.auth_url')
        region_name = __salt__['config.option']('keystone.region_name')
        api_key = __salt__['config.option']('keystone.api_key')
        os_auth_system = __salt__['config.option']('keystone.os_auth_system')
        use_keystoneauth = __salt__['config.option']('keystone.use_keystoneauth')

    # Override pillar settings with settings provided by module argument
    if keystone_api_args:
        user = keystone_api_args.get('user', user)
        password = keystone_api_args.get('password', password)
        tenant = keystone_api_args.get('tenant', tenant)
        auth_url = keystone_api_args.get('auth_url', auth_url)
        region_name = keystone_api_args.get('region_name', region_name)
        api_key = keystone_api_args.get('api_key', api_key)
        os_auth_system = keystone_api_args.get('os_auth_system', os_auth_system)
        use_keystoneauth = keystone_api_args.get('use_keystoneauth', use_keystoneauth)

    if use_keystoneauth is True:
        if profile:
            credentials = __salt__['config.option'](profile)
            project_id = credentials.get('keystone.project_id', None)
            project_name = credentials.get('keystone.project_name', None)
            user_domain_name = credentials.get('keystone.user_domain_name', None)
            project_domain_name = credentials.get('keystone.project_domain_name', None)
            verify = credentials.get('keystone.verify', None)
        else:
            project_id = __salt__['config.option']('keystone.project_id')
            project_name = __salt__['config.option']('keystone.project_name')
            user_domain_name = __salt__['config.option']('keystone.user_domain_name')
            project_domain_name = __salt__['config.option']('keystone.project_domain_name')
            verify = __salt__['config.option']('keystone.verify')

        # Override pillar settings with settings provided by module argument
        if keystone_api_args:
            project_id = keystone_api_args.get('project_id', project_id)
            project_name = keystone_api_args.get('project_name', project_name)
            user_domain_name = keystone_api_args.get('user_domain_name', user_domain_name)
            project_domain_name = keystone_api_args.get('project_domain_name', project_domain_name)
            verify = keystone_api_args.get('verify', verify)

        send_kwargs = {
            'username': user,
            'password': password,
            'project_id': project_id,
            'auth_url': auth_url,
            'region_name': region_name,
            'use_keystoneauth': use_keystoneauth,
            'verify': verify,
            'project_name': project_name,
            'project_domain_name': project_domain_name,
            'user_domain_name': user_domain_name
        }
    else:
        send_kwargs = {
            'username': user,
            'password': password,
            'api_key': api_key,
            'project_id': tenant,
            'auth_url': auth_url,
            'region_name': region_name,
            'os_auth_plugin': os_auth_system
        }
    log.debug('SEND_KWARGS: %s', send_kwargs)
    return suon.SaltNova(**send_kwargs)
1058144
def authenticated(f):
    """"""
    @wraps(f)
    def new_f(self, *args, **kwargs):
        if not self.nova_client.client.auth_token:
            self.authenticate()
        return f(self, *args, **kwargs)
    return new_f
1341162
def authenticate_credentials(self, userid, password, request=None):
        """"""

        user = auth.authenticate(username=userid, password=password)

        if user is None or (user and not user.is_active):
            raise exceptions.AuthenticationFailed("Invalid username/password.")

        return (user, None)
1232009
def deploy(self, image_name, ip, flavor='m1.small'):
        
        body_value = {
            "port": {
                "admin_state_up": True,
                "name": self.name + '_provision',
                "network_id": os_utils.get_network_id(self.nova_api, 'provision_bob'),
                'fixed_ips': [{'ip_address': ip}]}}
        response = self.neutron.create_port(body=body_value)
        self._provision_port_id = response['port']['id']
        self.mac = response['port']['mac_address']

        image_id_to_boot_from = os_utils.get_image_id(self.nova_api, image_name)
        flavor_id = os_utils.get_flavor_id(self.nova_api, flavor)
        # TODO(Gonéri): We don't need keypair for the BM nodes
        keypair_id = os_utils.get_keypair_id(self.nova_api, self._keypair)
        # Ensure with get DHCP lease on the provision network first
        nics = [{'port-id': self._provision_port_id}]

        self._os_instance = os_provisioner.build_openstack_instance(
            self.nova_api,
            self.name,
            image_id_to_boot_from,
            flavor_id,
            keypair_id,
            nics)

        if not self._os_instance:
            LOG.error("deployment has failed")
            raise Exception()

        os_provisioner.add_provision_security_group(self.nova_api)
        os_utils.add_security_groups(self._os_instance, ['provision'])
        os_utils.add_security_groups(self._os_instance, self._security_groups)
        LOG.info("add security groups '%s'" % self._security_groups)
        LOG.info("instance '%s' ready to use" % self.name)

        # the instance should be off for Ironic
        self._os_instance.stop()
883848
private static Credentials newNTCredentials(HttpClientSettings settings) {
        return new NTCredentials(settings.getProxyUsername(),
                settings.getProxyPassword(),
                settings.getProxyWorkstation(),
                settings.getProxyDomain());
    }
956407
def _auth(profile=None):
    '''
    
    '''
    if profile:
        credentials = __salt__['config.option'](profile)
        user = credentials['keystone.user']
        password = credentials['keystone.password']
        tenant = credentials['keystone.tenant']
        auth_url = credentials['keystone.auth_url']
        region_name = credentials.get('keystone.region_name', None)
        service_type = credentials.get('keystone.service_type', 'network')
        os_auth_system = credentials.get('keystone.os_auth_system', None)
        use_keystoneauth = credentials.get('keystone.use_keystoneauth', False)
        verify = credentials.get('keystone.verify', True)
    else:
        user = __salt__['config.option']('keystone.user')
        password = __salt__['config.option']('keystone.password')
        tenant = __salt__['config.option']('keystone.tenant')
        auth_url = __salt__['config.option']('keystone.auth_url')
        region_name = __salt__['config.option']('keystone.region_name')
        service_type = __salt__['config.option']('keystone.service_type')
        os_auth_system = __salt__['config.option']('keystone.os_auth_system')
        use_keystoneauth = __salt__['config.option']('keystone.use_keystoneauth')
        verify = __salt__['config.option']('keystone.verify')

    if use_keystoneauth is True:
        project_domain_name = credentials['keystone.project_domain_name']
        user_domain_name = credentials['keystone.user_domain_name']

        kwargs = {
            'username': user,
            'password': password,
            'tenant_name': tenant,
            'auth_url': auth_url,
            'region_name': region_name,
            'service_type': service_type,
            'os_auth_plugin': os_auth_system,
            'use_keystoneauth': use_keystoneauth,
            'verify': verify,
            'project_domain_name': project_domain_name,
            'user_domain_name': user_domain_name
        }
    else:
        kwargs = {
            'username': user,
            'password': password,
            'tenant_name': tenant,
            'auth_url': auth_url,
            'region_name': region_name,
            'service_type': service_type,
            'os_auth_plugin': os_auth_system
        }

    return suoneu.SaltNeutron(**kwargs)
622755
def credentials(opts)
      calback = lambda do
        credentials = nil
        unless opts[:access_key_id].empty? or opts[:secret_access_key].empty?
          credentials = Aws::Credentials.new opts[:access_key_id], opts[:secret_access_key]
        else
          if opts[:assume_role_arn].nil?
            if opts[:ecs_container_credentials_relative_uri].nil?
              credentials = Aws::SharedCredentials.new({retries: 2}).credentials
              credentials ||= Aws::InstanceProfileCredentials.new.credentials
              credentials ||= Aws::ECSCredentials.new.credentials
            else
              credentials = Aws::ECSCredentials.new({
                credential_path: opts[:ecs_container_credentials_relative_uri]
              }).credentials
            end
          else
            credentials = sts_credential_provider({
                            role_arn: opts[:assume_role_arn],
                            role_session_name: opts[:assume_role_session_name],
                            region: opts[:region]
                          }).credentials
          end
        end
        raise "No valid AWS credentials found." unless credentials.set?
        credentials
      end
      def calback.inspect
        credentials = self.call
        credentials.credentials.inspect
      end
      calback
    end
260487
def update_credentials(self, key, secret):
        '''  '''
        self.access_key = key
        self.secret_key = secret
367498
def authenticate(self, credentials):
        
        auth.authenticate(credentials, self)
        self.authset.add(credentials)
250527
def add_credential(rack_env, type, credential)
      Env.new(rack_env).tap do |env|
        env.credentials[type] = credential
      end.to_rack
    end
1350808
def load_fog_credentials(dot_fog = '.fog')
      default = get_fog_credentials(dot_fog)

      raise "You must specify an aws_access_key_id in your .fog file (#{dot_fog}) for ec2 instances!" unless default[:aws_access_key_id]
      raise "You must specify an aws_secret_access_key in your .fog file (#{dot_fog}) for ec2 instances!" unless default[:aws_secret_access_key]

      Aws::Credentials.new(
        default[:aws_access_key_id],
        default[:aws_secret_access_key],
        default[:aws_session_token]
      )
    end
1241865
def set_credentials(self, username, password):
        
        if username is not None:
            self._username = username

        if password is not None:
            self._password = password
959329
def update_credentials(self, aws_access_key_id, aws_secret_access_key):
        '''  '''
        self.aws_access_key_id = aws_access_key_id
        self.aws_secret_access_key = aws_secret_access_key
315481
private void addNtCredentials(NtAuthInfo authInfo, Map<AuthScope, Credentials> credentialsMap) {
        logger.info("NT authentication for: {}", authInfo.getLoginTarget());
        try {
            Credentials credentials = new NTCredentials(authInfo.getUsername(),
                    authInfo.getPassword(), InetAddress.getLocalHost().getHostName(),
                    authInfo.getDomain());
            credentialsMap.put(new AuthScope(authInfo.getHost(), authInfo.getPort()), credentials);
        } catch (UnknownHostException e) {
            logger.error("Error creating NT credentials", e);
        }
    }
851635
def setup_connection():
    

    # get connection parameters, first from environment variables if they are
    # defined, otherwise from .nipaprc
    try:
        con_params = {
            'username': os.getenv('NIPAP_USERNAME') or cfg.get('global', 'username'),
            'password': os.getenv('NIPAP_PASSWORD') or cfg.get('global', 'password'),
            'hostname': os.getenv('NIPAP_HOST') or cfg.get('global', 'hostname'),
            'port'    : os.getenv('NIPAP_PORT') or cfg.get('global', 'port')
        }
    except (configparser.NoOptionError, configparser.NoSectionError) as exc:
        print("ERROR:", str(exc), file=sys.stderr)
        print("HINT: Please define the username, password, hostname and port in your .nipaprc under the section 'global' or provide them through the environment variables NIPAP_HOST, NIPAP_PORT, NIPAP_USERNAME and NIPAP_PASSWORD.", file=sys.stderr)
        sys.exit(1)

    # if we haven't got a password (from env var or config) we interactively
    # prompt for one
    if con_params['password'] is None:
        import getpass
        con_params['password'] = getpass.getpass()

    # build XML-RPC URI
    pynipap.xmlrpc_uri = "http://%(username)s:%(password)s@%(hostname)s:%(port)s" % con_params

    ao = pynipap.AuthOptions({
        'authoritative_source': 'nipap',
        'username': os.getenv('NIPAP_IMPERSONATE_USERNAME') or con_params['username'],
        'full_name': os.getenv('NIPAP_IMPERSONATE_FULL_NAME'),
        })
1250311
def connect_to_rackspace(region,
                         access_key_id,
                         secret_access_key):
    
    pyrax.set_setting('identity_type', 'rackspace')
    pyrax.set_default_region(region)
    pyrax.set_credentials(access_key_id, secret_access_key)
    nova = pyrax.connect_to_cloudservers(region=region)
    return nova
570008
def authenticate_through_netrc(path=None):
    
    errors = []
    netrc_machine = 'coursera-dl'
    paths = [path] if path else get_config_paths("netrc")
    for path in paths:
        try:
            logging.debug('Trying netrc file %s', path)
            auths = netrc.netrc(path).authenticators(netrc_machine)
        except (IOError, netrc.NetrcParseError) as e:
            errors.append(e)
        else:
            if auths is None:
                errors.append('Didn\'t find any credentials for ' +
                              netrc_machine)
            else:
                return auths[0], auths[2]

    error_messages = '\n'.join(str(e) for e in errors)
    raise CredentialsError(
        'Did not find valid netrc file:\n' + error_messages +
        '\nPlease run this command: chmod og-rw ~/.netrc')