func New()

in internal/output/azureeventhub/azure_event_hub.go [27:52]


func New(opts *output.Options) (output.Output, error) {
	var producerClient *azeventhubs.ProducerClient
	var err error

	if opts.AzureEventHubOptions.ConnectionString != "" {
		producerClient, err = azeventhubs.NewProducerClientFromConnectionString(opts.AzureEventHubOptions.ConnectionString, opts.AzureEventHubOptions.EventHubName, nil)
		if err != nil {
			return nil, fmt.Errorf("error while creating new eventhub producer client from connection string: %w", err)
		}
	} else {
		fmt.Print("no connection string was provided, falling back to default credentials or environment variable")

		// Credentials set as env variables - https://github.com/Azure/azure-sdk-for-go/tree/main/sdk/azidentity#environment-variables
		defaultAzureCred, err := azidentity.NewDefaultAzureCredential(nil)
		if err != nil {
			return nil, fmt.Errorf("missing azure credentials in the environment variables: %w", err)
		}

		producerClient, err = azeventhubs.NewProducerClient(opts.AzureEventHubOptions.FullyQualifiedNamespace, opts.AzureEventHubOptions.EventHubName, defaultAzureCred, nil)
		if err != nil {
			return nil, fmt.Errorf("error while creating new eventhub producer client: %w", err)
		}
	}
	ctx, cancel := context.WithCancel(context.Background())
	return &Output{opts: opts, producerClient: producerClient, cancelFunc: cancel, cancelCtx: ctx}, nil
}