@@ -7,7 +7,6 @@ package publisher
77
88import (
99 "context"
10- "net/http"
1110
1211 "github.com/Azure/azure-sdk-for-go/sdk/azcore"
1312 "github.com/Azure/azure-sdk-for-go/sdk/azcore/messaging"
@@ -45,20 +44,17 @@ func NewClient(endpoint string, tokenCredential azcore.TokenCredential, options
4544 }, nil
4645}
4746
48- // NewClientWithSharedKeyCredential creates a [Client] using a shared key.
49- func NewClientWithSharedKeyCredential (endpoint string , key string , options * ClientOptions ) (* Client , error ) {
47+ // NewClientWithSharedKeyCredential creates a [Client] using a shared key credential .
48+ func NewClientWithSharedKeyCredential (endpoint string , keyCred * azcore. KeyCredential , options * ClientOptions ) (* Client , error ) {
5049 const sasKeyHeader = "aeg-sas-key"
5150
5251 if options == nil {
5352 options = & ClientOptions {}
5453 }
5554
56- // TODO: I believe we're supposed to allow for dynamically updating the key at any time as well.
5755 azc , err := azcore .NewClient (internal .ModuleName + ".Client" , internal .ModuleVersion , runtime.PipelineOptions {
5856 PerRetry : []policy.Policy {
59- // TODO: Java has a specific policy for this kind of authentication.
60- // AzureKeyCredentialPolicy
61- & skpolicy {HeaderName : sasKeyHeader , Key : key },
57+ runtime .NewKeyCredentialPolicy (keyCred , sasKeyHeader , nil ),
6258 },
6359 }, & options .ClientOptions )
6460
@@ -72,20 +68,17 @@ func NewClientWithSharedKeyCredential(endpoint string, key string, options *Clie
7268 }, nil
7369}
7470
75- // NewClientWithSharedKeyCredential creates a [Client] using a shared key .
76- func NewClientWithSAS (endpoint string , sas string , options * ClientOptions ) (* Client , error ) {
71+ // NewClientWithSAS creates a [Client] using a shared access signature credential .
72+ func NewClientWithSAS (endpoint string , sasCred * azcore. SASCredential , options * ClientOptions ) (* Client , error ) {
7773 const sasTokenHeader = "aeg-sas-token"
7874
7975 if options == nil {
8076 options = & ClientOptions {}
8177 }
8278
83- // TODO: I believe we're supposed to allow for dynamically updating the key at any time as well.
8479 azc , err := azcore .NewClient (internal .ModuleName + ".PublisherClient" , internal .ModuleVersion , runtime.PipelineOptions {
8580 PerRetry : []policy.Policy {
86- // TODO: Java has a specific policy for this kind of authentication.
87- // AzureKeyCredentialPolicy
88- & skpolicy {HeaderName : sasTokenHeader , Key : sas },
81+ runtime .NewSASCredentialPolicy (sasCred , sasTokenHeader , nil ),
8982 },
9083 }, & options .ClientOptions )
9184
@@ -99,17 +92,6 @@ func NewClientWithSAS(endpoint string, sas string, options *ClientOptions) (*Cli
9992 }, nil
10093}
10194
102- // TODO: remove in favor of a common policy instead?
103- type skpolicy struct {
104- Key string
105- HeaderName string
106- }
107-
108- func (p * skpolicy ) Do (req * policy.Request ) (* http.Response , error ) {
109- req .Raw ().Header .Add (p .HeaderName , p .Key )
110- return req .Next ()
111- }
112-
11395// PublishCloudEvents - Publishes a batch of events to an Azure Event Grid topic.
11496// If the operation fails it returns an *azcore.ResponseError type.
11597//
0 commit comments