Beispiel #1
0
 def change_password(self, password):
     seed = hashlib.sha1(str(datetime.datetime.now()).encode('utf-8')).hexdigest()
     pw_hash = calc_hash(password, seed)
     try:
         request(self.oc_address, '/user/user/change_password/', {'login': self.login,
                                                                  'pw_hash': calc_hash(self.password, self.seed),
                                                                  'password_hash': pw_hash,
                                                                  'password_seed': seed}, self.debug)
     except:
         try:
             print("Cloud.change_password: Using uld, unsecure SHA1 for authentication. Changing to SHA512 hash")
             request(self.oc_address,
                     '/user/user/change_password/',
                     {'login': self.login,
                      'pw_hash': calc_hash(self.password, self.seed, method='sha1'),
                      'password_hash': pw_hash,
                      'password_seed': seed},
                     self.debug)
         except:
             print("Cloud.change_password: Using old, unsecure SHA1 method with old CoreCluster API (<=16.03)")
             pw_hash = calc_hash(password, seed, method='legacy')
             request(self.oc_address,
                     '/user/user/change_password/',
                     {'login': self.login,
                      'pw_hash': calc_hash(self.password, self.seed, method='legacy'),
                      'password_hash': pw_hash,
                      'password_seed': seed},
                     self.debug)
Beispiel #2
0
    def __init__(self,
                 address,
                 login,
                 password,
                 seed,
                 token_dict,
                 debug=False):
        self.login = login
        self.password = password
        self.oc_address = address
        self.seed = seed
        self.debug = debug

        self.token = None
        tokens = request(
            self.oc_address, '/user/token/get_list/', {
                'login': self.login,
                'pw_hash': calc_hash(self.password, self.seed),
                'name': 'pycloud'
            }, self.debug)
        if len(tokens) == 0:
            self.token = request(
                self.oc_address, '/user/token/create/', {
                    'login': self.login,
                    'pw_hash': calc_hash(self.password, self.seed),
                    'name': 'pycloud'
                }, self.debug)['token']
        else:
            self.token = tokens[0]['token']

        BaseModel.__init__(self, self.oc_address, self.token, token_dict)
Beispiel #3
0
 def delete(self):
     request(
         self.oc_address, '/user/token/delete/', {
             'login': self.login,
             'pw_hash': calc_hash(self.password, self.seed),
             'token_id': self.id
         }, self.debug)
Beispiel #4
0
 def detach(self, token):
     request(
         self.oc_address, '/user/permission/detach/', {
             'login': self.login,
             'pw_hash': calc_hash(self.password, self.seed),
             'function': self.function,
             'token_id': token.id
         })
Beispiel #5
0
    def token_create(self, name='', token_valid_to=datetime.datetime.now()+datetime.timedelta(weeks=1)):
        token = request(self.oc_address,
                        '/user/token/create/',
                        {'login': self.login,
                         'pw_hash': calc_hash(self.password, self.seed),
                         'name': name,
                         'token_valid_to': str(token_valid_to)}, self.debug)

        return Token(self.oc_address, self.login, self.password, self.seed, token, self.debug)
Beispiel #6
0
    def token_list(self):
        tokens = request(self.oc_address, '/user/token/get_list/',
                         {'login': self.login,
                          'pw_hash': calc_hash(self.password, self.seed)},
                         self.debug)
        token_list = []
        for token in tokens:
            token_list.append(Token(self.oc_address, self.login, self.password, self.seed, token, self.debug))

        return token_list
Beispiel #7
0
 def edit(self, **kwargs):
     for key in kwargs.keys():
         if hasattr(self, key):
             setattr(self, key, kwargs[key])
             request(
                 self.oc_address, '/user/token/edit/', {
                     'login': self.login,
                     'pw_hash': calc_hash(self.password, self.seed),
                     'vm_id': self.id,
                     key: kwargs[key]
                 }, self.debug)
Beispiel #8
0
    def get_api(self):
        """
        Generate API object and fetch token for it's instance to manage all non-user
        functions in cloud. Api class could be generated without calling this
        function, unless you have valid token.
        """
        token = None
        password_hash = None
        try:
            password_hash = calc_hash(self.password, self.seed)
            tokens = request(self.oc_address, '/user/token/get_list/', {'login': self.login,
                                                                        'pw_hash': password_hash,
                                                                        'name': 'pycloud'}, self.debug)
        except:
            try:
                password_hash = calc_hash(self.password, self.seed, method='sha1')
                print("Cloud.get_api: Using old, unsecure SHA1 method")
                tokens = request(self.oc_address, '/user/token/get_list/', {'login': self.login,
                                                                            'pw_hash': password_hash,
                                                                            'name': 'pycloud'}, self.debug)
            except:
                password_hash = calc_hash(self.password, self.seed, method='legacy')
                print("Cloud.get_api: Using old, unsecure SHA1 method with old CoreCluster API (<=16.03)")
                tokens = request(self.oc_address, '/user/token/get_list/', {'login': self.login,
                                                                            'pw_hash': password_hash,
                                                                            'name': 'pycloud'}, self.debug)
        if len(tokens) == 0:
            token = request(self.oc_address, '/user/token/create/', {'login': self.login,
                                                                     'pw_hash': password_hash,
                                                                     'name': 'pycloud'}, self.debug)['token']
        else:
            try:
                request(self.oc_address, '/api/api/list_api_modules/', {'token': tokens[0]['token']})
                token = tokens[0]['token']
            except:
                token = request(self.oc_address, '/user/token/create/', {'login': self.login,
                                                                         'pw_hash': password_hash,
                                                                         'name': 'pycloud'}, self.debug)['token']

        return Api(self.oc_address, token, self.debug)
Beispiel #9
0
    def permission_list(self):
        permissions = request(self.oc_address,
                              '/user/permission/get_list/',
                              {'login': self.login, 'pw_hash': calc_hash(self.password, self.seed)},
                              self.debug)

        permission_list = []
        for permission in permissions:
            permission_list.append(Permission(self.oc_address,
                                              self.login,
                                              self.password,
                                              self.seed,
                                              permission,
                                              self.debug))

        return permission_list
Beispiel #10
0
 def token_by_id(self, token_id):
     token = request(self.oc_address, '/user/token/get/', {'login': self.login,
                                                           'pw_hash': calc_hash(self.password, self.seed),
                                                           'token_id': token_id}, self.debug)
     return Token(self.oc_address, self.login, self.password, self.seed, token, self.debug)
Beispiel #11
0
 def account_quota(self):
     return request(self.oc_address,
                    '/user/user/get_quota/',
                    {'login': self.login, 'pw_hash': calc_hash(self.password, self.seed)},
                    self.debug)