コード例 #1
0
ファイル: test_util.py プロジェクト: timvancann/takeoff
def test_get_custom_eventhub_entity_name():
    paths = [os.path.dirname(os.path.realpath(__file__))]
    add_takeoff_plugin_paths(paths)

    res = victim.get_eventhub_entity_name("", ENV)
    assert res == "Romeo"
    sys.path.remove(paths[0])
コード例 #2
0
 def _setup_producer_policies(self):
     policies = [
         EventHubProducerPolicy(
             get_eventhub_entity_name(policy["eventhub_entity_naming"],
                                      self.env),
             policy["create_databricks_secret"],
         ) for policy in self.config["create_producer_policies"]
     ]
     self.create_eventhub_producer_policies(policies)
コード例 #3
0
ファイル: configure_eventhub.py プロジェクト: bcambel/takeoff
 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"],
         ) for group in self.config["create_consumer_groups"]
     ]
     self.create_eventhub_consumer_groups(groups)
コード例 #4
0
    def _create_producer_policy(
        self,
        policy: EventHubProducerPolicy,
        resource_group: str,
        eventhub_namespace: str,
        application_name: str,
    ) -> Secret:
        """Creates given producer policy on EventHub. Optionally constructs Databricks secret
        containing the connection string for the policy.

        Args:
            policy: Name of the EventHub entity
            resource_group: The name of the resource group
            eventhub_namespace: The name of the EventHub namespace
            application_name: The name of this application
        """
        common_azure_parameters = {
            "resource_group_name":
            resource_group,
            "namespace_name":
            eventhub_namespace,
            "event_hub_name":
            get_eventhub_entity_name(policy.eventhub_entity_name, self.env),
            "authorization_rule_name":
            f"{application_name}-send-policy",
        }

        try:
            logger.info(
                f"Creating producer policy with values {pprint.pformat(common_azure_parameters)}"
            )
            self.eventhub_client.event_hubs.create_or_update_authorization_rule(
                **common_azure_parameters, rights=[AccessRights.send])
            connection_string = self.eventhub_client.event_hubs.list_keys(
                **common_azure_parameters).primary_connection_string
        except Exception as e:
            logger.error(
                "Could not create connection String. Make sure the EventHub exists."
            )
            raise e

        secret = Secret(f"{policy.eventhub_entity_name}-connection-string",
                        connection_string)
        if policy.create_databricks_secret:
            self.create_databricks_secrets([secret])
        return secret
コード例 #5
0
ファイル: test_util.py プロジェクト: timvancann/takeoff
def test_get_default_eventhub_entity_name():
    res = victim.get_eventhub_entity_name("Michael{env}", ENV)
    assert res == "Michaeldev"