Skip to content

Commit

Permalink
Merge branch 'main' into dependabot/go_modules/google.golang.org/prot…
Browse files Browse the repository at this point in the history
…obuf-1.33.0
  • Loading branch information
andrewsomething authored Apr 8, 2024
2 parents 3da575c + c56902f commit 3649a42
Show file tree
Hide file tree
Showing 6 changed files with 660 additions and 161 deletions.
10 changes: 10 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,15 @@
# Change Log

## [v1.111.0] - 2024-04-02

- #674 - @asaha2 - load balancers: introduce glb settings in godo, currently in closed beta

## [v1.110.0] - 2024-03-14

- #667 - @dwilsondo - Include DBaaS metrics credential endpoint operations
- #670 - @guptado - [NETPROD-3583] Added name param in ListOption to get resource by name
- #671 - @greeshmapill - APPS-8383: Add deprecation intent and bandwidth allowance to app instance size spec

## [v1.109.0] - 2024-02-09

- #668 - @greeshmapill - APPS-8315: Update app instance size spec
Expand Down
87 changes: 87 additions & 0 deletions databases.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@ const (
databasePromoteReplicaToPrimaryPath = databaseReplicaPath + "/promote"
databaseTopicPath = databaseBasePath + "/%s/topics/%s"
databaseTopicsPath = databaseBasePath + "/%s/topics"
databaseMetricsCredentialsPath = databaseBasePath + "/metrics/credentials"
databaseEvents = databaseBasePath + "/%s/events"
)

// SQL Mode constants allow for MySQL-specific SQL flavor configuration.
Expand Down Expand Up @@ -154,6 +156,9 @@ type DatabasesService interface {
GetTopic(context.Context, string, string) (*DatabaseTopic, *Response, error)
DeleteTopic(context.Context, string, string) (*Response, error)
UpdateTopic(context.Context, string, string, *DatabaseUpdateTopicRequest) (*Response, error)
GetMetricsCredentials(context.Context) (*DatabaseMetricsCredentials, *Response, error)
UpdateMetricsCredentials(context.Context, *DatabaseUpdateMetricsCredentialsRequest) (*Response, error)
ListDatabaseEvents(context.Context, string) ([]*DatabaseEvent, *Response, error)
}

// DatabasesServiceOp handles communication with the Databases related methods
Expand Down Expand Up @@ -190,6 +195,7 @@ type Database struct {
Tags []string `json:"tags,omitempty"`
ProjectID string `json:"project_id,omitempty"`
StorageSizeMib uint64 `json:"storage_size_mib,omitempty"`
MetricsEndpoints []*ServiceAddress `json:"metrics_endpoints,omitempty"`
}

// DatabaseCA represents a database ca.
Expand All @@ -210,6 +216,12 @@ type DatabaseConnection struct {
ApplicationPorts map[string]uint32 `json:"application_ports,omitempty"`
}

// ServiceAddress represents a host:port for a generic service (e.g. metrics endpoint)
type ServiceAddress struct {
Host string `json:"host"`
Port int `json:"port"`
}

