Exemplo n.º 1
0
def delete_sshkey():
    handler = request_handler.SSHKey_Handler()
    handler.authenticate(fromRequestHeaders('Apikey', request))
    requestBody = RequestBody(request.data)
    requestBody.put("sshKey", fromRequestHeaders('SshKey', request))
    requestBody.put("applicationName", fromRequestHeaders('Applicationname', request))
    return handler.delete_sshkey(requestBody)
Exemplo n.º 2
0
def delete_sshkey():
    try:
        handler = request_handler.SSHKey_Handler()
        handler.authenticate(fromRequestHeaders('Apikey', request))
        
        requestBody = RequestBody()
        requestBody.put("sshKey", fromRequestHeaders('SshKey', request))
        
        return handler.delete_sshkey(requestBody)
    except Exception, e:
        return wrapResponseMessage(e), extractStatusCode(e)    
Exemplo n.º 3
0
def sshkey():
    handler = request_handler.SSHKey_Handler()
    handler.authenticate(fromRequestHeaders('Apikey', request))
    requestBody = {
        'GET': RequestBody(),
        'POST': RequestBody(request.data)
    }[request.method]
    requestBody.put("applicationName",
                    fromRequestHeaders('Applicationname', request))
    response = {
        'GET': handler.list_sshkey,
        'POST': handler.create_sshkey,
    }[request.method](requestBody)
    return response
Exemplo n.º 4
0
 def delete_sshkey(self, requestBody=RequestBody()):
     applicationName = requestBody.get('applicationName')
     sshKey = requestBody.get('sshKey')
     if applicationName and sshKey:
         app = self.read_app(applicationName)
         username = app['users'][0]['username']
         keys = self.read_user_keys(username)
         deleted = False
         for key_id_ob in keys:
             key_object = self.read_user_key(username, key_id_ob['key_id'])
             affectedKey = key_object['key']
             if affectedKey == sshKey:
                 deleted = self.delete_user_key(username,
                                                key_id_ob['key_id'])
                 break
         if deleted:
             sshKey = dict({
                 'sshKey': sshKey,
                 'owner': app['users'][0]['email']
             })
             return wrapResponseMessage(dict(sshKey=sshKey)), 204
         else:
             raise GoneError()
     else:
         return wrapResponseMessage("Bad Request"), 400
Exemplo n.º 5
0
    def operation(self,
                  applicationName=None,
                  operation=None,
                  requestBody=RequestBody()):
        try:
            if operation in self.valid_operations:
                message = 'success'
                if not operation is "nop":
                    state = {
                        'start': "0",
                        'stop': "1",
                    }[operation]
                    response = self._http_resource(
                        method='POST',
                        resource=('apps', applicationName,
                                  'server/maintenance'),
                        params={
                            'app': applicationName,
                            'maintenance_mode': state
                        },
                        data={
                            'app': applicationName,
                            'maintenance_mode': state
                        })
                    if not response.ok:
                        message = response.text

                return wrapResponseMessage({'message': message})
            else:
                return wrapResponseMessage({'message': 'Bad Request'}), 400
        except Exception, e:
            return wrapResponseMessage(e)
Exemplo n.º 6
0
    def delete_database(self,
                        applicationName=None,
                        deploymentName=None,
                        databaseName=None,
                        requestBody=RequestBody()):
        redistogo = 'redistogo:nano'

        try:
            response = self._http_resource(method='DELETE',
                                           resource=('apps', applicationName,
                                                     'addons', redistogo))

            if response.ok:
                return wrapResponseMessage({
                    'database': {
                        'databaseName': redistogo,
                        'userName': '',
                        'password': '',
                        'host': '',
                        'port': '',
                    },
                    'message': 'success'
                })
            else:
                return wrapResponseMessage({'message': response.reason}), 500

        except requests.exceptions.HTTPError, he:
            e = Exception(he.response.text)
            if hasattr(he.response, 'status_code'):
                e.status = he.response.status_code
            raise e
    def set_container_ru(self, dbname, cname, ru):
        print('set_container_ru: {} {} {}'.format(dbname, cname, ru))
        associations = self.associate_offers(dbname)

        for a in associations:
            if (a['type'] == 'coll') and (a['name'] == cname):
                offer = a['offer']
                print(json.dumps(offer, sort_keys=False, indent=2))
                offer['content'][
                    'offerThroughput'] = ru  # update the offer JSON with new RU
                print(json.dumps(offer, sort_keys=False, indent=2))
                # See https://docs.microsoft.com/en-us/rest/api/cosmos-db/replace-an-offer
                offer_id = a['offer']['id']
                resource = a['offer']['resource']
                offerResourceId = a['offer']['offerResourceId']
                id = a['offer']['id']
                rid = a['offer']['_rid']
                body = RequestBody.replace_container_offer(
                    ru, resource, offerResourceId, id, rid)
                print(body)
                verb, resource_link = 'put', '{}'.format(offer_id)
                headers = self.__rest_headers(verb, 'offers', resource_link)
                url = 'https://{}.documents.azure.com/offers/{}'.format(
                    self.cosmos_acct, offer_id)
                return self.__execute_http_request('replace_offer', verb, url,
                                                   headers, body)
