Skip to content
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -270,3 +270,4 @@ $RECYCLE.BIN/
# End of https://www.gitignore.io/api/vim,linux,macos,emacs,windows,terraform,intellij+all,visualstudiocode

bin/
vendor
8 changes: 7 additions & 1 deletion client.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import (
"github.com/RedisLabs/rediscloud-go-api/service/account"
"github.com/RedisLabs/rediscloud-go-api/service/cloud_accounts"
"github.com/RedisLabs/rediscloud-go-api/service/databases"
"github.com/RedisLabs/rediscloud-go-api/service/regions"
"github.com/RedisLabs/rediscloud-go-api/service/subscriptions"
)

Expand All @@ -22,6 +23,7 @@ type Client struct {
CloudAccount *cloud_accounts.API
Database *databases.API
Subscription *subscriptions.API
Regions *regions.API
}

func NewClient(configs ...Option) (*Client, error) {
Expand Down Expand Up @@ -53,12 +55,14 @@ func NewClient(configs ...Option) (*Client, error) {
c := cloud_accounts.NewAPI(client, t, config.logger)
d := databases.NewAPI(client, t, config.logger)
s := subscriptions.NewAPI(client, t, config.logger)
r := regions.NewAPI(client, t, config.logger)

return &Client{
Account: a,
CloudAccount: c,
Database: d,
Subscription: s,
Regions: r,
}, nil
}

Expand Down Expand Up @@ -207,7 +211,9 @@ func prettyPrint(data []byte) string {
// redactPasswords: Redacts password values from a JSON message.
func redactPasswords(data string) string {
m1 := regexp.MustCompile(`\"password\"\s*:\s*\"(?:[^"\\]|\\.)*\"`)
return m1.ReplaceAllString(data, "\"password\": \"REDACTED\"")
output := m1.ReplaceAllString(data, "\"password\": \"REDACTED\"")
m2 := regexp.MustCompile(`\"global_password\"\s*:\s*\"(?:[^"\\]|\\.)*\"`)
return m2.ReplaceAllString(output, "\"global_password\": \"REDACTED\"")
}

func escapePath(path string) string {
Expand Down
11 changes: 6 additions & 5 deletions client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -252,8 +252,8 @@ func TestCredentialTripper_RedactPasswordFromNestedBody(t *testing.T) {
ProtoMajor: 1,
ProtoMinor: 1,
Header: map[string][]string{},
Body: ioutil.NopCloser(bytes.NewBufferString(`{"security": {"password":"pass"}}`)),
ContentLength: 33,
Body: ioutil.NopCloser(bytes.NewBufferString(`{"security": {"password":"pass", "global_password":"globalpass"}}`)),
ContentLength: 65,
Host: "example.org",
}
expected := &http.Response{
Expand All @@ -262,7 +262,7 @@ func TestCredentialTripper_RedactPasswordFromNestedBody(t *testing.T) {
ProtoMajor: 1,
ProtoMinor: 1,
Header: map[string][]string{},
Body: ioutil.NopCloser(bytes.NewBufferString(`{"security": {"password":"REDACTED"}}`)),
Body: ioutil.NopCloser(bytes.NewBufferString(`{"security": {"password":"REDACTED", "global_password":"REDACTED"}}`)),
}

mockTripper.On("RoundTrip", request).Return(expected, nil)
Expand All @@ -285,13 +285,14 @@ func TestCredentialTripper_RedactPasswordFromNestedBody(t *testing.T) {
POST /foo/bar HTTP/1.1
Host: example.org
User-Agent: test-user-agent
Content-Length: 33
Content-Length: 65
Accept: application/json
Accept-Encoding: gzip

{
"security": {
"password": "REDACTED"
"password": "REDACTED",
"global_password": "REDACTED"
}
}`, mockLogger.log[0])
}
Expand Down
4 changes: 4 additions & 0 deletions internal/http_client.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,10 @@ func (c *HttpClient) Delete(ctx context.Context, name, path string, responseBody
return c.connection(ctx, http.MethodDelete, name, path, nil, nil, responseBody)
}

func (c *HttpClient) DeleteWithQuery(ctx context.Context, name, path string, requestBody interface{}, responseBody interface{}) error {
return c.connection(ctx, http.MethodDelete, name, path, nil, requestBody, responseBody)
}

func (c *HttpClient) connection(ctx context.Context, method, name, path string, query url.Values, requestBody interface{}, responseBody interface{}) error {
parsed := new(url.URL)
*parsed = *c.baseUrl
Expand Down
1 change: 1 addition & 0 deletions service/databases/model.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ func (o CreateModule) String() string {
return internal.ToString(o)
}

// TODO: do we need a separate ActiveActiveDatabase type as well?
type Database struct {
ID *int `json:"databaseId,omitempty"`
Name *string `json:"name,omitempty"`
Expand Down
149 changes: 149 additions & 0 deletions service/databases/model_active_active.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,149 @@
package databases

import (
"time"

"github.com/RedisLabs/rediscloud-go-api/internal"
)

type ActiveActiveDatabase struct {
ID *int `json:"databaseId,omitempty"`
Name *string `json:"name,omitempty"`
Protocol *string `json:"protocol,omitempty"`
Status *string `json:"status,omitempty"`
MemoryStorage *string `json:"memoryStorage,omitempty"`
ActiveActiveRedis *bool `json:"activeActiveRedis,omitempty"`
ActivatedOn *time.Time `json:"activatedOn,omitempty"`
LastModified *time.Time `json:"lastModified,omitempty"`
SupportOSSClusterAPI *bool `json:"supportOSSClusterApi,omitempty"`
UseExternalEndpointForOSSClusterAPI *bool `json:"useExternalEndpointForOSSClusterApi,omitempty"`
Replication *bool `json:"replication,omitempty"`
DataEvictionPolicy *string `json:"dataEvictionPolicy,omitempty"`
CrdbDatabases []*CrdbDatabase `json:"crdbDatabases,omitempty"`
}

func (o ActiveActiveDatabase) String() string {
return internal.ToString(o)
}

type CrdbDatabase struct {
Provider *string `json:"provider,omitempty"`
Region *string `json:"region,omitempty"`
RedisVersionCompliance *string `json:"redisVersionCompliance,omitempty"`
PublicEndpoint *string `json:"publicEndpoint,omitempty"`
PrivateEndpoint *string `json:"privateEndpoint,omitempty"`
MemoryLimitInGB *float64 `json:"memoryLimitInGb,omitempty"`
MemoryUsedInMB *float64 `json:"memoryUsedInMb,omitempty"`
ReadOperationsPerSecond *int `json:"readOperationsPerSecond,omitempty"`
WriteOperationsPerSecond *int `json:"writeOperationsPerSecond,omitempty"`
DataPersistence *string `json:"dataPersistence,omitempty"`
Alerts []*Alert `json:"alerts,omitempty"`
Security *Security `json:"security,omitempty"`
Backup *Backup `json:"backup,omitempty"`
}

func (o CrdbDatabase) String() string {
return internal.ToString(o)
}

type Backup struct {
Enabled *bool `json:"enableRemoteBackup,omitempty"`
Interval *string `json:"interval,omitempty"`
Destination *string `json:"destination,omitempty"`
}

func (o Backup) String() string {
return internal.ToString(o)
}

type CreateActiveActiveDatabase struct {
DryRun *bool `json:"dryRun,omitempty"`
Name *string `json:"name,omitempty"`
Protocol *string `json:"protocol,omitempty"`
MemoryLimitInGB *float64 `json:"memoryLimitInGb,omitempty"`
SupportOSSClusterAPI *bool `json:"supportOSSClusterApi,omitempty"`
UseExternalEndpointForOSSClusterAPI *bool `json:"useExternalEndpointForOSSClusterApi,omitempty"`
DataEvictionPolicy *string `json:"dataEvictionPolicy,omitempty"`
GlobalDataPersistence *string `json:"dataPersistence,omitempty"`
GlobalSourceIP []*string `json:"sourceIp,omitempty"`
GlobalPassword *string `json:"password,omitempty"`
GlobalAlerts []*CreateAlert `json:"alerts,omitempty"`
LocalThroughputMeasurement []*LocalThroughput `json:"localThroughputMeasurement,omitempty"`
}

func (o CreateActiveActiveDatabase) String() string {
return internal.ToString(o)
}

type LocalThroughput struct {
Region *string `json:"region,omitempty"`
WriteOperationsPerSecond *int `json:"writeOperationsPerSecond,omitempty"`
ReadOperationsPerSecond *int `json:"readOperationsPerSecond,omitempty"`
}

func (o LocalThroughput) String() string {
return internal.ToString(o)
}

type UpdateActiveActiveDatabase struct {
DryRun *bool `json:"dryRun,omitempty"`
MemoryLimitInGB *float64 `json:"memoryLimitInGb,omitempty"`
SupportOSSClusterAPI *bool `json:"supportOSSClusterApi,omitempty"`
UseExternalEndpointForOSSClusterAPI *bool `json:"useExternalEndpointForOSSClusterApi,omitempty"`
ClientSSLCertificate *string `json:"clientSslCertificate,omitempty"`
EnableTls *bool `json:"enableTls,omitempty"`
GlobalDataPersistence *string `json:"globalDataPersistence,omitempty"`
GlobalPassword *string `json:"globalPassword,omitempty"`
GlobalSourceIP []*string `json:"globalSourceIp,omitempty"`
GlobalAlerts []*UpdateAlert `json:"globalAlerts,omitempty"`
Regions []*LocalRegionProperties `json:"regions,omitempty"`
DataEvictionPolicy *string `json:"dataEvictionPolicy,omitempty"`
}

func (o UpdateActiveActiveDatabase) String() string {
return internal.ToString(o)
}

type LocalRegionProperties struct {
Region *string `json:"region,omitempty"`
RemoteBackup *DatabaseBackupConfig `json:"remoteBackup,omitempty"`
LocalThroughputMeasurement *LocalThroughput `json:"localThroughputMeasurement,omitempty"`
DataPersistence *string `json:"dataPersistence,omitempty"`
Password *string `json:"password,omitempty"`
SourceIP []*string `json:"sourceIp,omitempty"`
Alerts []*UpdateAlert `json:"alerts,omitempty"`
}

func (o LocalRegionProperties) String() string {
return internal.ToString(o)
}

type DatabaseBackupConfig struct {
Active *bool `json:"active,omitempty"`
Interval *string `json:"interval,omitempty"`
TimeUTC *string `json:"timeUTC,omitempty"`
StorageType *string `json:"storageType,omitempty"`
StoragePath *string `json:"storagePath,omitempty"`
}

func (o DatabaseBackupConfig) String() string {
return internal.ToString(o)
}

type listActiveActiveDatabaseResponse struct {
AccountId *string `json:"accountId,omitempty"`
Subscription []*listActiveActiveDbSubscription `json:"subscription,omitempty"`
}

func (o listActiveActiveDatabaseResponse) String() string {
return internal.ToString(o)
}

type listActiveActiveDbSubscription struct {
ID *int `json:"subscriptionId,omitempty"`
Databases []*ActiveActiveDatabase `json:"databases,omitempty"`
}

func (o listActiveActiveDbSubscription) String() string {
return internal.ToString(o)
}
Loading