Beispiel #1
0
 def _getSubDomain(self, args):
     logger.info('fetching subdomain')
     if not self.attrsNotNone(args, 'host', 'domain'):
         raise Exception('Invalid request')
     req = RpcRequest('Alidns', '2015-01-09', 'DescribeSubDomainRecords')
     req.add_query_param('SubDomain', '.'.join([args.host, args.domain]))
     # req.add_query_param('Type', getattr(args, 'type') or 'A')
     res = self.do(req)
     return res
Beispiel #2
0
    def _deleteRecord(self, args):
        logger.info('deleting record')
        if not self.attrsNotNone(args, 'id'):
            raise Exception('Invalid request')
        req = RpcRequest('Alidns', '2015-01-09', 'DeleteDomainRecord')
        req.add_query_param('RecordId', args.id)

        res = self.do(req)
        return res
Beispiel #3
0
    def _listSubDomain(self, args):
        logger.info('listing domain records')
        if not self.attrsNotNone(args, 'domain'):
            raise Exception('Invalid request')
        req = RpcRequest('Alidns', '2015-01-09', 'DescribeDomainRecords')
        req.add_query_param('DomainName', args.domain)
        # req.add_query_param('Type', getattr(args, 'type') or 'A')

        res = self.do(req)
        return res
Beispiel #4
0
def getDNSrecords():
    global product, version, accesskey, accesspasswd
    clt = client.AcsClient(accesskey, accesspasswd, 'cn-hangzhou')
    # request=RpcRequest('Alidns', '2015-01-09', 'DescribeDomainRecords')
    # request.add_query_param("DomainName","wiki.leo.com")
    request = RpcRequest('Alidns', '2015-01-09', 'DescribeSubDomainRecords')
    request.add_query_param("SubDomain", "intranet.xxx.com")
    request.set_accept_format('json')
    response = clt.do_action(request)
    return eval(response.replace('false', '0'))
Beispiel #5
0
    def _deleteSubDomain(self, args):
        logger.info('deleting subdomain')
        if not self.attrsNotNone(args, 'host', 'domain'):
            raise Exception('Invalid request')
        req = RpcRequest('Alidns', '2015-01-09', 'DeleteSubDomainRecords')
        req.add_query_param('DomainName', args.domain)
        req.add_query_param('RR', args.host)
        # req.add_query_param('Type', getattr(args, 'type') or 'A')

        res = self.do(req)
        return res
Beispiel #6
0
def get_dns_records(domain):
    """
    DescribeDomainRecords
    """
    access_key_id, access_key_secret = get_access()
    clt = client.AcsClient(access_key_id, access_key_secret, "cn-hangzhou")
    request = RpcRequest("Alidns", "2015-01-09", "DescribeDomainRecords")
    request.add_query_param("DomainName", domain)
    request.set_accept_format("json")
    response = clt.do_action_with_exception(request)
    response_json = json.loads(response.decode())
    return response_json
Beispiel #7
0
def get_record():
    req = RpcRequest(PROD, VERSION, 'DescribeDomainRecords', 'JSON')
    req.add_query_param('DomainName', DOMAIN_NAME)
    resp = json.loads(client.do_action(req))

    record_id = None
    record_value = None
    for record in resp['DomainRecords']['Record']:
        if record['RR'] == DOMAIN_RECORD:
            record_id = record['RecordId']
            if record['Type'] != RECORD_TYPE:
                raise Exception('The record is already exsits and the type not same.')
            record_value = record['Value']
    return record_id, record_value
Beispiel #8
0
 def Domain_Record(self, RR, Type, Value):
     request = RpcRequest('Alidns', '2015-01-09', 'UpdateDomainRecord')
     request.add_query_param("RecordId", '3645564013972480')
     request.add_query_param("RR", RR)
     request.add_query_param("Type", Type)
     request.add_query_param("Value", Value)
     request.set_accept_format('json')
     response = self._send_request(request)
     return response
Beispiel #9
0
def add_record(domain_record, record_value):
    req = RpcRequest(PROD, VERSION, 'AddDomainRecord', 'JSON')
    req.add_query_param('DomainName', DOMAIN_NAME)
    req.add_query_param('RR', domain_record)
    req.add_query_param('Type', RECORD_TYPE)
    req.add_query_param('Value', record_value)
    req.add_query_param('TTL', TTL)

    resp = json.loads(client.do_action(req))
    return resp['RecordId']
