Skip to content

Commit

Permalink
Merge branch 'main' into zhiwei/obj-gen2
Browse files Browse the repository at this point in the history
  • Loading branch information
zliang-akamai authored Jan 8, 2025
2 parents dd21c72 + 9633762 commit 55beb8e
Show file tree
Hide file tree
Showing 13 changed files with 3,799 additions and 52,826 deletions.
125 changes: 102 additions & 23 deletions databases.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ type (
DatabaseDayOfWeek int
DatabaseMaintenanceFrequency string
DatabaseStatus string
DatabasePlatform string
DatabaseMemberType string
)

const (
Expand Down Expand Up @@ -50,24 +52,45 @@ const (
DatabaseStatusBackingUp DatabaseStatus = "backing_up"
)

const (
DatabasePlatformRDBMSLegacy DatabasePlatform = "rdbms-legacy"
DatabasePlatformRDBMSDefault DatabasePlatform = "rdbms-default"
)

const (
DatabaseMemberTypePrimary DatabaseMemberType = "primary"
DatabaseMemberTypeFailover DatabaseMemberType = "failover"
)

// A Database is a instance of Linode Managed Databases
type Database struct {
ID int `json:"id"`
Status DatabaseStatus `json:"status"`
Label string `json:"label"`
Hosts DatabaseHost `json:"hosts"`
Region string `json:"region"`
Type string `json:"type"`
Engine string `json:"engine"`
Version string `json:"version"`
ClusterSize int `json:"cluster_size"`
ReplicationType string `json:"replication_type"`
SSLConnection bool `json:"ssl_connection"`
Encrypted bool `json:"encrypted"`
AllowList []string `json:"allow_list"`
InstanceURI string `json:"instance_uri"`
Created *time.Time `json:"-"`
Updated *time.Time `json:"-"`
ID int `json:"id"`
Status DatabaseStatus `json:"status"`
Label string `json:"label"`
Hosts DatabaseHost `json:"hosts"`
Region string `json:"region"`
Type string `json:"type"`
Engine string `json:"engine"`
Version string `json:"version"`
ClusterSize int `json:"cluster_size"`
Platform DatabasePlatform `json:"platform"`
Fork *DatabaseFork `json:"fork"`

// Members has dynamic keys so it is a map
Members map[string]DatabaseMemberType `json:"members"`

// Deprecated: ReplicationType is a deprecated property, as it is no longer supported in DBaaS V2.
ReplicationType string `json:"replication_type"`
// Deprecated: SSLConnection is a deprecated property, as it is no longer supported in DBaaS V2.
SSLConnection bool `json:"ssl_connection"`
// Deprecated: Encrypted is a deprecated property, as it is no longer supported in DBaaS V2.
Encrypted bool `json:"encrypted"`

AllowList []string `json:"allow_list"`
InstanceURI string `json:"instance_uri"`
Created *time.Time `json:"-"`
Updated *time.Time `json:"-"`
OldestRestoreTime *time.Time `json:"-"`
}

// DatabaseHost for Primary/Secondary of Database
Expand All @@ -85,11 +108,21 @@ type DatabaseEngine struct {

// DatabaseMaintenanceWindow stores information about a MySQL cluster's maintenance window
type DatabaseMaintenanceWindow struct {
DayOfWeek DatabaseDayOfWeek `json:"day_of_week"`
Duration int `json:"duration"`
Frequency DatabaseMaintenanceFrequency `json:"frequency"`
HourOfDay int `json:"hour_of_day"`
WeekOfMonth *int `json:"week_of_month"`
DayOfWeek DatabaseDayOfWeek `json:"day_of_week"`
Duration int `json:"duration"`
Frequency DatabaseMaintenanceFrequency `json:"frequency"`
HourOfDay int `json:"hour_of_day"`

Pending []DatabaseMaintenanceWindowPending `json:"pending,omitempty"`

// Deprecated: WeekOfMonth is a deprecated property, as it is no longer supported in DBaaS V2.
WeekOfMonth *int `json:"week_of_month,omitempty"`
}

type DatabaseMaintenanceWindowPending struct {
Deadline *time.Time `json:"-"`
Description string `json:"description"`
PlannedFor *time.Time `json:"-"`
}

// DatabaseType is information about the supported Database Types by Linode Managed Databases
Expand Down Expand Up @@ -120,13 +153,20 @@ type ClusterPrice struct {
Monthly float32 `json:"monthly"`
}

// DatabaseFork describes the source and restore time for the fork for forked DBs
type DatabaseFork struct {
Source int `json:"source"`
RestoreTime *time.Time `json:"-,omitempty"`
}

func (d *Database) UnmarshalJSON(b []byte) error {
type Mask Database

p := struct {
*Mask
Created *parseabletime.ParseableTime `json:"created"`
Updated *parseabletime.ParseableTime `json:"updated"`
Created *parseabletime.ParseableTime `json:"created"`
Updated *parseabletime.ParseableTime `json:"updated"`
OldestRestoreTime *parseabletime.ParseableTime `json:"oldest_restore_time"`
}{
Mask: (*Mask)(d),
}
Expand All @@ -137,6 +177,45 @@ func (d *Database) UnmarshalJSON(b []byte) error {

d.Created = (*time.Time)(p.Created)
d.Updated = (*time.Time)(p.Updated)
d.OldestRestoreTime = (*time.Time)(p.OldestRestoreTime)
return nil
}

func (d *DatabaseFork) UnmarshalJSON(b []byte) error {
type Mask DatabaseFork

p := struct {
*Mask
RestoreTime *parseabletime.ParseableTime `json:"restore_time"`
}{
Mask: (*Mask)(d),
}

if err := json.Unmarshal(b, &p); err != nil {
return err
}

d.RestoreTime = (*time.Time)(p.RestoreTime)
return nil
}

func (d *DatabaseMaintenanceWindowPending) UnmarshalJSON(b []byte) error {
type Mask DatabaseMaintenanceWindowPending

p := struct {
*Mask
Deadline *parseabletime.ParseableTime `json:"deadline"`
PlannedFor *parseabletime.ParseableTime `json:"planned_for"`
}{
Mask: (*Mask)(d),
}

if err := json.Unmarshal(b, &p); err != nil {
return err
}

d.Deadline = (*time.Time)(p.Deadline)
d.PlannedFor = (*time.Time)(p.PlannedFor)
return nil
}

Expand Down
1 change: 1 addition & 0 deletions go.work.sum
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ golang.org/x/crypto v0.28.0/go.mod h1:rmgy+3RHxRZMyY0jjAJShp2zgEdOqj2AO7U0pYmeQ7
golang.org/x/crypto v0.29.0/go.mod h1:+F4F4N5hv6v38hfeYwTdx20oUvLLc+QfrE9Ax9HtgRg=
golang.org/x/crypto v0.30.0 h1:RwoQn3GkWiMkzlX562cLB7OxWvjH1L8xutO2WoJcRoY=
golang.org/x/crypto v0.30.0/go.mod h1:kDsLvtWBEx7MV9tJOj9bnXsPbxwJQ6csT/x4KIN4Ssk=
golang.org/x/crypto v0.31.0 h1:ihbySMvVjLAeSH1IbfcRTkD/iNscyz8rGzjF/E5hV6U=
golang.org/x/crypto v0.31.0/go.mod h1:kDsLvtWBEx7MV9tJOj9bnXsPbxwJQ6csT/x4KIN4Ssk=
golang.org/x/mod v0.17.0 h1:zY54UmvipHiNd+pm+m0x9KhZ9hl1/7QNMyxXbc6ICqA=
golang.org/x/mod v0.17.0/go.mod h1:hTbmBsO62+eylJbnUtE2MGJUyE7QWk4xUqPFrRgJ+7c=
Expand Down
96 changes: 65 additions & 31 deletions mysql.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,32 +19,44 @@ const (

// A MySQLDatabase is an instance of Linode MySQL Managed Databases
type MySQLDatabase struct {
ID int `json:"id"`
Status DatabaseStatus `json:"status"`
Label string `json:"label"`
Hosts DatabaseHost `json:"hosts"`
Region string `json:"region"`
Type string `json:"type"`
Engine string `json:"engine"`
Version string `json:"version"`
ClusterSize int `json:"cluster_size"`
ReplicationType string `json:"replication_type"`
SSLConnection bool `json:"ssl_connection"`
Encrypted bool `json:"encrypted"`
AllowList []string `json:"allow_list"`
InstanceURI string `json:"instance_uri"`
Created *time.Time `json:"-"`
Updated *time.Time `json:"-"`
Updates DatabaseMaintenanceWindow `json:"updates"`
ID int `json:"id"`
Status DatabaseStatus `json:"status"`
Label string `json:"label"`
Hosts DatabaseHost `json:"hosts"`
Region string `json:"region"`
Type string `json:"type"`
Engine string `json:"engine"`
Version string `json:"version"`
ClusterSize int `json:"cluster_size"`
Platform DatabasePlatform `json:"platform"`

// Members has dynamic keys so it is a map
Members map[string]DatabaseMemberType `json:"members"`

// Deprecated: ReplicationType is a deprecated property, as it is no longer supported in DBaaS V2.
ReplicationType string `json:"replication_type"`
// Deprecated: SSLConnection is a deprecated property, as it is no longer supported in DBaaS V2.
SSLConnection bool `json:"ssl_connection"`
// Deprecated: Encrypted is a deprecated property, as it is no longer supported in DBaaS V2.
Encrypted bool `json:"encrypted"`

AllowList []string `json:"allow_list"`
InstanceURI string `json:"instance_uri"`
Created *time.Time `json:"-"`
Updated *time.Time `json:"-"`
Updates DatabaseMaintenanceWindow `json:"updates"`
Fork *DatabaseFork `json:"fork"`
OldestRestoreTime *time.Time `json:"-"`
}

func (d *MySQLDatabase) UnmarshalJSON(b []byte) error {
type Mask MySQLDatabase

p := struct {
*Mask
Created *parseabletime.ParseableTime `json:"created"`
Updated *parseabletime.ParseableTime `json:"updated"`
Created *parseabletime.ParseableTime `json:"created"`
Updated *parseabletime.ParseableTime `json:"updated"`
OldestRestoreTime *parseabletime.ParseableTime `json:"oldest_restore_time"`
}{
Mask: (*Mask)(d),
}
Expand All @@ -55,30 +67,42 @@ func (d *MySQLDatabase) UnmarshalJSON(b []byte) error {

d.Created = (*time.Time)(p.Created)
d.Updated = (*time.Time)(p.Updated)
d.OldestRestoreTime = (*time.Time)(p.OldestRestoreTime)
return nil
}

// MySQLCreateOptions fields are used when creating a new MySQL Database
type MySQLCreateOptions struct {
Label string `json:"label"`
Region string `json:"region"`
Type string `json:"type"`
Engine string `json:"engine"`
AllowList []string `json:"allow_list,omitempty"`
ReplicationType string `json:"replication_type,omitempty"`
ClusterSize int `json:"cluster_size,omitempty"`
Encrypted bool `json:"encrypted,omitempty"`
SSLConnection bool `json:"ssl_connection,omitempty"`
Label string `json:"label"`
Region string `json:"region"`
Type string `json:"type"`
Engine string `json:"engine"`
AllowList []string `json:"allow_list,omitempty"`
ClusterSize int `json:"cluster_size,omitempty"`

// Deprecated: ReplicationType is a deprecated property, as it is no longer supported in DBaaS V2.
ReplicationType string `json:"replication_type,omitempty"`
// Deprecated: Encrypted is a deprecated property, as it is no longer supported in DBaaS V2.
Encrypted bool `json:"encrypted,omitempty"`
// Deprecated: SSLConnection is a deprecated property, as it is no longer supported in DBaaS V2.
SSLConnection bool `json:"ssl_connection,omitempty"`

Fork *DatabaseFork `json:"fork,omitempty"`
}

// MySQLUpdateOptions fields are used when altering the existing MySQL Database
type MySQLUpdateOptions struct {
Label string `json:"label,omitempty"`
AllowList *[]string `json:"allow_list,omitempty"`
Updates *DatabaseMaintenanceWindow `json:"updates,omitempty"`
Label string `json:"label,omitempty"`
AllowList *[]string `json:"allow_list,omitempty"`
Updates *DatabaseMaintenanceWindow `json:"updates,omitempty"`
Type string `json:"type,omitempty"`
ClusterSize int `json:"cluster_size,omitempty"`
Version string `json:"version,omitempty"`
}

// MySQLDatabaseBackup is information for interacting with a backup for the existing MySQL Database
// Deprecated: MySQLDatabaseBackup is a deprecated struct, as the backup endpoints are no longer supported in DBaaS V2.
// In DBaaS V2, databases can be backed up via database forking.
type MySQLDatabaseBackup struct {
ID int `json:"id"`
Label string `json:"label"`
Expand All @@ -87,6 +111,8 @@ type MySQLDatabaseBackup struct {
}

// MySQLBackupCreateOptions are options used for CreateMySQLDatabaseBackup(...)
// Deprecated: MySQLBackupCreateOptions is a deprecated struct, as the backup endpoints are no longer supported in DBaaS V2.
// In DBaaS V2, databases can be backed up via database forking.
type MySQLBackupCreateOptions struct {
Label string `json:"label"`
Target MySQLDatabaseTarget `json:"target"`
Expand Down Expand Up @@ -132,6 +158,8 @@ func (c *Client) ListMySQLDatabases(ctx context.Context, opts *ListOptions) ([]M
}

// ListMySQLDatabaseBackups lists all MySQL Database Backups associated with the given MySQL Database
// Deprecated: ListMySQLDatabaseBackups is a deprecated method, as the backup endpoints are no longer supported in DBaaS V2.
// In DBaaS V2, databases can be backed up via database forking.
func (c *Client) ListMySQLDatabaseBackups(ctx context.Context, databaseID int, opts *ListOptions) ([]MySQLDatabaseBackup, error) {
response, err := getPaginatedResults[MySQLDatabaseBackup](ctx, c, formatAPIPath("databases/mysql/instances/%d/backups", databaseID), opts)
if err != nil {
Expand Down Expand Up @@ -211,6 +239,8 @@ func (c *Client) ResetMySQLDatabaseCredentials(ctx context.Context, databaseID i
}

// GetMySQLDatabaseBackup returns a specific MySQL Database Backup with the given ids
// Deprecated: GetMySQLDatabaseBackup is a deprecated method, as the backup endpoints are no longer supported in DBaaS V2.
// In DBaaS V2, databases can be backed up via database forking.
func (c *Client) GetMySQLDatabaseBackup(ctx context.Context, databaseID int, backupID int) (*MySQLDatabaseBackup, error) {
e := formatAPIPath("databases/mysql/instances/%d/backups/%d", databaseID, backupID)
response, err := doGETRequest[MySQLDatabaseBackup](ctx, c, e)
Expand All @@ -222,13 +252,17 @@ func (c *Client) GetMySQLDatabaseBackup(ctx context.Context, databaseID int, bac
}

// RestoreMySQLDatabaseBackup returns the given MySQL Database with the given Backup
// Deprecated: RestoreMySQLDatabaseBackup is a deprecated method, as the backup endpoints are no longer supported in DBaaS V2.
// In DBaaS V2, databases can be backed up via database forking.
func (c *Client) RestoreMySQLDatabaseBackup(ctx context.Context, databaseID int, backupID int) error {
e := formatAPIPath("databases/mysql/instances/%d/backups/%d/restore", databaseID, backupID)
_, err := doPOSTRequest[MySQLDatabaseBackup, any](ctx, c, e)
return err
}

// CreateMySQLDatabaseBackup creates a snapshot for the given MySQL database
// Deprecated: CreateMySQLDatabaseBackup is a deprecated method, as the backup endpoints are no longer supported in DBaaS V2.
// In DBaaS V2, databases can be backed up via database forking.
func (c *Client) CreateMySQLDatabaseBackup(ctx context.Context, databaseID int, opts MySQLBackupCreateOptions) error {
e := formatAPIPath("databases/mysql/instances/%d/backups", databaseID)
_, err := doPOSTRequest[MySQLDatabaseBackup](ctx, c, e, opts)
Expand Down
Loading

0 comments on commit 55beb8e

Please sign in to comment.