Skip to content

Commit

Permalink
removed public endpoint on client and use getter (#15838)
Browse files Browse the repository at this point in the history
Co-authored-by: Jason Amos <[email protected]>
  • Loading branch information
jay-most and vindicatesociety authored Oct 19, 2021
1 parent c8505fb commit 81b3493
Show file tree
Hide file tree
Showing 6 changed files with 23 additions and 19 deletions.
4 changes: 2 additions & 2 deletions sdk/data/azcosmos/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,12 +32,12 @@ You can create an Azure Cosmos account using:

#### Authenticate the client

In order to interact with the Azure CosmosDB service you'll need to create an instance of the Cosmos Client class. To make this possible you will need an URL and key of the Azure CosmosDB service.
In order to interact with the Azure CosmosDB service you'll need to create an instance of the Cosmos client class. To make this possible you will need an URL and key of the Azure CosmosDB service.
## Examples
The following section provides several code snippets covering some of the most common CosmosDB SQL API tasks, including:
* [Create Cosmos Client](#create-cosmos-client "Create Cosmos Client")
* [Create Client](#create-cosmos-client "Create Cosmos client")
* [Create Database](#create-database "Create Database")
* [Create Container](#create-container "Create Container")
* [CRUD operation on Items](#crud-operation-on-items "CRUD operation on Items")
Expand Down
26 changes: 15 additions & 11 deletions sdk/data/azcosmos/cosmos_client.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,32 +8,36 @@ import (
"errors"
)

// A CosmosClient is used to interact with the Azure Cosmos DB database service.
type CosmosClient struct {
// Endpoint used to create the client.
Endpoint string
// Cosmos client is used to interact with the Azure Cosmos DB database service.
type Client struct {
endpoint string
connection *cosmosClientConnection
cred *SharedKeyCredential
options *CosmosClientOptions
}

// NewClientWithSharedKey creates a new instance of CosmosClient with the specified values. It uses the default pipeline configuration.
// Endpoint used to create the client.
func (c *Client) Endpoint() string {
return c.endpoint
}

// NewClientWithSharedKey creates a new instance of Cosmos client with the specified values. It uses the default pipeline configuration.
// endpoint - The cosmos service endpoint to use.
// cred - The credential used to authenticate with the cosmos service.
// options - Optional CosmosClient options. Pass nil to accept default values.
func NewClientWithSharedKey(endpoint string, cred *SharedKeyCredential, options *CosmosClientOptions) (*CosmosClient, error) {
// options - Optional Cosmos client options. Pass nil to accept default values.
func NewClientWithSharedKey(endpoint string, cred *SharedKeyCredential, options *CosmosClientOptions) (*Client, error) {
if options == nil {
options = &CosmosClientOptions{}
}

connection := newCosmosClientConnection(endpoint, cred, options)

return &CosmosClient{Endpoint: endpoint, connection: connection, cred: cred, options: options}, nil
return &Client{endpoint: endpoint, connection: connection, cred: cred, options: options}, nil
}

// GetDatabase returns a Database object.
// id - The id of the database.
func (c *CosmosClient) GetDatabase(id string) (*Database, error) {
func (c *Client) GetDatabase(id string) (*Database, error) {
if id == "" {
return nil, errors.New("id is required")
}
Expand All @@ -44,7 +48,7 @@ func (c *CosmosClient) GetDatabase(id string) (*Database, error) {
// GetContainer returns a Container object.
// databaseId - The id of the database.
// containerId - The id of the container.
func (c *CosmosClient) GetContainer(databaseId string, containerId string) (*Container, error) {
func (c *Client) GetContainer(databaseId string, containerId string) (*Container, error) {
if databaseId == "" {
return nil, errors.New("databaseId is required")
}
Expand All @@ -60,7 +64,7 @@ func (c *CosmosClient) GetContainer(databaseId string, containerId string) (*Con
// ctx - The context for the request.
// databaseProperties - The definition of the database
// o - Options for the create database operation.
func (c *CosmosClient) CreateDatabase(
func (c *Client) CreateDatabase(
ctx context.Context,
databaseProperties DatabaseProperties,
o *CreateDatabaseOptions) (DatabaseResponse, error) {
Expand Down
2 changes: 1 addition & 1 deletion sdk/data/azcosmos/cosmos_client_options.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ type CosmosClientOptions struct {
// When EnableContentResponseOnWrite is false will cause the response to have a null resource. This reduces networking and CPU load by not sending the resource back over the network and serializing it on the client.
// The default is false.
EnableContentResponseOnWrite bool
// LimitToEndpoint limits the operations to the provided endpoint on the CosmosClient. See https://docs.microsoft.com/azure/cosmos-db/troubleshoot-sdk-availability
// LimitToEndpoint limits the operations to the provided endpoint on the Cosmos client. See https://docs.microsoft.com/azure/cosmos-db/troubleshoot-sdk-availability
LimitToEndpoint bool
// RateLimitedRetry defines the retry configuration for rate limited requests.
// By default, the SDK will do 9 retries.
Expand Down
4 changes: 2 additions & 2 deletions sdk/data/azcosmos/cosmos_database.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,12 @@ type Database struct {
// The Id of the Cosmos database
Id string
// The client associated with the Cosmos database
client *CosmosClient
client *Client
// The resource link
link string
}

func newDatabase(id string, client *CosmosClient) *Database {
func newDatabase(id string, client *Client) *Database {
return &Database{
Id: id,
client: client,
Expand Down
4 changes: 2 additions & 2 deletions sdk/data/azcosmos/emulator_tests.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ func newEmulatorTests(t *testing.T) *emulatorTests {
}
}

func (e *emulatorTests) getClient(t *testing.T) *CosmosClient {
func (e *emulatorTests) getClient(t *testing.T) *Client {
cred, _ := NewSharedKeyCredential(e.key)
client, err := NewClientWithSharedKey(e.host, cred, nil)
if err != nil {
Expand All @@ -39,7 +39,7 @@ func (e *emulatorTests) getClient(t *testing.T) *CosmosClient {
func (e *emulatorTests) createDatabase(
t *testing.T,
ctx context.Context,
client *CosmosClient,
client *Client,
dbName string) *Database {
database := DatabaseProperties{Id: dbName}
resp, err := client.CreateDatabase(ctx, database, nil)
Expand Down
2 changes: 1 addition & 1 deletion sdk/data/azcosmos/example_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import (
"github.com/Azure/azure-sdk-for-go/sdk/data/azcosmos"
)

// This example shows you how to get started using the Azure Cosmos DB SDK for Go. NewCosmosClient creates a new instance of CosmosClient with the specified values. It uses the default pipeline configuration.
// This example shows you how to get started using the Azure Cosmos DB SDK for Go. NewCosmosClient creates a new instance of Cosmos client with the specified values. It uses the default pipeline configuration.
func Example() {

endpoint, _ := os.LookupEnv("SOME_ENDPOINT")
Expand Down

0 comments on commit 81b3493

Please sign in to comment.