Skip to content

Commit

Permalink
fmt with Go 1.19
Browse files Browse the repository at this point in the history
  • Loading branch information
chlowell committed Aug 8, 2022
1 parent 5f66c47 commit 1e08e16
Show file tree
Hide file tree
Showing 54 changed files with 478 additions and 460 deletions.
8 changes: 5 additions & 3 deletions sdk/azidentity/default_azure_credential.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,11 @@ type DefaultAzureCredentialOptions struct {
// DefaultAzureCredential is a default credential chain for applications that will deploy to Azure.
// It combines credentials suitable for deployment with credentials suitable for local development.
// It attempts to authenticate with each of these credential types, in the following order, stopping when one provides a token:
// EnvironmentCredential
// ManagedIdentityCredential
// AzureCLICredential
//
// EnvironmentCredential
// ManagedIdentityCredential
// AzureCLICredential
//
// Consult the documentation for these credential types for more information on how they authenticate.
// Once a credential has successfully authenticated, DefaultAzureCredential will use that credential for
// every subsequent authentication.
Expand Down
6 changes: 3 additions & 3 deletions sdk/azidentity/environment_credential.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,15 +28,15 @@ type EnvironmentCredentialOptions struct {
// EnvironmentCredential authenticates a service principal with a secret or certificate, or a user with a password, depending
// on environment variable configuration. It reads configuration from these variables, in the following order:
//
// Service principal with client secret
// # Service principal with client secret
//
// AZURE_TENANT_ID: ID of the service principal's tenant. Also called its "directory" ID.
//
// AZURE_CLIENT_ID: the service principal's client ID
//
// AZURE_CLIENT_SECRET: one of the service principal's client secrets
//
// Service principal with certificate
// # Service principal with certificate
//
// AZURE_TENANT_ID: ID of the service principal's tenant. Also called its "directory" ID.
//
Expand All @@ -46,7 +46,7 @@ type EnvironmentCredentialOptions struct {
//
// AZURE_CLIENT_CERTIFICATE_PASSWORD: (optional) password for the certificate file.
//
// User with username and password
// # User with username and password
//
// AZURE_TENANT_ID: (optional) tenant to authenticate in. Defaults to "organizations".
//
Expand Down
42 changes: 19 additions & 23 deletions sdk/data/azcosmos/doc.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,24 +6,24 @@
Package azcosmos implements the client to interact with the Azure Cosmos DB SQL API.
The azcosmos package is capable of:
- Creating, deleting, and reading databases in an account
- Creating, deleting, updating, and reading containers in a database
- Creating, deleting, replacing, upserting, and reading items in a container
- Creating, deleting, and reading databases in an account
- Creating, deleting, updating, and reading containers in a database
- Creating, deleting, replacing, upserting, and reading items in a container
Creating the Client
# Creating the Client
Types of Credentials
The clients support different forms of authentication. The azcosmos library supports
authorization via Azure Active Directory or an account key.
Using Azure Active Directory
To create a client, you can use any of the TokenCredential implementations provided by `azidentity`.
cred, err := azidentity.NewClientSecretCredential("tenantId", "clientId", "clientSecret")
handle(err)
client, err := azcosmos.NewClient("myAccountEndpointURL", cred, nil)
handle(err)
Using account keys
To create a client, you will need the account's endpoint URL and a key credential.
Expand All @@ -32,34 +32,30 @@ To create a client, you will need the account's endpoint URL and a key credentia
client, err := azcosmos.NewClientWithKey("myAccountEndpointURL", cred, nil)
handle(err)
Using connection string
To create a client, you will need the account's connection string.
client, err := azcosmos.NewClientFromConnectionString("myConnectionString", nil)
handle(err)
Key Concepts
# Key Concepts
The following are relevant concepts for the usage of the client:
- A client is a connection to an Azure Cosmos DB account.
- An account can have multiple databases, and the client allows you to create, read, and delete databases.
- A database can have multiple containers, and the client allows you to create, read, update, and delete containers, and to modify throughput provision.
- Information is stored as items inside containers and the client allows you to create, read, update, and delete items in containers.
- A client is a connection to an Azure Cosmos DB account.
- An account can have multiple databases, and the client allows you to create, read, and delete databases.
- A database can have multiple containers, and the client allows you to create, read, update, and delete containers, and to modify throughput provision.
- Information is stored as items inside containers and the client allows you to create, read, update, and delete items in containers.
More Examples
# More Examples
The following sections provide several code snippets covering some of the most common Table tasks, including:
- Creating a database
- Creating a container
- Creating, reading, and deleting items
- Querying items
- Using Transactional Batch
- Creating a database
- Creating a container
- Creating, reading, and deleting items
- Querying items
- Using Transactional Batch
Creating a database
# Creating a database
Create a database and obtain a `DatabaseClient` to perform operations on your newly created database.
Expand All @@ -73,8 +69,7 @@ Create a database and obtain a `DatabaseClient` to perform operations on your ne
database, err := azcosmos.NewDatabase("myDatabase")
handle(err)
Creating a container
# Creating a container
Create a container on an existing database and obtain a `ContainerClient` to perform operations on your newly created container.
Expand Down Expand Up @@ -145,6 +140,7 @@ Querying items
}
Querying items with parametrized queries
&opt := azcosmos.QueryOptions{
azcosmos.QueryParameters: []QueryParameter{
{"@value", "2"},
Expand Down
2 changes: 1 addition & 1 deletion sdk/data/azcosmos/shared_key_credential.go
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ func (c *KeyCredential) buildCanonicalizedAuthHeaderFromRequest(req *policy.Requ
return value, nil
}

//where date is like time.RFC1123 but hard-codes GMT as the time zone
// where date is like time.RFC1123 but hard-codes GMT as the time zone
func (c *KeyCredential) buildCanonicalizedAuthHeader(method, resourceType, resourceAddress, xmsDate, tokenType, version string) string {
if method == "" || resourceType == "" {
return ""
Expand Down
4 changes: 2 additions & 2 deletions sdk/data/aztables/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -215,8 +215,8 @@ func newListEntitiesPage(resp generated.TableClientQueryEntitiesResponse) (ListE
//
// NewListEntitiesPager returns a Pager, which allows iteration through each page of results. Use nil for listOptions if you want to use the default options.
// For more information about writing query strings, check out:
// - API Documentation: https://docs.microsoft.com/en-us/rest/api/storageservices/querying-tables-and-entities
// - README samples: https://github.com/Azure/azure-sdk-for-go/blob/main/sdk/data/aztables/README.md#writing-filters
// - API Documentation: https://docs.microsoft.com/en-us/rest/api/storageservices/querying-tables-and-entities
// - README samples: https://github.com/Azure/azure-sdk-for-go/blob/main/sdk/data/aztables/README.md#writing-filters
func (t *Client) NewListEntitiesPager(listOptions *ListEntitiesOptions) *runtime.Pager[ListEntitiesResponse] {
if listOptions == nil {
listOptions = &ListEntitiesOptions{}
Expand Down
35 changes: 16 additions & 19 deletions sdk/data/aztables/doc.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,14 @@
// license that can be found in the LICENSE file.

/*
Package aztables can access an Azure Storage or CosmosDB account.
The aztables package is capable of:
- Creating, deleting, and listing tables in an account
- Creating, deleting, updating, and querying entities in a table account
- Creating Shared Access Signatures for authentication
- Creating, deleting, and listing tables in an account
- Creating, deleting, updating, and querying entities in a table account
- Creating Shared Access Signatures for authentication
Creating the Client
# Creating the Client
The Azure Data Tables library allows you to interact with two types of resources:
* the tables in your account
Expand All @@ -28,14 +27,13 @@ URL and a credential that allows you to access the account.
serviceClient, err := aztables.NewServiceClient("https://<my_account_name>.table.core.windows.net/", cred, nil)
handle(err)
Types of Credentials
# Types of Credentials
The clients support different forms of authentication. The aztables library supports
any of the `azcore.TokenCredential` interfaces, authorization via a Connection String,
or authorization with a Shared Access Signature token.
Using a Shared Key
# Using a Shared Key
To use an account shared key (aka account key or access key), provide the key as a string.
This can be found in your storage account in the Azure Portal under the "Access Keys" section.
Expand Down Expand Up @@ -74,8 +72,7 @@ ServiceClient.GetAccountSASToken or Client.GetTableSASToken() functions.
sasService, err := aztables.NewServiceClient(sasUrl, azcore.AnonymousCredential(), nil)
handle(err)
Key Concepts
# Key Concepts
Common uses of the Table service included:
* Storing TBs of structured data capable of serving web scale applications
Expand All @@ -93,13 +90,14 @@ through the use of a dedicated client object.
Two different clients are provided to interact with the various components of the Table Service:
1. **`ServiceClient`** -
* Get and set account setting
* Query, create, and delete tables within the account.
* Get a `Client` to access a specific table using the `NewClient` method.
- Get and set account setting
- Query, create, and delete tables within the account.
- Get a `Client` to access a specific table using the `NewClient` method.
2. **`Client`** -
* Interacts with a specific table (which need not exist yet).
* Create, delete, query, and upsert entities within the specified table.
* Create or delete the specified table itself.
- Interacts with a specific table (which need not exist yet).
- Create, delete, query, and upsert entities within the specified table.
- Create or delete the specified table itself.
Entities are similar to rows. An entity has a PartitionKey, a RowKey, and a set of properties.
A property is a name value pair, similar to a column. Every entity in a table does not need to
Expand All @@ -122,16 +120,15 @@ ensure proper round-trip serialization of all properties.
}
}
More Examples
# More Examples
The following sections provide several code snippets covering some of the most common Table tasks, including:
* Creating a table
* Creating entities
* Querying entities
Creating a Table
# Creating a Table
Create a table in your account and get a `Client` to perform operations on the newly created table:
Expand Down
4 changes: 2 additions & 2 deletions sdk/data/aztables/service_client.go
Original file line number Diff line number Diff line change
Expand Up @@ -218,8 +218,8 @@ func fromGeneratedTableResponseProperties(g *generated.TableResponseProperties)
//
// NewListTablesPager returns a Pager, which allows iteration through each page of results. Specify nil for listOptions if you want to use the default options.
// For more information about writing query strings, check out:
// - API Documentation: https://docs.microsoft.com/en-us/rest/api/storageservices/querying-tables-and-entities
// - README samples: https://github.com/Azure/azure-sdk-for-go/blob/main/sdk/data/aztables/README.md#writing-filters
// - API Documentation: https://docs.microsoft.com/en-us/rest/api/storageservices/querying-tables-and-entities
// - README samples: https://github.com/Azure/azure-sdk-for-go/blob/main/sdk/data/aztables/README.md#writing-filters
func (t *ServiceClient) NewListTablesPager(listOptions *ListTablesOptions) *runtime.Pager[ListTablesResponse] {
if listOptions == nil {
listOptions = &ListTablesOptions{}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -86,8 +86,9 @@ func (w *batchWriter) HandleEvent(ctx context.Context, event *eventhub.Event) er

// Flush flushes the buffer to the given io.Writer
// Post-condition:
// error == nil: buffer has been flushed successfully, buffer has been replaced with a new buffer
// error != nil: some or no events have been flushed, buffer contains only events that failed to flush
//
// error == nil: buffer has been flushed successfully, buffer has been replaced with a new buffer
// error != nil: some or no events have been flushed, buffer contains only events that failed to flush
func (w *batchWriter) Flush(ctx context.Context) error {
for i, s := range w.batch {
_, err := fmt.Fprintln(w.writer, s)
Expand Down
32 changes: 14 additions & 18 deletions sdk/messaging/azeventhubs/internal/hub.go
Original file line number Diff line number Diff line change
Expand Up @@ -359,26 +359,24 @@ func NewHub(namespace, name string, tokenProvider auth.TokenProvider, opts ...Hu
//
// There are two sets of environment variables which can produce a SAS TokenProvider
//
// 1) Expected Environment Variables:
// 1. Expected Environment Variables:
// - "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:
// 2. Expected Environment Variable:
// - "EVENTHUB_CONNECTION_STRING" connection string from the Azure portal
//
//
// AAD TokenProvider environment variables:
//
// 1. client Credentials: attempt to authenticate with a Service Principal via "AZURE_TENANT_ID", "AZURE_CLIENT_ID" and
// 1. client Credentials: attempt to authenticate with a Service Principal via "AZURE_TENANT_ID", "AZURE_CLIENT_ID" and
// "AZURE_CLIENT_SECRET"
//
// 2. client Certificate: attempt to authenticate with a Service Principal via "AZURE_TENANT_ID", "AZURE_CLIENT_ID",
// 2. client Certificate: attempt to authenticate with a Service Principal via "AZURE_TENANT_ID", "AZURE_CLIENT_ID",
// "AZURE_CERTIFICATE_PATH" and "AZURE_CERTIFICATE_PASSWORD"
//
// 3. Managed Service Identity (MSI): attempt to authenticate via MSI on the default local MSI internally addressable IP
// 3. Managed Service Identity (MSI): attempt to authenticate via MSI on the default local MSI internally addressable IP
// and port. See: adal.GetMSIVMEndpoint()
//
//
// The Azure Environment used can be specified using the name of the Azure Environment set in the AZURE_ENVIRONMENT var.
func NewHubWithNamespaceNameAndEnvironment(namespace, name string, opts ...HubOption) (*Hub, error) {
var provider auth.TokenProvider
Expand All @@ -401,7 +399,6 @@ func NewHubWithNamespaceNameAndEnvironment(namespace, name string, opts ...HubOp
// - "EVENTHUB_NAMESPACE" the namespace of the Event Hub instance
// - "EVENTHUB_NAME" the name of the Event Hub instance
//
//
// This method depends on NewHubWithNamespaceNameAndEnvironment which will attempt to build a token provider from
// environment variables. If unable to build a AAD Token Provider it will fall back to a SAS token provider. If neither
// can be built, it will return error.
Expand All @@ -410,24 +407,23 @@ func NewHubWithNamespaceNameAndEnvironment(namespace, name string, opts ...HubOp
//
// There are two sets of environment variables which can produce a SAS TokenProvider
//
// 1) Expected Environment Variables:
// 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:
// 2. Expected Environment Variable:
// - "EVENTHUB_CONNECTION_STRING" connection string from the Azure portal
//
//
// AAD TokenProvider environment variables:
// 1. client Credentials: attempt to authenticate with a Service Principal via "AZURE_TENANT_ID", "AZURE_CLIENT_ID" and
//
// 1. client Credentials: attempt to authenticate with a Service Principal via "AZURE_TENANT_ID", "AZURE_CLIENT_ID" and
// "AZURE_CLIENT_SECRET"
//
// 2. client Certificate: attempt to authenticate with a Service Principal via "AZURE_TENANT_ID", "AZURE_CLIENT_ID",
// 2. client Certificate: attempt to authenticate with a Service Principal via "AZURE_TENANT_ID", "AZURE_CLIENT_ID",
// "AZURE_CERTIFICATE_PATH" and "AZURE_CERTIFICATE_PASSWORD"
//
// 3. Managed Service Identity (MSI): attempt to authenticate via MSI
//
// 3. Managed Service Identity (MSI): attempt to authenticate via MSI
//
// The Azure Environment used can be specified using the name of the Azure Environment set in the AZURE_ENVIRONMENT var.
func NewHubFromEnvironment(opts ...HubOption) (*Hub, error) {
Expand All @@ -448,7 +444,7 @@ func NewHubFromEnvironment(opts ...HubOption) (*Hub, error) {
// NewHubFromConnectionString creates a new Event Hub client for sending and receiving messages from a connection string
// formatted like the following:
//
// Endpoint=sb://namespace.servicebus.windows.net/;SharedAccessKeyName=RootManageSharedAccessKey;SharedAccessKey=superSecret1234=;EntityPath=hubName
// Endpoint=sb://namespace.servicebus.windows.net/;SharedAccessKeyName=RootManageSharedAccessKey;SharedAccessKey=superSecret1234=;EntityPath=hubName
func NewHubFromConnectionString(connStr string, opts ...HubOption) (*Hub, error) {
parsed, err := conn.ParsedConnectionFromStr(connStr)
if err != nil {
Expand Down Expand Up @@ -587,9 +583,9 @@ func (h *Hub) closeReceivers(ctx context.Context) error {
// If Receive starts successfully, a *ListenerHandle and a nil error will be returned. The ListenerHandle exposes
// methods which will help manage the life span of the receiver.
//
// ListenerHandle.Close(ctx) closes the receiver
// # ListenerHandle.Close(ctx) closes the receiver
//
// ListenerHandle.Done() signals the consumer when the receiver has stopped
// # ListenerHandle.Done() signals the consumer when the receiver has stopped
//
// ListenerHandle.Err() provides the last error the listener encountered and was unable to recover from
func (h *Hub) Receive(ctx context.Context, partitionID string, handler Handler, opts ...ReceiveOption) (*ListenerHandle, error) {
Expand Down
6 changes: 3 additions & 3 deletions sdk/messaging/azeventhubs/internal/sender.go
Original file line number Diff line number Diff line change
Expand Up @@ -107,9 +107,9 @@ func (s *sender) Recover(ctx context.Context) error {
}

// recoverWithExpectedLinkID attemps to recover the link as cheaply as possible.
// - It does not recover the link if expectedLinkID is not "" and does NOT match
// the current link ID, as this would indicate that the previous bad link has
// already been closed and removed.
// - It does not recover the link if expectedLinkID is not "" and does NOT match
// the current link ID, as this would indicate that the previous bad link has
// already been closed and removed.
func (s *sender) recoverWithExpectedLinkID(ctx context.Context, expectedLinkID string) error {
span, ctx := s.startProducerSpanFromContext(ctx, "eh.sender.Recover")
defer span.End()
Expand Down
9 changes: 4 additions & 5 deletions sdk/messaging/azeventhubs/internal/storage/credential.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,15 +45,14 @@ type (

// AADSASCredentialWithEnvironmentVars configures the TokenProvider using the environment variables available
//
// 1. Client Credentials: attempt to authenticate with a Service Principal via "AZURE_TENANT_ID", "AZURE_CLIENT_ID" and
// "AZURE_CLIENT_SECRET"
// 1. Client Credentials: attempt to authenticate with a Service Principal via "AZURE_TENANT_ID", "AZURE_CLIENT_ID" and
// "AZURE_CLIENT_SECRET"
//
// 2. Client Certificate: attempt to authenticate with a Service Principal via "AZURE_TENANT_ID", "AZURE_CLIENT_ID",
// "AZURE_CERTIFICATE_PATH" and "AZURE_CERTIFICATE_PASSWORD"
// 2. Client Certificate: attempt to authenticate with a Service Principal via "AZURE_TENANT_ID", "AZURE_CLIENT_ID",
// "AZURE_CERTIFICATE_PATH" and "AZURE_CERTIFICATE_PASSWORD"
//
// 3. Managed Service Identity (MSI): attempt to authenticate via MSI
//
//
// The Azure Environment used can be specified using the name of the Azure Environment set in "AZURE_ENVIRONMENT" var.
func AADSASCredentialWithEnvironmentVars() AADSASCredentialOption {
return func(config *aad.TokenProviderConfiguration) error {
Expand Down
Loading

0 comments on commit 1e08e16

Please sign in to comment.