Beispiel #10
0
def update_record(record_id, record_value):
    req = RpcRequest(PROD, VERSION, 'UpdateDomainRecord', 'JSON')
    req.add_query_param('RecordId', record_id)
    req.add_query_param('RR', DOMAIN_RECORD)
    req.add_query_param('Type', RECORD_TYPE)
    req.add_query_param('Value', record_value)
    req.add_query_param('TTL', TTL)

    resp = json.loads(client.do_action(req))
    return resp['RecordId']
Beispiel #11
0
def update_record(record_id, domain_record, record_value):
    req = RpcRequest(PROD, VERSION, 'UpdateDomainRecord', 'JSON')
    req.add_query_param('RecordId', record_id)
    req.add_query_param('RR', domain_record)
    req.add_query_param('Type', RECORD_TYPE)
    req.add_query_param('Value', record_value)
    req.add_query_param('TTL', TTL)

    resp = json.loads(client.do_action(req))
    return resp['RecordId']
Beispiel #12
0
def setDNSrecord(record, ip):
    global product, version, accesskey, accesspassw
    clt = client.AcsClient(accesskey, accesspasswd, 'cn-hangzhou')
    request = RpcRequest('Alidns', '2015-01-09', 'UpdateDomainRecord')
    request.add_query_param("RecordId", record['RecordId'])
    request.add_query_param("RR", record['RR'])
    request.add_query_param("Type", record['Type'])
    request.add_query_param("Value", ip)
    request.set_accept_format('json')
    response = clt.do_action(request)
    print response
Beispiel #13
0
    def _addRecord(self, args):
        logger.info('adding record')
        if not self.attrsNotNone(args, 'host', 'domain', 'value'):
            raise Exception('Invalid request')
        req = RpcRequest('Alidns', '2015-01-09', 'AddDomainRecord')
        req.add_query_param('DomainName', args.domain)
        req.add_query_param('RR', args.host)
        req.add_query_param('Value', args.value)
        req.add_query_param('Type', getattr(args, 'type') or 'A')

        res = self.do(req)
        return res
Beispiel #14
0
def set_dns_records(record, ip, oldip):
    """
    UpdateDomainRecord
    """
    access_key_id, access_key_secret = get_access()
    clt = client.AcsClient(access_key_id, access_key_secret, "cn-hangzhou")
    request = RpcRequest("Alidns", "2015-01-09", "UpdateDomainRecord")
    request.add_query_param("RecordId", record["RecordId"])
    request.add_query_param("RR", record["RR"])
    request.add_query_param("Type", record["Type"])
    request.add_query_param("Value", ip)
    response = clt.do_action_with_exception(request)
    logger.info("{} old:{} new:{}".format(response.decode(), oldip, ip))
 def __get_secret_value(self, secret_name):
     get_secret_request = RpcRequest('Kms', '2016-01-20', 'GetSecretValue',
                                     'kms')
     get_secret_request._protocol_type = "https"
     get_secret_request.add_query_param('SecretName', secret_name)
     get_secret_request.add_query_param('VersionStage', self.stage)
     get_secret_request.add_query_param('FetchExtendedConfig', True)
     get_secret_request.set_accept_format("JSON")
     try:
         get_secret_resp = self.secret_client.get_secret_value(
             get_secret_request)
         resp_json = json.loads(get_secret_resp.decode(encoding="utf-8"))
     except ClientException as e:
         get_logger().error("action:get_secret_value", exc_info=True)
         if judge_need_recovery_exception(e):
             try:
                 secret_info = self.cache_hook.recovery_get_secret(
                     secret_name)
                 if secret_info is not None:
                     return secret_info
                 else:
                     raise e
             except ClientException:
                 get_logger().error("action:recovery_get_secret",
                                    exc_info=True)
                 raise e
         else:
             raise e
     return convert_json_to_secret_info(resp_json)
 def get_secret_value(self, get_secret_value_req):
     futures = []
     finished = []
     if self.signer is not None and isinstance(self.signer,
                                               ClientKeySigner):
         get_secret_value_req._signer = sha_hmac256
     for i in range(len(self.region_info_list)):
         if i == 0:
             try:
                 return self.__get_secret_value(
                     self.region_info_list[i], get_secret_value_req)
             except ClientException as e:
                 get_logger().error("action:__get_secret_value",
                                    exc_info=True)
                 if not judge_need_recovery_exception(e):
                     raise e
         get_secret_request = RpcRequest(
             get_secret_value_req._product,
             get_secret_value_req._version,
             get_secret_value_req._action_name,
             get_secret_value_req._location_service_code,
             signer=get_secret_value_req._signer)
         get_secret_request._protocol_type = get_secret_value_req._protocol_type
         get_secret_request.add_query_param(
             'SecretName',
             get_secret_value_req.get_query_params().get('SecretName'))
         get_secret_request.add_query_param(
             'VersionStage',
             get_secret_value_req.get_query_params().get(
                 'VersionStage'))
         get_secret_request.add_query_param(
             'FetchExtendedConfig',
             get_secret_value_req.get_query_params().get(
                 'FetchExtendedConfig'))
         future = self.pool.submit(self.__retry_get_secret_value,
                                   get_secret_request,
                                   self.region_info_list[i], finished)
         futures.append(future)
     try:
         if wait(futures,
                 self.request_waiting_time,
                 return_when=FIRST_COMPLETED):
             for future in futures:
                 if not future.done():
                     future.cancel()
                 else:
                     return future.result()
     except Exception as e:
         get_logger().error("action:__retry_get_secret_value_task",
                            exc_info=True)
         raise e
     finally:
         finished.append(True)
     raise ClientException(error_code.SDK_HTTP_ERROR,
                           "refreshSecretTask fail")
