Example #1
0
 def test_env_vars(self):
   c = credentials('<unittest>')
   c.username = '******'
   c.password = '******'
   with env_override( { 'MY_USERNAME': '******', 'MY_PASSWORD': '******' }) as env:
     self.assertEqual( 'fred', c.username )
     self.assertEqual( 'flintpass', c.password )
Example #2
0
 def vmrest_credentials(self):
   if self.vmrest_username and not self.vmrest_password:
     raise vmware_error('both vmrest_username and vmrest_password need to be given.')
   if self.vmrest_password and not self.vmrest_username:
     raise vmware_error('both vmrest_password and vmrest_username need to be given.')
   if not self.vmrest_username:
     assert not self.vmrest_password
     return None
   return credentials('<cli>', username = self.vmrest_username, password = self.vmrest_password)
Example #3
0
 def credentials(self):
     if self.username and not self.password:
         raise _test_cli_options_error(
             'both username and password need to be given.')
     if self.password and not self.username:
         raise _test_cli_options_error(
             'both password and username need to be given.')
     if not self.username:
         assert not self.password
         return None
     return credentials('<cli>',
                        username=self.username,
                        password=self.password)
Example #4
0
 def credentials(self, name):
     values = self.values
     if not values:
         return None
     username_key = '{}User'.format(name)
     username = values.get(username_key, None)
     if not username:
         return None
     password_key = '{}Password'.format(name)
     password = values.get(password_key, None)
     if not password:
         return None
     c = credentials(self._filename, username=username, password=password)
     return c
Example #5
0
 def resolve_login_credentials(self, vm_name):
     login_username = self.resolve_login_username(vm_name)
     login_password = self.resolve_login_password(vm_name)
     if login_username and not login_password:
         raise vmware_error(
             'both login_username and login_password need to be given.')
     if login_password and not login_username:
         raise vmware_error(
             'both login_password and login_username need to be given.')
     if not login_username:
         assert not login_password
         return None
     return credentials('<cli>',
                        username=login_username,
                        password=login_password)
Example #6
0
    def ssh_credentials(self):
        self._check_ssh_credentials()

        if not self.ssh_public_key:
            assert not self.ssh_private_key
            return None
        try:
            ssh_public_key_content = file_util.read(self.ssh_public_key,
                                                    codec='utf-8')
        except Exception as ex:
            raise git_error('Failed to ready public ssh key: "{}" - {}'.format(
                self.ssh_public_key, str(ex)))
        try:
            ssh_private_key_content = file_util.read(self.ssh_private_key,
                                                     codec='utf-8')
        except Exception as ex:
            raise git_error(
                'Failed to ready private ssh key: "{}" - {}'.format(
                    self.ssh_private_key, str(ex)))
        return credentials('<cli>',
                           public_key=ssh_public_key_content,
                           private_key=ssh_private_key_content,
                           username=self.username,
                           host_key_type=self.host_key_type)
Example #7
0
 def test_eq(self):
   self.assertEqual( credentials('<unittest>'), credentials('<unittest>') )
   self.assertEqual( credentials('<unittest>', username = '******'), credentials('<unittest>', username = '******') )
   self.assertEqual( credentials('<unittest>', username = '******'), credentials('<unittest>', username = '******') )
Example #8
0
 def test_basic(self):
   c = credentials('<unittest>')
   c.username = '******'
   c.password = '******'
   self.assertEqual( 'fred', c.username )
   self.assertEqual( 'flintpass', c.password )
Example #9
0
 def auth(self):
   username = self.username or os_env_var('BES_VMWARE_USERNAME').value_if_set
   password = self.password or os_env_var('BES_VMWARE_PASSWORD').value_if_set
   return credentials('<cli>', username = username, password = password)
Example #10
0
 def credentials(self):
     return credentials('<cli>', password=self.vmrest_password)
Example #11
0
 def make_random_credentials(clazz):
   return credentials('<random>',
                      username = clazz._make_random_username(),
                      password = clazz._make_random_password())