Merge pull request #10 from devigned/helpers
add sas comments and new event hub constructor
This commit is contained in:
Коммит
4b4cd3f5f0
|
@ -108,6 +108,6 @@
|
|||
[solve-meta]
|
||||
analyzer-name = "dep"
|
||||
analyzer-version = 1
|
||||
inputs-digest = "b7c45c0ec32d34417f3a7f0cd4ad053b98b3bb6c56d189c9585a2e10c2f49a62"
|
||||
inputs-digest = "ba2c4b282a80f80853ac403c1d0d0b2556faa19bd890174ca2a2cc7d06b810f2"
|
||||
solver-name = "gps-cdcl"
|
||||
solver-version = 1
|
||||
|
|
32
hub.go
32
hub.go
|
@ -92,20 +92,10 @@ func NewClient(namespace, name string, tokenProvider auth.TokenProvider, opts ..
|
|||
return h, nil
|
||||
}
|
||||
|
||||
// NewClientFromEnvironment creates a new Event Hub client for sending and receiving messages from environment variables
|
||||
func NewClientFromEnvironment(opts ...HubOption) (Client, error) {
|
||||
const envErrMsg = "environment var %s must not be empty"
|
||||
var namespace, name string
|
||||
// NewClientWithNamespaceNameAndEnvironment creates a new Event Hub client for sending and receiving messages from
|
||||
// environment variables with supplied namespace and name
|
||||
func NewClientWithNamespaceNameAndEnvironment(namespace, name string, opts ...HubOption) (Client, error) {
|
||||
var provider auth.TokenProvider
|
||||
|
||||
if namespace = os.Getenv("EVENTHUB_NAMESPACE"); namespace == "" {
|
||||
return nil, errors.Errorf(envErrMsg, "EVENTHUB_NAMESPACE")
|
||||
}
|
||||
|
||||
if name = os.Getenv("EVENTHUB_NAME"); name == "" {
|
||||
return nil, errors.Errorf(envErrMsg, "EVENTHUB_NAME")
|
||||
}
|
||||
|
||||
aadProvider, aadErr := aad.NewProviderFromEnvironment()
|
||||
sasProvider, sasErr := sas.NewProviderFromEnvironment()
|
||||
|
||||
|
@ -131,6 +121,22 @@ func NewClientFromEnvironment(opts ...HubOption) (Client, error) {
|
|||
return h, nil
|
||||
}
|
||||
|
||||
// NewClientFromEnvironment creates a new Event Hub client for sending and receiving messages from environment variables
|
||||
func NewClientFromEnvironment(opts ...HubOption) (Client, error) {
|
||||
const envErrMsg = "environment var %s must not be empty"
|
||||
var namespace, name string
|
||||
|
||||
if namespace = os.Getenv("EVENTHUB_NAMESPACE"); namespace == "" {
|
||||
return nil, errors.Errorf(envErrMsg, "EVENTHUB_NAMESPACE")
|
||||
}
|
||||
|
||||
if name = os.Getenv("EVENTHUB_NAME"); name == "" {
|
||||
return nil, errors.Errorf(envErrMsg, "EVENTHUB_NAME")
|
||||
}
|
||||
|
||||
return NewClientWithNamespaceNameAndEnvironment(namespace, name, opts...)
|
||||
}
|
||||
|
||||
// GetRuntimeInformation fetches runtime information from the Event Hub management node
|
||||
func (h *hub) GetRuntimeInformation(ctx context.Context) (*mgmt.HubRuntimeInformation, error) {
|
||||
client := mgmt.NewClient(h.namespace.name, h.name, h.namespace.tokenProvider, h.namespace.environment)
|
||||
|
|
|
@ -39,10 +39,17 @@ func NewProvider(namespace, keyName, key string) auth.TokenProvider {
|
|||
|
||||
// NewProviderFromEnvironment creates a new SAS TokenProvider from environment variables
|
||||
//
|
||||
// Expected Environment Variables:
|
||||
// There are two sets of environment variables which can produce a SAS TokenProvider
|
||||
//
|
||||
// 1) Expected Environment Variables:
|
||||
// - "EVENTHUB_NAMESPACE" the namespace of the Event Hub instance
|
||||
// - "EVENTHUB_KEY_NAME" the name of the Event Hub key
|
||||
// - "EVENTHUB_KEY_VALUE" the secret for the Event Hub key named in "EVENTHUB_KEY_NAME"
|
||||
//
|
||||
// 2) Expected Environment Variable:
|
||||
// - "EVENTHUB_CONNECTION_STRING" connection string from the Azure portal
|
||||
//
|
||||
// looks like: Endpoint=sb://namespace.servicebus.windows.net/;SharedAccessKeyName=RootManageSharedAccessKey;SharedAccessKey=superSecret1234=
|
||||
func NewProviderFromEnvironment() (auth.TokenProvider, error) {
|
||||
var provider auth.TokenProvider
|
||||
keyName := os.Getenv("EVENTHUB_KEY_NAME")
|
||||
|
|
Загрузка…
Ссылка в новой задаче