Beispiel #1
0
def wait_private_endpoint_conn(cmd, name, conn_name, resource_group_name=None):
    rp = ResourceProvider(cmd)
    return rp.get_private_endpoint_conn(
        name=name,
        resource_group_name=resource_group_name,
        conn_name=conn_name,
        wait=True)
def _add_endpoint_eventhub(
    cmd,
    name,
    endpoint_name,
    eventhub_name,
    eventhub_resource_group,
    eventhub_policy,
    eventhub_namespace,
    resource_group_name=None,
    endpoint_subscription=None,
    tags=None,
):
    rp = ResourceProvider(cmd)
    return rp.add_endpoint(
        name=name,
        resource_group_name=resource_group_name,
        endpoint_name=endpoint_name,
        endpoint_resource_type=ADTEndpointType.eventhub,
        endpoint_resource_name=eventhub_name,
        endpoint_resource_group=eventhub_resource_group,
        endpoint_resource_namespace=eventhub_namespace,
        endpoint_resource_policy=eventhub_policy,
        endpoint_subscription=endpoint_subscription,
        tags=tags,
    )
def _add_endpoint_servicebus(
    cmd,
    name,
    endpoint_name,
    servicebus_topic_name,
    servicebus_resource_group,
    servicebus_policy,
    servicebus_namespace,
    resource_group_name=None,
    endpoint_subscription=None,
    tags=None,
):
    rp = ResourceProvider(cmd)
    return rp.add_endpoint(
        name=name,
        resource_group_name=resource_group_name,
        endpoint_name=endpoint_name,
        endpoint_resource_type=ADTEndpointType.servicebus,
        endpoint_resource_name=servicebus_topic_name,
        endpoint_resource_group=servicebus_resource_group,
        endpoint_resource_namespace=servicebus_namespace,
        endpoint_resource_policy=servicebus_policy,
        endpoint_subscription=endpoint_subscription,
        tags=tags,
    )
Beispiel #4
0
def add_endpoint_eventhub(
    cmd,
    name,
    endpoint_name,
    eventhub_name,
    eventhub_resource_group,
    eventhub_namespace,
    eventhub_policy=None,
    resource_group_name=None,
    endpoint_subscription=None,
    dead_letter_uri=None,
    dead_letter_secret=None,
    auth_type=ADTEndpointAuthType.keybased.value,
):
    rp = ResourceProvider(cmd)
    return rp.add_endpoint(
        name=name,
        resource_group_name=resource_group_name,
        endpoint_name=endpoint_name,
        endpoint_resource_type=ADTEndpointType.eventhub.value,
        endpoint_resource_name=eventhub_name,
        endpoint_resource_group=eventhub_resource_group,
        endpoint_resource_namespace=eventhub_namespace,
        endpoint_resource_policy=eventhub_policy,
        endpoint_subscription=endpoint_subscription,
        dead_letter_uri=dead_letter_uri,
        dead_letter_secret=dead_letter_secret,
        auth_type=auth_type,
    )
Beispiel #5
0
def add_endpoint_servicebus(
    cmd,
    name,
    endpoint_name,
    servicebus_topic_name,
    servicebus_resource_group,
    servicebus_namespace,
    servicebus_policy=None,
    resource_group_name=None,
    endpoint_subscription=None,
    dead_letter_uri=None,
    dead_letter_secret=None,
    auth_type=ADTEndpointAuthType.keybased.value,
):
    rp = ResourceProvider(cmd)
    return rp.add_endpoint(
        name=name,
        resource_group_name=resource_group_name,
        endpoint_name=endpoint_name,
        endpoint_resource_type=ADTEndpointType.servicebus.value,
        endpoint_resource_name=servicebus_topic_name,
        endpoint_resource_group=servicebus_resource_group,
        endpoint_resource_namespace=servicebus_namespace,
        endpoint_resource_policy=servicebus_policy,
        endpoint_subscription=endpoint_subscription,
        dead_letter_uri=dead_letter_uri,
        dead_letter_secret=dead_letter_secret,
        auth_type=auth_type,
    )
Beispiel #6
0
def add_endpoint_eventgrid(
    cmd,
    name,
    endpoint_name,
    eventgrid_topic_name,
    eventgrid_resource_group,
    resource_group_name=None,
    endpoint_subscription=None,
    dead_letter_uri=None,
    dead_letter_secret=None,
    auth_type=ADTEndpointAuthType.keybased.value,
):
    rp = ResourceProvider(cmd)
    return rp.add_endpoint(
        name=name,
        resource_group_name=resource_group_name,
        endpoint_name=endpoint_name,
        endpoint_resource_type=ADTEndpointType.eventgridtopic.value,
        endpoint_resource_name=eventgrid_topic_name,
        endpoint_resource_group=eventgrid_resource_group,
        endpoint_subscription=endpoint_subscription,
        dead_letter_uri=dead_letter_uri,
        dead_letter_secret=dead_letter_secret,
        auth_type=auth_type,
    )
