def cce_client(self):
        self.log('Geting CCE client')
        if not self._cce_client:
            config = HttpConfig.get_default_config()
            config.ignore_ssl_verification = True
            if self.module.params["project_id"]:
                credentials = BasicCredentials(
                    self.module.params["access_key"],
                    self.module.params["secret_key"],
                    self.module.params["project_id"])

                if self.module.params["identity_endpoint"]:
                    credentials.iam_endpoint = self.module.params[
                        "identity_endpoint"]

                endpoint = 'https://cce.{}.{}'.format(
                    self.module.params["region"], self.module.params["cloud"])
                self._cce_client = CceClient.new_builder() \
                .with_http_config(config) \
                .with_credentials(credentials) \
                .with_endpoint(endpoint) \
                .build()
            else:
                raise HwcModuleException(
                    'Getting CCE client failed: "project_id" is required for CCE client'
                )

        return self._cce_client
示例#2
0
    def ecs_client(self, region):
        self.log('Geting ECS client')
        config = HttpConfig.get_default_config()
        config.ignore_ssl_verification = True
        if self.credentials["project_id"] and self.credentials[
                "access_key"] and self.credentials["secret_key"] and region:
            _credentials = BasicCredentials(self.credentials["access_key"],
                                            self.credentials["secret_key"],
                                            self.credentials["project_id"])

            if self.credentials["identity_endpoint"]:
                _credentials.iam_endpoint = self.credentials[
                    "identity_endpoint"]

            if self.credentials["cloud"]:
                endpoint = 'https://ecs.{}.{}'.format(
                    region, self.credentials["cloud"])
            else:
                endpoint = 'https://ecs.{}.myhuaweicloud.com'.format(region)
            ecs_client = EcsClient.new_builder() \
            .with_http_config(config) \
            .with_credentials(_credentials) \
            .with_endpoint(endpoint) \
            .build()
        else:
            raise HwcModuleException(
                'Getting ECS client failed: "project_id", "access_key", "access_key" and "region" are required for ECS client'
            )

        return ecs_client
示例#3
0
def test_project_id_with_region(mocker):
    mock_credential = BasicCredentials("ak",
                                       "sk").with_iam_endpoint(MOCK_ENDPOINT)
    client = Client().with_credentials(mock_credential).with_config(
        HttpConfig.get_default_config())
    client.init_http_client()
    http_client = client.get_http_client()

    mocker.patch.object(http_client,
                        'do_request_sync',
                        return_value=mock_keystone_list_projects(REGION_ID))

    result_credential = mock_credential.process_auth_params(
        http_client, ServiceRegion.CN_NORTH_7.id)
    assert result_credential.project_id == "123456789"
示例#4
0
def credentials():
    ak = "my ak"
    sk = "my sk"
    project_id = "my project_id"

    credentials = BasicCredentials(ak, sk, project_id)
    yield credentials
示例#5
0
def get_iot_client():
    config = HttpConfig.get_default_config()
    credentials = BasicCredentials(HwyunSettings.access_key_id,
                                   HwyunSettings.access_key_secret,
                                   HwyunSettings.project_id,
                                   HwyunSettings.domain_id)
    builder: ClientBuilder = IoTDAClient().new_builder(IoTDAClient)
    client: IoTDAClient = builder.with_http_config(config) \
        .with_credentials(credentials) \
        .with_endpoint(HwyunSettings.endpoint) \
        .with_stream_log(log_level=logging.INFO) \
        .build()
    return client
示例#6
0
def client():
    ak = "my ak"
    sk = "my sk"
    project_id = "my project_id"
    endpoint = "https://vpc.cn-north-x.myhuaweicloud.com"

    config = HttpConfig.get_default_config()
    config.ignore_ssl_verification = True
    credentials = BasicCredentials(ak, sk, project_id)

    client = ClientBuilder(Client) \
        .with_http_config(config) \
        .with_credentials(credentials) \
        .with_endpoint(endpoint) \
        .build()

    yield client