Beispiel #17
0
 def get_reslut(self, type, domain=None, PageNumber=1):
     try:
         clt = client.AcsClient(self.AccessKeyId, self.AccessKeySecret,
                                'cn-shanghai')
         if type == "domain":
             request = RpcRequest('Alidns', '2015-01-09', 'DescribeDomains')
             request.add_query_param("PageSize", 100)
         else:
             request = RpcRequest('Alidns', '2015-01-09',
                                  'DescribeDomainRecords')
             request.add_query_param("DomainName", domain)
             request.add_query_param("PageSize", 500)
             request.add_query_param("PageNumber", PageNumber)
         request.set_accept_format('json')
         json_response = json.loads(clt.do_action_with_exception(request))
     except:
         json_response = None
     return json_response
    def do_action_with_exception(self, request: RpcRequest):
        request.set_accept_format('JSON')
        path = request.path_pattern if hasattr(
            request, 'path_pattern') else '/api/acs/openapi'

        if self._endpoint:
            endpoint = self._endpoint
        elif request.endpoint:
            endpoint = request.endpoint
        else:
            endpoint = self._resolve_endpoint(request)

        request.add_query_param('Product', request.get_product())
        request.add_query_param('RegionId', self.get_region_id())
        request.add_query_param('Action', request.get_action_name())
        request.add_query_param('Version', request.get_version())

        request._params.update(self.query_params)
        sign_params = dict(request._params)
        query, sign_str = get_signed_url(sign_params, self.get_access_key(),
                                         self.get_access_secret(),
                                         request.get_accept_format(),
                                         request.get_method(),
                                         request.get_body_params(),
                                         self.query_params)
        request.string_to_sign = sign_str

        endpoint += path
        response = HttpResponse(
            endpoint, query, request.get_method(),
            request.get_signed_header(self.get_region_id(),
                                      self.get_access_key(),
                                      self.get_access_secret()),
            request.get_protocol_type(), request.get_content(), self._port)

        if self._read_timeout:
            response._timeout = response.__read_timeout = self._read_timeout
        if self._connect_timeout:
            response.__connect_timeout = self._connect_timeout

        try:
            status, headers, body = response.get_response_object()
        except IOError as e:
            exception = ClientException(error_code.SDK_HTTP_ERROR,
                                        compat.ensure_string('%s' % e))
            return None, None, None, exception

        exception = self.get_server_exception(status, body)
        if exception:
            raise exception

        return body
Beispiel #19
0
def send_sms(name):
    REGION = "cn-hangzhou"
    PRODUCT_NAME = "Dysmsapi"
    DOMAIN = "dysmsapi.aliyuncs.com"

    # need modify
    ACCESS_KEY_ID='YourKey'
    ACCESS_KEY_SECRET='YourSecret'

    TemplateParam = {"name": name}
    rpc_request = RpcRequest('Dysmsapi', '2017-05-25', 'SendSms')
    rpc_request.add_query_param('TemplateCode', 'SMS_77130046')
    rpc_request.add_query_param('TemplateParam', json.dumps(TemplateParam))
    rpc_request.add_query_param('OutId', uuid.uuid1())
    rpc_request.add_query_param('SignName', 'MKeng提醒')
    rpc_request.add_query_param('PhoneNumbers', '18829028766')

    region_provider.add_endpoint(PRODUCT_NAME, REGION, DOMAIN)
    acs_client = AcsClient(ACCESS_KEY_ID, ACCESS_KEY_SECRET, REGION)
    response = acs_client.do_action_with_exception(rpc_request)
    return response