def assign_role(cmd, name, role_type, assignee, resource_group_name=None):
    rp = ResourceProvider(cmd)
    return rp.assign_role(
        name=name,
        role_type=role_type,
        assignee=assignee,
        resource_group_name=resource_group_name,
    )
Beispiel #8
0
def delete_private_endpoint_conn(cmd,
                                 name,
                                 conn_name,
                                 resource_group_name=None):
    rp = ResourceProvider(cmd)
    return rp.delete_private_endpoint_conn(
        name=name,
        resource_group_name=resource_group_name,
        conn_name=conn_name)
Beispiel #9
0
    def __init__(self, cmd, name, rg=None):
        assert cmd
        assert name

        self.cmd = cmd
        self.name = name
        self.rg = rg
        self.resource_id = DIGITALTWINS_RESOURCE_ID
        self.rp = ResourceProvider(self.cmd)
def list_assignments(cmd,
                     name,
                     include_inherited=False,
                     role_type=None,
                     resource_group_name=None):
    rp = ResourceProvider(cmd)
    return rp.get_role_assignments(
        name=name,
        include_inherited=include_inherited,
        resource_group_name=resource_group_name,
        role_type=role_type,
    )
Beispiel #11
0
class DigitalTwinsProvider(object):
    def __init__(self, cmd, name, rg=None):
        assert cmd
        assert name

        self.cmd = cmd
        self.name = name
        self.rg = rg
        self.resource_id = DIGITALTWINS_RESOURCE_ID
        self.rp = ResourceProvider(self.cmd)

    def _get_endpoint(self):
        host_name = None
        https_prefix = "https://"
        http_prefix = "http://"

        if self.name.lower().startswith(https_prefix):
            self.name = self.name[len(https_prefix):]
        elif self.name.lower().startswith(http_prefix):
            self.name = self.name[len(http_prefix):]

        if not all([valid_hostname(self.name), "." in self.name]):
            instance = self.rp.find_instance(name=self.name, resource_group_name=self.rg)
            host_name = instance.host_name
            if not host_name:
                raise CLIError("Instance has invalid hostName. Aborting operation...")
        else:
            host_name = self.name

        return "https://{}".format(host_name)

    def get_sdk(self):
        creds = DigitalTwinAuthentication(cmd=self.cmd, resource_id=self.resource_id)
        return AzureDigitalTwinsAPI(base_url=self._get_endpoint(), credentials=creds)
Beispiel #12
0
def set_private_endpoint_conn(
    cmd,
    name,
    conn_name,
    status,
    description=None,
    group_ids=None,
    actions_required=None,
    resource_group_name=None,
):
    rp = ResourceProvider(cmd)
    return rp.set_private_endpoint_conn(
        name=name,
        resource_group_name=resource_group_name,
        conn_name=conn_name,
        status=status,
        description=description,
        group_ids=group_ids,
        actions_required=actions_required,
    )
def _add_endpoint_eventgrid(
    cmd,
    name,
    endpoint_name,
    eventgrid_topic_name,
    eventgrid_resource_group,
    resource_group_name=None,
    endpoint_subscription=None,
    tags=None,
):
    rp = ResourceProvider(cmd)
    return rp.add_endpoint(
        name=name,
        resource_group_name=resource_group_name,
        endpoint_name=endpoint_name,
        endpoint_resource_type=ADTEndpointType.eventgridtopic,
        endpoint_resource_name=eventgrid_topic_name,
        endpoint_resource_group=eventgrid_resource_group,
        endpoint_subscription=endpoint_subscription,
        tags=tags,
    )
def _add_endpoint_eventgrid(
    cmd,
    name,
    endpoint_name,
    eventgrid_topic_name,
    eventgrid_resource_group,
    timeout=15,
    resource_group_name=None,
    tags=None,
):
    rp = ResourceProvider(cmd)
    return rp.add_endpoint(
        name=name,
        resource_group_name=resource_group_name,
        endpoint_name=endpoint_name,
        endpoint_resource_type=ADTEndpointType.eventgridtopic,
        endpoint_resource_name=eventgrid_topic_name,
        endpoint_resource_group=eventgrid_resource_group,
        tags=tags,
        timeout=timeout,
    )
Beispiel #15
0
def create_instance(
    cmd,
    name,
    resource_group_name,
    location=None,
    tags=None,
    assign_identity=None,
    scopes=None,
    role_type="Contributor",
    public_network_access=ADTPublicNetworkAccessType.enabled.value,
):
    rp = ResourceProvider(cmd)
    return rp.create(
        name=name,
        resource_group_name=resource_group_name,
        location=location,
        tags=tags,
        assign_identity=assign_identity,
        scopes=scopes,
        role_type=role_type,
        public_network_access=public_network_access,
    )