Exemplo n.º 8
0
    def list_application(self, requestBody=RequestBody()):
        try:
            herokuApps = self.apps

            applicationList = []
            for application in herokuApps:
                applicationModel = dict({
                    'applicationName':
                    application.name,
                    'created':
                    application.created_at.isoformat(),
                    'modified':
                    None,
                    'repository':
                    None,
                    'language':
                    None
                })
                applicationList.append(applicationModel)
            return wrapResponseMessage(dict(applications=applicationList))
        except requests.exceptions.HTTPError, he:
            e = Exception(he.response.text)
            if hasattr(he.response, 'status_code'):
                e.status = he.response.status_code
            raise e
Exemplo n.º 9
0
    def application(self, applicationName=None, requestBody=RequestBody()):
        try:
            response = self._http_resource(method='GET',
                                           resource=('apps', applicationName))

            if response.ok:
                response = response.json

                application = dict({
                    'applicationName':
                    response['name'] if 'name' in response else None,
                    'created':
                    response['created_at']
                    if 'created_at' in response else None,
                    'repository':
                    response['git_url'] if 'git_url' in response else None,
                    'modified':
                    response['updated_at']
                    if 'updated_at' in response else None,
                    'language':
                    response['buildpack_provided_description']
                    if 'buildpack_provided_description' in response else None
                })

                return wrapResponseMessage({'application': application})
            else:
                return wrapResponseMessage({'message': response.reason}), 500
        except requests.exceptions.HTTPError, he:
            e = Exception(he.response.text)
            if hasattr(he.response, 'status_code'):
                e.status = he.response.status_code
            raise e
Exemplo n.º 10
0
 def delete_deployment(self,
                       applicationName=None,
                       deploymentName=None,
                       requestBody=RequestBody()):
     try:
         return wrapResponseMessage({'message': '501 Not implemented'}), 501
     except Exception, e:
         return wrapResponseMessage(e)
Exemplo n.º 11
0
 def ems(self, requestBody=RequestBody()):
     return wrapResponseMessage({
         'module': {
             'description': 'cloud4soa execution & management',
             'version': '1.0',
             'moduleName': 'ems'
         }
     })
Exemplo n.º 12
0
 def monitor(self, requestBody=RequestBody()):
     return wrapResponseMessage({
         'module': {
             'description': 'cloud4soa monitoring',
             'version': '1.0',
             'moduleName': 'monitor'
         }
     })
Exemplo n.º 13
0
def sshkey():
    try:
        handler = request_handler.SSHKey_Handler()
        handler.authenticate(fromRequestHeaders('Apikey',request))
        
        requestBody = {
            'GET' : RequestBody(), 
            'POST' : RequestBody(request.data)
        }[request.method]
        
        response = {
            'GET': handler.list_sshkey,
            'POST': handler.create_sshkey,
        }[request.method](requestBody)
        return response.status_code if type(response) is requests.models.Response else response
    except Exception, e:
        return wrapResponseMessage(e), extractStatusCode(e)
Exemplo n.º 14
0
 def c4s(self, requestBody=RequestBody()):
     return wrapResponseMessage({
         'module': {
             'description': 'cloud4soa',
             'version': '1.0',
             'moduleName': ''
         }
     })