Beispiel #20
0
 def test_rpc_request(self):
     r = RpcRequest("product", "version", "action_name")
     # accept format
     self.assertIsNone(r.get_accept_format())
     r.set_accept_format('json')
     self.assertEqual(r.get_accept_format(), "json")
     # action name
     self.assertEqual(r.get_action_name(), "action_name")
     r.set_action_name('new action name')
     self.assertEqual(r.get_action_name(), "new action name")
     # body params
     self.assertDictEqual(r.get_body_params(), {})
     r.set_body_params({'key': 'value'})
     self.assertDictEqual(r.get_body_params(), {'key': 'value'})
     r.add_body_params("key2", "value2")
     self.assertDictEqual(r.get_body_params(), {
         'key': 'value',
         'key2': 'value2'
     })
     # content
     self.assertIsNone(r.get_content())
     r.set_content("content")
     self.assertEqual(r.get_content(), "content")
     # headers
     self.assertDictEqual(r.get_headers(), {'x-sdk-invoke-type': 'normal'})
     r.set_headers({})
     self.assertDictEqual(r.get_headers(), {})
     r.add_header("key", "value")
     self.assertDictEqual(r.get_headers(), {"key": "value"})
     # location endpoint type
     self.assertEqual(r.get_location_endpoint_type(), 'openAPI')
     # no set_location_endpoint_type ??
     # location_service_code
     self.assertEqual(r.get_location_service_code(), None)
     r.set_location_service_code('new service code')
     self.assertEqual(r.get_location_service_code(), 'new service code')
     # method
     self.assertEqual(r.get_method(), 'GET')
     r.set_method('POST')
     self.assertEqual(r.get_method(), 'POST')
     # product
     self.assertEqual(r.get_product(), 'product')
     r.set_product('new-product')
     self.assertEqual(r.get_product(), 'new-product')
     # protocol_type
     self.assertEqual(r.get_protocol_type(), "http")
     r.set_protocol_type('https')
     self.assertEqual(r.get_protocol_type(), "https")
     # query params
     self.assertDictEqual(r.get_query_params(), {})
     r.set_query_params({'key': 'value'})
     self.assertDictEqual(r.get_query_params(), {'key': 'value'})
     r.add_query_param("key2", "value2")
     self.assertDictEqual(r.get_query_params(), {
         'key': 'value',
         "key2": "value2"
     })
     # signed_header
     self.assertEqual(r.get_signed_header(), {})
     r.add_header("x-acs-xxx", "value")
     self.assertDictEqual(r.get_signed_header(), {"x-acs-xxx": "value"})
     # style
     self.assertEqual(r.get_style(), "RPC")
     # uri params
     self.assertEqual(r.get_uri_params(), None)
     r.set_uri_params({'user': "******"})
     self.assertDictEqual(r.get_uri_params(), {'user': '******'})
     # uri pattern
     self.assertEqual(r.get_uri_pattern(), None)
     r.set_uri_pattern('/users/:userid')
     self.assertEqual(r.get_uri_pattern(), '/users/:userid')
     # version
     self.assertEqual(r.get_version(), "version")
     r.set_version('2014-10-18')
     self.assertEqual(r.get_version(), "2014-10-18")
     # user-agent
     self.assertEqual(r.get_headers().get('User-Agent'), None)
     r.set_user_agent("user-agent")
     self.assertEqual(r.get_headers().get('User-Agent'), "user-agent")
     # content-type
     self.assertEqual(r.get_headers().get('Content-Type'), None)
     r.set_content_type("application/json")
     self.assertEqual(r.get_headers().get('Content-Type'),
                      "application/json")
     # endpoint
     self.assertEqual(r.endpoint, None)
     r.set_endpoint('endpoint')
     self.assertEqual(r.endpoint, "endpoint")
Beispiel #21
0
 def Get_RecordId(self, DomainName):
     request = RpcRequest('Alidns', '2015-01-09', 'DescribeDomainRecords')
     request.add_query_param("DomainName", DomainName)
     response = self._send_request(request)
     return response
Beispiel #22
0
def get_all_record():
    req = RpcRequest(PROD, VERSION, 'DescribeDomainRecords', 'JSON')
    req.add_query_param('DomainName', DOMAIN_NAME)
    resp = json.loads(client.do_action(req))
    return resp