"Fossies" - the Fresh Open Source Software Archive

Member "openstack-heat-13.0.0/heat/engine/clients/os/keystone/fake_keystoneclient.py" (16 Oct 2019, 4243 Bytes) of package /linux/misc/openstack/openstack-heat-13.0.0.tar.gz:


As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) Python source code syntax highlighting (style: standard) with prefixed line numbers. Alternatively you can here view or download the uninterpreted source code file. For more information about "fake_keystoneclient.py" see the Fossies "Dox" file reference documentation and the latest Fossies "Diffs" side-by-side code changes report: 12.0.0_vs_13.0.0.

    1 #
    2 #    Licensed under the Apache License, Version 2.0 (the "License"); you may
    3 #    not use this file except in compliance with the License. You may obtain
    4 #    a copy of the License at
    5 #
    6 #         http://www.apache.org/licenses/LICENSE-2.0
    7 #
    8 #    Unless required by applicable law or agreed to in writing, software
    9 #    distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
   10 #    WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
   11 #    License for the specific language governing permissions and limitations
   12 #    under the License.
   13 
   14 """A fake FakeKeystoneClient. This can be used during some runtime
   15 scenarios where you want to disable Heat's internal Keystone dependencies
   16 entirely. One example is the TripleO Undercloud installer.
   17 
   18 To use this class at runtime set to following heat.conf config setting:
   19 
   20   keystone_backend = heat.engine.clients.os.keystone.fake_keystoneclient\
   21   .FakeKeystoneClient
   22 
   23 """
   24 
   25 from keystoneauth1 import session
   26 
   27 from heat.common import context
   28 
   29 
   30 class FakeKeystoneClient(object):
   31     def __init__(self, username='test_username', password='password',
   32                  user_id='1234', access='4567', secret='8901',
   33                  credential_id='abcdxyz', auth_token='abcd1234',
   34                  context=None, stack_domain_id='4321', client=None):
   35         self.username = username
   36         self.password = password
   37         self.user_id = user_id
   38         self.access = access
   39         self.secret = secret
   40         self.session = session.Session()
   41         self.credential_id = credential_id
   42         self.token = auth_token
   43         self.context = context
   44         self.v3_endpoint = 'http://localhost:5000/v3'
   45         self.stack_domain_id = stack_domain_id
   46         self.client = client
   47 
   48         class FakeCred(object):
   49             id = self.credential_id
   50             access = self.access
   51             secret = self.secret
   52         self.creds = FakeCred()
   53 
   54     def create_stack_user(self, username, password=''):
   55         self.username = username
   56         return self.user_id
   57 
   58     def delete_stack_user(self, user_id):
   59         self.user_id = None
   60 
   61     def get_ec2_keypair(self, access, user_id):
   62         if user_id == self.user_id:
   63             if access == self.access:
   64                 return self.creds
   65             else:
   66                 raise ValueError("Unexpected access %s" % access)
   67         else:
   68             raise ValueError("Unexpected user_id %s" % user_id)
   69 
   70     def create_ec2_keypair(self, user_id):
   71         if user_id == self.user_id:
   72             return self.creds
   73 
   74     def delete_ec2_keypair(self, credential_id=None, user_id=None,
   75                            access=None):
   76         if user_id == self.user_id and access == self.creds.access:
   77             self.creds = None
   78         else:
   79             raise Exception('Incorrect user_id or access')
   80 
   81     def enable_stack_user(self, user_id):
   82         pass
   83 
   84     def disable_stack_user(self, user_id):
   85         pass
   86 
   87     def create_trust_context(self):
   88         return context.RequestContext(username=self.username,
   89                                       password=self.password,
   90                                       is_admin=False,
   91                                       trust_id='atrust',
   92                                       trustor_user_id=self.user_id)
   93 
   94     def delete_trust(self, trust_id):
   95         pass
   96 
   97     def delete_stack_domain_project(self, project_id):
   98         pass
   99 
  100     def create_stack_domain_project(self, stack_id):
  101         return 'aprojectid'
  102 
  103     def create_stack_domain_user(self, username, project_id, password=None):
  104         return self.user_id
  105 
  106     def delete_stack_domain_user(self, user_id, project_id):
  107         pass
  108 
  109     def create_stack_domain_user_keypair(self, user_id, project_id):
  110         return self.creds
  111 
  112     def enable_stack_domain_user(self, user_id, project_id):
  113         pass
  114 
  115     def disable_stack_domain_user(self, user_id, project_id):
  116         pass
  117 
  118     def delete_stack_domain_user_keypair(self, user_id, project_id,
  119                                          credential_id):
  120         pass
  121 
  122     def stack_domain_user_token(self, user_id, project_id, password):
  123         return 'adomainusertoken'
  124 
  125     def server_keystone_endpoint_url(self, fallback_endpoint):
  126         return fallback_endpoint