def test_upload_download(mocker):
    client = Client().with_credentials(
        BasicCredentials("ak", "sk",
                         "project_id")).with_endpoint("mock://test.com")

    mocker.patch.object(client, '_is_stream', return_value=True)
    mocker.patch.object(client,
                        '_do_http_request_sync',
                        return_value=mocked_file_response())
    mocker.patch.object(client,
                        'deserialize',
                        return_value=SdkStreamResponse(mocked_file_response()))

    response = client.do_http_request(
        method="POST",
        resource_path="/",
        header_params={"Content-Type": "application/octet-stream"},
        body=mocked_file(),
        response_type="SdkStreamResponse")

    response.consumeDownloadStream(process_stream)
示例#8
0
import pytest

from huaweicloudsdkcore.auth.credentials import BasicCredentials
from huaweicloudsdkcore.http.http_config import HttpConfig
from huaweicloudsdkcore.region.region import Region
from tests.data.project_response_mocker import MOCK_ENDPOINT
from tests.model.service.service_client import ServiceClient
from tests.model.service.service_region import ServiceRegion

OVERRIDE_ENDPOINT = "https://service.cn-north-x.myhuaweicloud.com"

config = HttpConfig.get_default_config()
config.ignore_ssl_verification = True

credentials = BasicCredentials("ak", "sk", "project_id")


def test_endpoint_with_region_1():
    client = ServiceClient.new_builder() \
        .with_http_config(config) \
        .with_credentials(credentials) \
        .with_region(ServiceRegion.CN_NORTH_7) \
        .build()

    assert hasattr(client, "_endpoint") is True
    assert getattr(client, "_endpoint") == MOCK_ENDPOINT


def test_endpoint_with_region_2():
    client = ServiceClient.new_builder() \
示例#9
0
def get_yaml_data(yaml_file):
    file = open(yaml_file, 'r', encoding="utf-8")
    file_data = file.read()
    file.close()
    data = yaml.load(file_data, Loader=yaml.FullLoader)
    return data


if __name__ == "__main__":
    current_path = os.path.abspath("../config")
    yaml_path = os.path.join(current_path, "config.yaml")
    config_file = get_yaml_data(yaml_path)
    ak = config_file["huaweiocr"]["AccessKey"]
    sk = config_file["huaweiocr"]["SecretAccessKey"]

    credentials = BasicCredentials(ak, sk) \

    client = OcrClient.new_builder() \
        .with_credentials(credentials) \
        .with_region(OcrRegion.value_of("cn-north-4")) \
        .build()

    try:
        request = RecognizeIdCardRequest()
        request.body = IdCardRequestBody(
            side="front",
            url=
            "https://file.yuanfusc.com/group1/M00/09/B5/rBOz8V25Iu2ACDmCAACQ5EvSOMg247.jpg"
        )
        response = client.recognize_id_card(request)
        print(response)
示例#10
0
        #         print("list: " + rule['id'])
        return response.to_dict()
    except exceptions.ClientRequestException as e:
        print(e.status_code)
        print(e.request_id)
        print(e.error_code)
        print(e.error_msg)


if __name__ == "__main__":
    start(sys.argv[1:])

    (ak, sk, project_id, region, endpoint, security_group_id) = get_cred_config()

    config = HttpConfig.get_default_config()
    config.ignore_ssl_verification = False
    credentials = BasicCredentials(ak, sk, project_id)

    vpc_client = VpcClient.new_builder(VpcClient) \
        .with_http_config(config) \
        .with_credentials(credentials) \
        .with_region(VpcRegion.value_of(region)) \
        .build()

    # list_vpc(vpc_client)
    # list_sg(vpc_client)

    current_rules = list_sg(vpc_client, security_group_id)
    condition = date_to_be_deleted
    delete_sg(vpc_client, security_group_id, current_rules, condition)