class DigitalTwinsProvider(object):
    def __init__(self, cmd, name, rg=None):
        assert cmd
        assert name

        self.cmd = cmd
        self.name = name
        self.rg = rg
        self.resource_id = DIGITALTWINS_RESOURCE_ID
        self.rp = ResourceProvider(self.cmd)

    def _get_endpoint(self):
        host_name = None
        https_prefix = "https://"
        http_prefix = "http://"

        if self.name.lower().startswith(https_prefix):
            self.name = self.name[len(https_prefix):]
        elif self.name.lower().startswith(http_prefix):
            self.name = self.name[len(http_prefix):]

        if not all([valid_hostname(self.name), "." in self.name]):
            instance = self.rp.find_instance(name=self.name,
                                             resource_group_name=self.rg)
            host_name = instance.host_name
            if not host_name:
                raise CLIError(
                    "Instance has invalid hostName. Aborting operation...")
        else:
            host_name = self.name

        return "https://{}".format(host_name)

    def get_sdk(self):
        from azure.cli.core.commands.client_factory import get_mgmt_service_client

        client = get_mgmt_service_client(
            cli_ctx=self.cmd.cli_ctx,
            client_or_resource_type=AzureDigitalTwinsAPI,
            base_url=self._get_endpoint(),
            resource=self.resource_id,
            subscription_bound=False,
            base_url_bound=False,
        )

        client.config.add_user_agent(USER_AGENT)
        return client
class DigitalTwinsProvider(object):
    def __init__(self, cmd, name, rg=None):
        assert cmd
        assert name

        self.cmd = cmd
        self.name = name
        self.rg = rg
        self.resource_id = DIGITALTWINS_RESOURCE_ID
        self.rp = ResourceProvider(self.cmd)

    def _get_endpoint(self):
        instance = self.rp.find_instance(name=self.name, resource_group_name=self.rg)
        host_name = instance.host_name
        if not host_name:
            raise CLIError("Retrieved hostName was null which is invalid.")
        return "https://{}".format(instance.host_name)

    def get_sdk(self):
        creds = DigitalTwinAuthentication(cmd=self.cmd, resource_id=self.resource_id)
        return AzureDigitalTwinsAPI(base_url=self._get_endpoint(), credentials=creds)
def delete_endpoint(cmd, name, endpoint_name, resource_group_name=None):
    rp = ResourceProvider(cmd)
    return rp.delete_endpoint(name=name,
                              endpoint_name=endpoint_name,
                              resource_group_name=resource_group_name)
def show_endpoint(cmd, name, endpoint_name, resource_group_name=None):
    rp = ResourceProvider(cmd)
    return rp.get_endpoint(name=name,
                           endpoint_name=endpoint_name,
                           resource_group_name=resource_group_name)
def list_endpoints(cmd, name, resource_group_name=None):
    rp = ResourceProvider(cmd)
    return rp.list_endpoints(name=name,
                             resource_group_name=resource_group_name)
def delete_instance(cmd, name, resource_group_name=None):
    rp = ResourceProvider(cmd)
    return rp.delete(name=name, resource_group_name=resource_group_name)
def show_instance(cmd, name, resource_group_name=None):
    rp = ResourceProvider(cmd)
    return rp.find_instance(name=name, resource_group_name=resource_group_name)
Beispiel #23
0
def show_private_link(cmd, name, link_name, resource_group_name=None):
    rp = ResourceProvider(cmd)
    return rp.get_private_link(name=name,
                               resource_group_name=resource_group_name,
                               link_name=link_name)
Beispiel #24
0
def list_private_links(cmd, name, resource_group_name=None):
    rp = ResourceProvider(cmd)
    return rp.list_private_links(name=name,
                                 resource_group_name=resource_group_name)
def create_instance(cmd, name, resource_group_name, location=None, tags=None):
    rp = ResourceProvider(cmd)
    return rp.create(name=name,
                     resource_group_name=resource_group_name,
                     location=location,
                     tags=tags)
Beispiel #26
0
def wait_instance(cmd, name, resource_group_name=None):
    rp = ResourceProvider(cmd)
    return rp.find_instance(name=name,
                            resource_group_name=resource_group_name,
                            wait=True)
def list_instances(cmd, resource_group_name=None):
    rp = ResourceProvider(cmd)

    if not resource_group_name:
        return rp.list()
    return rp.list_by_resouce_group(resource_group_name)
Beispiel #28
0
def dt_rp(fixture_cmd2):
    rp = ResourceProvider(fixture_cmd2)
    yield rp