Exemplo n.º 15
0
 def create_sshkey(self, requestBody=RequestBody()):
     sshKey = requestBody.get('sshKey')
     if sshKey:
         user = self.read_users()[0]
         self.create_user_key(user['username'], sshKey)
         sshKey = dict({'sshKey': sshKey, 'owner': user['email']})
         return wrapResponseMessage(dict(sshKey=sshKey)), 201
     else:
         return wrapResponseMessage("Bad Request"), 400
Exemplo n.º 16
0
def list_application():
    try:
        handler = request_handler.Application_Handler()
        handler.authenticate(request.headers['Apikey'])
        
        response = handler.list_application(RequestBody(request.data))
        return response.status_code if type(response) is requests.models.Response else response
    except Exception, e:
        return wrapResponseMessage(e), extractStatusCode(e)
Exemplo n.º 17
0
def application(application):
    handler = request_handler.Application_Handler()
    handler.authenticate(request.headers['Apikey'])
    response = {
        'POST': handler.create_application,
        'PUT': handler.update_application,
        'GET': handler.application,
        'DELETE': handler.delete_application
    }[request.method](application, RequestBody(request.data))
    return response
Exemplo n.º 18
0
 def application(self, applicationName=None, requestBody=RequestBody()):
     application = self.read_app(applicationName)
     app = dict({
         'applicationName': application['name'],
         'created': application['date_created'],
         'modified': application['date_modified'],
         'repository': application['repository'],
         'language': application['type']['name']
     })
     return wrapResponseMessage({'application': app}), 200
Exemplo n.º 19
0
    def create_sshkey(self, requestBody=RequestBody()):
        sshKey = requestBody.get('sshKey')

        if not sshKey is None:
            newKey = heroku.models.Key()
            newKey._h = self
            newKey = newKey.new(sshKey)

            sshKey = dict({'sshKey': newKey.contents, 'owner': newKey.email})
            return wrapResponseMessage(dict(sshKey=sshKey))
        else:
            return wrapResponseMessage(Exception('Bad Request')), 400
Exemplo n.º 20
0
def c4s():
    try:
        handler = request_handler.Common_Handler()
        
        '''
            If we need authentication here, we should enable this, otherwise not
        '''
        #handler.authenticate(request.headers["Apikey"])
        
        response = handler.c4s(RequestBody(request.data))
        return response.status_code if type(response) is requests.models.Response else response
    except Exception, e:
        return wrapResponseMessage(e), extractStatusCode(e)
Exemplo n.º 21
0
 def list_deployment(self, applicationName=None, requestBody=RequestBody()):
     app = self.read_app(applicationName)
     deploymentList = []
     for dep in app['deployments']:
         deployment = self.read_deployment(applicationName, dep)
         deployment = dict({
             'applicationName': applicationName,
             'deploymentName': deployment['name'],
             'subdomain': deployment['default_subdomain'],
             'state': deployment['state']
         })
         deploymentList.append(deployment)
     return wrapResponseMessage(dict(deployments=deploymentList)), 200
Exemplo n.º 22
0
    def list_database(self,
                      applicationName=None,
                      deploymentName=None,
                      requestBody=RequestBody()):
        try:
            #redistogo:nano
            response = self._get_resource(resource=('apps', applicationName),
                                          obj=heroku.models.App)
            redis = response.addons.get('redistogo:nano')

            return wrapResponseMessage({'message': '501 Not implemented'}), 501
        except Exception, e:
            return wrapResponseMessage(e)
Exemplo n.º 23
0
 def deployment(self,
                applicationName=None,
                deploymentName=None,
                requestBody=RequestBody()):
     deployment = self.read_deployment(applicationName, deploymentName)
     return wrapResponseMessage({
         'deployment': {
             'applicationName': applicationName,
             'deploymentName': deploymentName,
             'subdomain': deployment['default_subdomain'],
             'state': deployment['state']
         }
     }), 200
Exemplo n.º 24
0
def delete_sshkey():
    handler = request_handler.SSHKey_Handler()
    handler.authenticate(fromRequestHeaders('Apikey', request))
    requestBody = RequestBody(request.data)
    requestBody.put("sshKey", fromRequestHeaders('SshKey', request))
    requestBody.put("applicationName",
                    fromRequestHeaders('Applicationname', request))
    return handler.delete_sshkey(requestBody)
