def _setup_consumer_groups(self):
     """Constructs consumer groups for all EventHub entities requested."""
     groups = [
         EventHubConsumerGroup(
             EventHub(
                 get_resource_group_name(self.config, self.env),
                 get_eventhub_name(self.config, self.env),
                 get_eventhub_entity_name(group["eventhub_entity_naming"],
                                          self.env),
             ),
             group["consumer_group"],
             group["create_databricks_secret"],
             group["append_env_to_databricks_secret_name"],
         ) for group in self.config["create_consumer_groups"]
     ]
     self.create_eventhub_consumer_groups(groups)
Esempio n. 2
0
    def _authenticate_with_kubernetes(self):
        """Authenticate with the defined AKS cluster and write the configuration to a file"""
        resource_group = get_resource_group_name(self.config, self.env)
        cluster_name = get_kubernetes_name(self.config, self.env)

        # get azure container service client
        credentials = ActiveDirectoryUserCredentials(
            vault_name=self.vault_name, vault_client=self.vault_client
        ).credentials(self.config)

        client = ContainerServiceClient(
            credentials=credentials,
            subscription_id=SubscriptionId(self.vault_name, self.vault_client).subscription_id(self.config),
        )

        # authenticate with Kubernetes
        credential_results = client.managed_clusters.list_cluster_user_credentials(
            resource_group_name=resource_group, resource_name=cluster_name
        )

        self._write_kube_config(credential_results)
Esempio n. 3
0
    def create_application_insights(self):
        client = self._create_client()

        insight = self._find_existing_instance(client, self.application_name)
        if not insight:
            logger.info("Creating new Application Insights...")
            # Create a new Application Insights
            comp = ApplicationInsightsComponent(
                location=self.config["azure"]["location"],
                kind=self.config["kind"],
                application_type=self.config["application_type"],
            )
            insight = client.components.create_or_update(
                get_resource_group_name(self.config, self.env),
                self.application_name, comp)

        if self.config["create_databricks_secret"]:
            instrumentation_secret = Secret("instrumentation-key",
                                            insight.instrumentation_key)
            self.create_databricks_secret(self.application_name,
                                          instrumentation_secret)
    def create_eventhub_producer_policies(
            self, producer_policies: List[EventHubProducerPolicy]):
        """Constructs producer policies for all EventHub entities requested.

        Args:
            producer_policies: List of producer policies to create
        """
        eventhub_namespace = get_eventhub_name(self.config, self.env)
        resource_group = get_resource_group_name(self.config, self.env)

        logger.info(f"Using Azure resource group: {resource_group}")
        logger.info(f"Using Azure EventHub namespace: {eventhub_namespace}")

        secrets = [
            self._create_producer_policy(policy, resource_group,
                                         eventhub_namespace,
                                         self.application_name)
            for policy in producer_policies
        ]
        Context().create_or_update(ContextKey.EVENTHUB_PRODUCER_POLICY_SECRETS,
                                   secrets)
Esempio n. 5
0
def test_get_default_resource_group():
    res = victim.get_resource_group_name(
        {'azure': {
            'resource_group_naming': 'rg{env}'
        }}, ENV)
    assert res == "rgdev"
Esempio n. 6
0
 def _get_cosmos_instance(self) -> dict:
     return {
         "resource_group_name":
         get_resource_group_name(self.config, self.env),
         "account_name": get_cosmos_name(self.config, self.env),
     }