Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
keystone_v3 = KeystoneClientV3(session=os_conn.session)
domain = keystone_v3.domains.find(name=domain_name)
user = keystone_v3.users.find(domain=domain, name=user_name)
logger.info("Setting role 'admin' to user {0}".format(user_name))
role_admin = keystone_v3.roles.find(name="admin")
keystone_v3.roles.grant(role=role_admin, user=user, domain=domain)
role_assignments = keystone_v3.role_assignments.list(domain=domain)
domain_users_ids = [du.user["id"] for du in role_assignments]
assert user.id in domain_users_ids
logger.info("Login as {0}".format(user_name))
controller_ip = env.get_primary_controller_ip()
auth_url = 'http://{0}:5000/v3'.format(controller_ip)
auth = v3.Password(auth_url=auth_url,
username=user_name,
password=user_pass,
domain_name=domain_name,
user_domain_name=domain_name)
sess = session.Session(auth=auth)
keystone_v3 = KeystoneClientV3(session=sess)
basic_check(keystone_v3, domain_name="openldap1")
def get_auth_plugin(opts):
auth_version = guess_auth_version(opts)
if opts.os_username:
if auth_version == '3':
return v3.Password(auth_url=opts.os_auth_url,
username=opts.os_username,
password=opts.os_password,
project_name=opts.os_project_name,
user_domain_name=opts.os_user_domain_name,
project_domain_name=opts.os_project_domain_name)
elif auth_version == '2.0':
return v2.Password(auth_url=opts.os_auth_url,
username=opts.os_username,
password=opts.os_password,
tenant_name=opts.os_tenant_name)
elif opts.os_token:
if auth_version == '3':
return v3.Token(auth_url=opts.os_auth_url,
token=opts.os_token,
project_name=opts.os_project_name,
project_domain_name=opts.os_project_domain_name)
user_domain_name=None, domain_name=None,
project_domain_name=None, project_name=None):
"""Return a keystone session object"""
ep = self.get_keystone_endpoint(keystone_ip,
api_version=api_version,
admin_port=admin_port)
if api_version == 2:
auth = v2.Password(
username=username,
password=password,
tenant_name=project_name,
auth_url=ep
)
sess = keystone_session.Session(auth=auth)
else:
auth = v3.Password(
user_domain_name=user_domain_name,
username=username,
password=password,
domain_name=domain_name,
project_domain_name=project_domain_name,
project_name=project_name,
auth_url=ep
)
sess = keystone_session.Session(auth=auth)
return (sess, auth)
def init_os():
# Authenticate to keystone
# http://docs.openstack.org/developer/keystoneauth/using-sessions.html
# http://docs.openstack.org/developer/python-glanceclient/apiv2.html
keystone_addr = STATE['config']['vip']
auth = v3.Password(auth_url='http://%s:5000/v3' % keystone_addr,
username='admin',
password='demo',
project_name='admin',
user_domain_id='Default',
project_domain_id='default')
sess = session.Session(auth=auth)
# Install `member` role
keystone = kclient.Client(session=sess)
role_name = 'member'
if role_name not in map(attrgetter('name'), keystone.roles.list()):
logger.info("Creating role %s" % role_name)
keystone.roles.create(role_name)
# Install cirros with glance client if absent
glance = gclient.Client('2', session=sess)
V3OidcPassword = oidc.OidcPassword
"""See :class:`keystoneauth1.identity.v3.oidc.OidcPassword`"""
V3OidcAuthorizationCode = oidc.OidcAuthorizationCode
"""See :class:`keystoneauth1.identity.v3.oidc.OidcAuthorizationCode`"""
V3OidcAccessToken = oidc.OidcAccessToken
"""See :class:`keystoneauth1.identity.v3.oidc.OidcAccessToken`"""
V3TOTP = v3.TOTP
"""See :class:`keystoneauth1.identity.v3.TOTP`"""
V3TokenlessAuth = v3.TokenlessAuth
"""See :class:`keystoneauth1.identity.v3.TokenlessAuth`"""
V3ApplicationCredential = v3.ApplicationCredential
"""See :class:`keystoneauth1.identity.v3.ApplicationCredential`"""
V3MultiFactor = v3.MultiFactor
"""See :class:`keystoneauth1.identity.v3.MultiFactor`"""
__all__ = ('BaseIdentityPlugin',
'Password',
'Token',
'V2Password',
'V2Token',
'V3Password',
'V3Token',
'V3OidcPassword',
'V3OidcAuthorizationCode',
'V3OidcAccessToken',
'V3TOTP',
auth = None
keystone_auth = {}
rendered_doc = []
sess = None
# Read and parse shiyard.conf
config = configparser.ConfigParser()
config.read(self.shipyard_conf)
# Construct Session Argument
for attr in ('auth_url', 'password', 'project_domain_name',
'project_name', 'username', 'user_domain_name'):
keystone_auth[attr] = config.get('keystone_authtoken', attr)
# Set up keystone session
auth = keystone_v3.Password(**keystone_auth)
sess = keystone_session.Session(auth=auth)
logging.info("Setting up DeckHand Client...")
# Set up DeckHand Client
# NOTE: The communication between the Airflow workers and Deckhand
# happens via the 'internal' endpoint and not the 'public' endpoint.
# Hence we will need to override the 'endpoint_type' from the default
# 'public' endpoint to 'internal' endpoint.
deckhandclient = deckhand_client.Client(session=sess,
endpoint_type='internal')
logging.info("Retrieving Rendered Document...")
# Retrieve Rendered Document
try:
def get_plugin(self, auth_url=None, username=None, password=None,
user_domain_name=None, **kwargs):
if not all((auth_url, username, password)):
return None
LOG.debug('Attempting to authenticate for %s', username)
return v3_auth.Password(auth_url=auth_url,
username=username,
password=password,
user_domain_name=user_domain_name,
unscoped=True)
def _get_auth(self):
if self.context.auth_token_info:
access_info = ka_access.create(body=self.context.auth_token_info,
auth_token=self.context.auth_token)
auth = ka_access_plugin.AccessInfoPlugin(access_info)
elif self.context.auth_token:
auth = ka_v3.Token(auth_url=self.auth_url,
token=self.context.auth_token)
elif self.context.trust_id:
auth_info = {
'auth_url': self.auth_url,
'username': self.context.user_name,
'password': self.context.password,
'user_domain_id': self.context.user_domain_id,
'user_domain_name': self.context.user_domain_name,
'trust_id': self.context.trust_id
}
auth = ka_v3.Password(**auth_info)
elif self.context.is_admin:
try:
auth = ka_loading.load_auth_from_conf_options(
CONF, ksconf.CFG_GROUP)
def _get_client(self, username, password, project_name=None):
if project_name:
auth = keystone_v3_auth.Password(
auth_url=self.auth_url,
username=username,
password=password,
project_name=project_name,
project_domain_id=self.project_domain_id,
user_domain_id=self.user_domain_id,
)
else:
auth = keystone_v3_auth.Password(
auth_url=self.auth_url,
username=username,
password=password,
user_domain_id=self.user_domain_id,
)
sess = session.Session(auth=auth)
def get_ks_session(**kwargs):
# Establishes a keystone session
if 'token' in kwargs:
auth = v3.TokenMethod(token=kwargs.get('token'))
else:
auth = v3.Password(**kwargs)
return session.Session(auth=auth)