Exemplo n.º 25
0
 def list_sshkey(self, requestBody=RequestBody()):
     response = self._http_resource(method='GET', resource=('user', 'keys'))
     if response.ok:
         sshKeys = response.json
         sshKeysList = []
         for sshKey in sshKeys:
             sshKey = dict({
                 'sshKey': sshKey['contents'],
                 'owner': sshKey['email']
             })
             sshKeysList.append(sshKey)
         return wrapResponseMessage(dict(sshKeys=sshKeysList))
     else:
         return wrapResponseMessage({'message': response.reason}), 500
Exemplo n.º 26
0
    def delete_application(self,
                           applicationName=None,
                           requestBody=RequestBody()):
        try:
            herokuApps = self.apps
            for application in herokuApps:
                if application.name == applicationName:
                    try:
                        response = application.destroy()
                        return wrapResponseMessage({'message': response})
                    except Exception, e:
                        return wrapResponseMessage(e)

            return wrapResponseMessage({'message': 'Not found.'}), 404
Exemplo n.º 27
0
    def database(self,
                 applicationName=None,
                 deploymentName=None,
                 databaseName=None,
                 requestBody=RequestBody()):
        redistogo = 'redistogo:nano'
        try:
            response = self._http_resource(method='GET',
                                           resource=('apps', applicationName,
                                                     'addons', redistogo))

            return wrapResponseMessage({'message': '501 Not implemented'}), 501
        except Exception, e:
            return wrapResponseMessage(e)
 def create_database(self, dbname, autopilot_ru):
     # See https://docs.microsoft.com/en-us/rest/api/cosmos-db/create-a-database
     print('create_database: {} {}'.format(dbname, autopilot_ru))
     verb, resource_link = 'post', ''
     headers = self.__rest_headers(verb, 'dbs', resource_link)
     if autopilot_ru > 0:
         settings = {"maxThroughput": autopilot_ru}
         headers['x-ms-cosmos-offer-autopilot-settings'] = json.dumps(
             settings)
     body = RequestBody.create_db(dbname)
     print(headers)
     print(body)
     url = 'https://{}.documents.azure.com/dbs'.format(self.cosmos_acct)
     return self.__execute_http_request('create_database', verb, url,
                                        headers, body)
Exemplo n.º 29
0
 def delete_dep(self,
                applicationName=None,
                deploymentName=None,
                requestBody=RequestBody()):
     deployment = self.read_deployment(applicationName, deploymentName)
     deleted = self.delete_deployment(applicationName, deploymentName)
     return wrapResponseMessage({
         'deployment': {
             'applicationName': applicationName,
             'deploymentName': deploymentName,
             'subdomain': deployment['default_subdomain'],
             'state': 'not deploymend' if deleted else 'deployed'
         },
         'message': 'success'
     }), 204
Exemplo n.º 30
0
 def create_application(self,
                        applicationName=None,
                        requestBody=RequestBody()):
     app = self.create_app(applicationName, requestBody.get('language'),
                           'git')
     return wrapResponseMessage(
         dict(
             application={
                 'applicationName': app['name'],
                 'created': app['date_created'],
                 'url': '{}.cloudcontrolled.com'.format(app['name']),
                 'modified': app['date_modified'],
                 'repository': app['repository'],
                 'language': app['type']['name']
             })), 201
    def create_container(self, dbname, cname, ru, pk):
        # See https://docs.microsoft.com/en-us/rest/api/cosmos-db/create-a-collection
        print('create_container: {} {} {} {}'.format(dbname, cname, ru, pk))
        verb, resource_link = 'post', 'dbs/{}'.format(dbname)
        headers = self.__rest_headers(verb, 'colls', resource_link)
        body = RequestBody.create_container(cname, pk)
        if ru > 0:
            headers['x-ms-offer-throughput'] = str(ru)
        url = 'https://{}.documents.azure.com/dbs/{}/colls'.format(
            self.cosmos_acct, dbname)

        print(json.dumps(headers, sort_keys=False, indent=2))
        print(json.dumps(body, sort_keys=False, indent=2))
        print(url)
        return self.__execute_http_request('create_container', verb, url,
                                           headers, body)