// DatabaseUser represents a user in the database
type DatabaseUser struct {
Name string `json:"name,omitempty"`
Expand Down Expand Up @@ -666,6 +678,19 @@ type databaseTopicsRoot struct {
Topics []DatabaseTopic `json:"topics"`
}

type databaseMetricsCredentialsRoot struct {
Credentials *DatabaseMetricsCredentials `json:"credentials"`
}

type DatabaseMetricsCredentials struct {
BasicAuthUsername string `json:"basic_auth_username"`
BasicAuthPassword string `json:"basic_auth_password"`
}

type DatabaseUpdateMetricsCredentialsRequest struct {
Credentials *DatabaseMetricsCredentials `json:"credentials"`
}

// DatabaseOptions represents the available database engines
type DatabaseOptions struct {
MongoDBOptions DatabaseEngineOptions `json:"mongodb"`
Expand All @@ -688,6 +713,23 @@ type DatabaseLayout struct {
Sizes []string `json:"sizes"`
}

// ListDatabaseEvents contains a list of project events.
type ListDatabaseEvents struct {
Events []*DatabaseEvent `json:"events"`
}

// DatbaseEvent contains the information about a Datbase event.
type DatabaseEvent struct {
ID string `json:"id"`
ServiceName string `json:"cluster_name"`
EventType string `json:"event_type"`
CreateTime string `json:"create_time"`
}

type ListDatabaseEventsRoot struct {
Events []*DatabaseEvent `json:"events"`
}

// URN returns a URN identifier for the database
func (d Database) URN() string {
return ToURN("dbaas", d.ID)
Expand Down Expand Up @@ -1466,3 +1508,48 @@ func (svc *DatabasesServiceOp) DeleteTopic(ctx context.Context, databaseID, name
}
return resp, nil
}

// GetMetricsCredentials gets the credentials required to access a user's metrics endpoints
func (svc *DatabasesServiceOp) GetMetricsCredentials(ctx context.Context) (*DatabaseMetricsCredentials, *Response, error) {
req, err := svc.client.NewRequest(ctx, http.MethodGet, databaseMetricsCredentialsPath, nil)
if err != nil {
return nil, nil, err
}

root := new(databaseMetricsCredentialsRoot)
resp, err := svc.client.Do(ctx, req, root)
if err != nil {
return nil, resp, err
}
return root.Credentials, resp, nil
}

// UpdateMetricsAuth updates the credentials required to access a user's metrics endpoints
func (svc *DatabasesServiceOp) UpdateMetricsCredentials(ctx context.Context, updateCreds *DatabaseUpdateMetricsCredentialsRequest) (*Response, error) {
req, err := svc.client.NewRequest(ctx, http.MethodPut, databaseMetricsCredentialsPath, updateCreds)
if err != nil {
return nil, err
}
resp, err := svc.client.Do(ctx, req, nil)
if err != nil {
return resp, err
}
return resp, nil
}

func (svc *DatabasesServiceOp) ListDatabaseEvents(ctx context.Context, databaseID string) ([]*DatabaseEvent, *Response, error) {
path := fmt.Sprintf(databaseEvents, databaseID)
root := new(ListDatabaseEventsRoot)
req, err := svc.client.NewRequest(ctx, http.MethodGet, path, nil)
if err != nil {
return nil, nil, err
}

resp, err := svc.client.Do(ctx, req, root)
if err != nil {
return nil, resp, err
}

return root.Events, resp, nil

}
105 changes: 104 additions & 1 deletion databases_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,16 @@ var db = Database{
Tags: []string{"production", "staging"},
ProjectID: "6d0f9073-0a24-4f1b-9065-7dc5c8bad3e2",
StorageSizeMib: 61440,
MetricsEndpoints: []*ServiceAddress{
{
Host: "dbtest-do-user-3342561-0.db.ondigitalocean.com",
Port: 9273,
},
{
Host: "replica-dbtest-do-user-3342561-0.db.ondigitalocean.com",
Port: 9273,
},
},
}

var dbJSON = `
Expand Down Expand Up @@ -147,7 +157,17 @@ var dbJSON = `
"private_network_uuid": "da4e0206-d019-41d7-b51f-deadbeefbb8f",
"tags": ["production", "staging"],
"project_id": "6d0f9073-0a24-4f1b-9065-7dc5c8bad3e2",
"storage_size_mib": 61440
"storage_size_mib": 61440,
"metrics_endpoints": [
{
"host": "dbtest-do-user-3342561-0.db.ondigitalocean.com",
"port": 9273
},
{
"host": "replica-dbtest-do-user-3342561-0.db.ondigitalocean.com",
"port": 9273
}
]
}
`

Expand Down Expand Up @@ -3063,3 +3083,86 @@ func TestDatabases_ListTopics(t *testing.T) {
require.NoError(t, err)
require.Equal(t, want, got)
}

func TestDatabases_GetMetricsCredentials(t *testing.T) {
setup()
defer teardown()

want := &DatabaseMetricsCredentials{
BasicAuthUsername: "username_for_http_basic_auth",
BasicAuthPassword: "password_for_http_basic_auth",
}

body := `{
"credentials": {
"basic_auth_username": "username_for_http_basic_auth",
"basic_auth_password": "password_for_http_basic_auth"
}
}`

mux.HandleFunc("/v2/databases/metrics/credentials", func(w http.ResponseWriter, r *http.Request) {
testMethod(t, r, http.MethodGet)
fmt.Fprint(w, body)
})

got, _, err := client.Databases.GetMetricsCredentials(ctx)
require.NoError(t, err)
require.Equal(t, want, got)
}

func TestDatabases_UpdateMetricsCredentials(t *testing.T) {
setup()
defer teardown()

updateRequest := &DatabaseUpdateMetricsCredentialsRequest{
Credentials: &DatabaseMetricsCredentials{
BasicAuthUsername: "username_for_http_basic_auth",
BasicAuthPassword: "password_for_http_basic_auth",
},
}

mux.HandleFunc("/v2/databases/metrics/credentials", func(w http.ResponseWriter, r *http.Request) {
testMethod(t, r, http.MethodPut)
})

_, err := client.Databases.UpdateMetricsCredentials(ctx, updateRequest)
require.NoError(t, err)
}

func TestDatabases_ListDatabaseEvents(t *testing.T) {
setup()
defer teardown()

dbID := "deadbeef-dead-4aa5-beef-deadbeef347d"

path := fmt.Sprintf("/v2/databases/%s/events", dbID)

want := []*DatabaseEvent{
{
ID: "pe8u2huh",
ServiceName: "customer-events",
EventType: "cluster_create",
CreateTime: "2020-10-29T15:57:38Z",
},
}

body := `{
"events": [
{
"id": "pe8u2huh",
"cluster_name": "customer-events",
"event_type": "cluster_create",
"create_time": "2020-10-29T15:57:38Z"
}
]
} `

mux.HandleFunc(path, func(w http.ResponseWriter, r *http.Request) {
testMethod(t, r, http.MethodGet)
fmt.Fprint(w, body)
})

got, _, err := client.Databases.ListDatabaseEvents(ctx, dbID)
require.NoError(t, err)
require.Equal(t, want, got)
}
2 changes: 1 addition & 1 deletion godo.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ import (
)

const (
libraryVersion = "1.109.0"
libraryVersion = "1.111.0"
defaultBaseURL = "https://api.digitalocean.com/"
userAgent = "godo/" + libraryVersion
mediaType = "application/json"
Expand Down
Loading

0 comments on commit 3649a42

Please sign in to comment.