Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: api updates #70

Merged
merged 9 commits into from
Sep 6, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion VERSION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
0.0.9
1.0.0
46 changes: 17 additions & 29 deletions api/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,73 +12,61 @@ type Client interface {
// CreateEnvironment creates the environment.
CreateEnvironment(ctx context.Context, environmentID string, create *EnvironmentMessage) (*EnvironmentMessage, error)
// GetEnvironment gets the environment by id.
GetEnvironment(ctx context.Context, environmentID string) (*EnvironmentMessage, error)
GetEnvironment(ctx context.Context, environmentName string) (*EnvironmentMessage, error)
// ListEnvironment finds all environments.
ListEnvironment(ctx context.Context, showDeleted bool) (*ListEnvironmentMessage, error)
// UpdateEnvironment updates the environment.
UpdateEnvironment(ctx context.Context, environmentID string, patch *EnvironmentPatchMessage) (*EnvironmentMessage, error)
UpdateEnvironment(ctx context.Context, patch *EnvironmentPatchMessage) (*EnvironmentMessage, error)
// DeleteEnvironment deletes the environment.
DeleteEnvironment(ctx context.Context, environmentID string) error
DeleteEnvironment(ctx context.Context, environmentName string) error
// UndeleteEnvironment undeletes the environment.
UndeleteEnvironment(ctx context.Context, environmentID string) (*EnvironmentMessage, error)
UndeleteEnvironment(ctx context.Context, environmentName string) (*EnvironmentMessage, error)

// Instance
// ListInstance will return instances.
ListInstance(ctx context.Context, find *InstanceFindMessage) (*ListInstanceMessage, error)
// GetInstance gets the instance by id.
GetInstance(ctx context.Context, find *InstanceFindMessage) (*InstanceMessage, error)
GetInstance(ctx context.Context, instanceName string) (*InstanceMessage, error)
// CreateInstance creates the instance.
CreateInstance(ctx context.Context, instanceID string, instance *InstanceMessage) (*InstanceMessage, error)
// UpdateInstance updates the instance.
UpdateInstance(ctx context.Context, instanceID string, patch *InstancePatchMessage) (*InstanceMessage, error)
UpdateInstance(ctx context.Context, patch *InstancePatchMessage) (*InstanceMessage, error)
// DeleteInstance deletes the instance.
DeleteInstance(ctx context.Context, instanceID string) error
DeleteInstance(ctx context.Context, instanceName string) error
// UndeleteInstance undeletes the instance.
UndeleteInstance(ctx context.Context, instanceID string) (*InstanceMessage, error)
UndeleteInstance(ctx context.Context, instanceName string) (*InstanceMessage, error)
// SyncInstanceSchema will trigger the schema sync for an instance.
SyncInstanceSchema(ctx context.Context, instanceID string) error

// Role
// CreateRole creates the role in the instance.
CreateRole(ctx context.Context, instanceID string, create *RoleUpsert) (*Role, error)
// GetRole gets the role by instance id and role name.
GetRole(ctx context.Context, instanceID, roleName string) (*Role, error)
// ListRole lists the role in instance.
ListRole(ctx context.Context, instanceID string) ([]*Role, error)
// UpdateRole updates the role in instance.
UpdateRole(ctx context.Context, instanceID, roleName string, patch *RoleUpsert) (*Role, error)
// DeleteRole deletes the role in the instance.
DeleteRole(ctx context.Context, instanceID, roleName string) error
SyncInstanceSchema(ctx context.Context, instanceName string) error

// Policy
// ListPolicies lists policies in a specific resource.
ListPolicies(ctx context.Context, find *PolicyFindMessage) (*ListPolicyMessage, error)
// GetPolicy gets a policy in a specific resource.
GetPolicy(ctx context.Context, find *PolicyFindMessage) (*PolicyMessage, error)
GetPolicy(ctx context.Context, policyName string) (*PolicyMessage, error)
// UpsertPolicy creates or updates the policy.
UpsertPolicy(ctx context.Context, find *PolicyFindMessage, patch *PolicyPatchMessage) (*PolicyMessage, error)
UpsertPolicy(ctx context.Context, patch *PolicyPatchMessage) (*PolicyMessage, error)
// DeletePolicy deletes the policy.
DeletePolicy(ctx context.Context, find *PolicyFindMessage) error
DeletePolicy(ctx context.Context, policyName string) error

// Database
// GetDatabase gets the database by instance resource id and the database name.
GetDatabase(ctx context.Context, find *DatabaseFindMessage) (*DatabaseMessage, error)
GetDatabase(ctx context.Context, databaseName string) (*DatabaseMessage, error)
// ListDatabase list the databases.
ListDatabase(ctx context.Context, find *DatabaseFindMessage) (*ListDatabaseMessage, error)
// UpdateDatabase patches the database.
UpdateDatabase(ctx context.Context, patch *DatabasePatchMessage) (*DatabaseMessage, error)

// Project
// GetProject gets the project by resource id.
GetProject(ctx context.Context, projectID string, showDeleted bool) (*ProjectMessage, error)
GetProject(ctx context.Context, projectName string) (*ProjectMessage, error)
// ListProject list the projects,
ListProject(ctx context.Context, showDeleted bool) (*ListProjectMessage, error)
// CreateProject creates the project.
CreateProject(ctx context.Context, projectID string, project *ProjectMessage) (*ProjectMessage, error)
// UpdateProject updates the project.
UpdateProject(ctx context.Context, projectID string, patch *ProjectPatchMessage) (*ProjectMessage, error)
UpdateProject(ctx context.Context, patch *ProjectPatchMessage) (*ProjectMessage, error)
// DeleteProject deletes the project.
DeleteProject(ctx context.Context, projectID string) error
DeleteProject(ctx context.Context, projectName string) error
// UndeleteProject undeletes the project.
UndeleteProject(ctx context.Context, projectID string) (*ProjectMessage, error)
UndeleteProject(ctx context.Context, projectName string) (*ProjectMessage, error)
}
2 changes: 1 addition & 1 deletion api/data_source.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ const (

// DataSourceMessage is the API message for a data source.
type DataSourceMessage struct {
Title string `json:"title"`
ID string `json:"id"`
Type DataSourceType `json:"type"`
Username string `json:"username"`
Password string `json:"password"`
Expand Down
8 changes: 6 additions & 2 deletions api/database.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,12 @@ type DatabaseFindMessage struct {

// DatabaseMessage is the API message for database.
type DatabaseMessage struct {
Name string `json:"name"`
Project string `json:"project"`
// Format: instances/{unique resource id}/databases/{database name}
Name string `json:"name"`
// Format: projects/{unique resource id}
Project string `json:"project"`
// Format: environments/{unique resource id}
Environment string `json:"environment"`
SchemaVersion string `json:"schemaVersion"`
SyncState State `json:"syncState"`
SuccessfulSyncTime string `json:"successfulSyncTime"`
Expand Down
30 changes: 0 additions & 30 deletions api/database_role.go

This file was deleted.

30 changes: 20 additions & 10 deletions api/environment.go
Original file line number Diff line number Diff line change
@@ -1,15 +1,24 @@
package api

// EnvironmentTier is the protection info for environment.
type EnvironmentTier string

const (
// EnvironmentTierProtected is the PROTECTED tier.
EnvironmentTierProtected EnvironmentTier = "PROTECTED"
// EnvironmentTierUnProtected is the UNPROTECTED tier.
EnvironmentTierUnProtected EnvironmentTier = "UNPROTECTED"
)

// EnvironmentMessage is the API message for an environment.
type EnvironmentMessage struct {
UID string `json:"uid"`

// Domain specific fields
Name string `json:"name"`
Title string `json:"title"`
Order int `json:"order"`
State State `json:"state,omitempty"`
Tier string `json:"tier"`
// Format: environments/{unique resource id}
Name string `json:"name"`
Title string `json:"title"`
Order int `json:"order"`
State State `json:"state,omitempty"`
Tier EnvironmentTier `json:"tier"`
}

// ListEnvironmentMessage is the API message for list environment response.
Expand All @@ -20,7 +29,8 @@ type ListEnvironmentMessage struct {

// EnvironmentPatchMessage is the API message to patch the environment.
type EnvironmentPatchMessage struct {
Title *string `json:"title,omitempty"`
Order *int `json:"order,omitempty"`
Tier *string `json:"tier,omitempty"`
Name string `json:"name"`
Title *string `json:"title,omitempty"`
Order *int `json:"order,omitempty"`
Tier *EnvironmentTier `json:"tier,omitempty"`
}
3 changes: 2 additions & 1 deletion api/instance.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ package api

// InstanceMessage is the API message for an instance.
type InstanceMessage struct {
UID string `json:"uid"`
// Format: instances/{unique resource id}
Name string `json:"name"`
State State `json:"state,omitempty"`
Title string `json:"title"`
Expand All @@ -15,6 +15,7 @@ type InstanceMessage struct {

// InstancePatchMessage is the API message to patch the instance.
type InstancePatchMessage struct {
Name string `json:"name"`
Title *string `json:"title,omitempty"`
ExternalLink *string `json:"externalLink,omitempty"`
DataSources []*DataSourceMessage `json:"dataSources,omitempty"`
Expand Down
27 changes: 6 additions & 21 deletions api/policy.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,6 @@ const (
PolicyTypeDeploymentApproval PolicyType = "DEPLOYMENT_APPROVAL"
// PolicyTypeBackupPlan is the policy type for backup plan policy.
PolicyTypeBackupPlan PolicyType = "BACKUP_PLAN"
// PolicyTypeSQLReview is the policy type for SQL review policy.
PolicyTypeSQLReview PolicyType = "SQL_REVIEW"
// PolicyTypeSensitiveData is the policy type for sensitive data policy.
PolicyTypeSensitiveData PolicyType = "SENSITIVE_DATA"
// PolicyTypeAccessControl is the policy type for access control policy.
Expand Down Expand Up @@ -92,50 +90,37 @@ type AccessControlRule struct {
FullDatabase bool `json:"fullDatabase"`
}

// SQLReviewPolicy is the API message for SQL review policy.
type SQLReviewPolicy struct {
Title string `json:"title"`
Rules []*SQLReviewRule `json:"rules"`
}

// PolicyFindMessage is the API message for finding policies.
type PolicyFindMessage struct {
ProjectID *string
EnvironmentID *string
InstanceID *string
DatabaseName *string
Type *PolicyType
ShowDeleted bool
Parent string
Type *PolicyType
}

// PolicyMessage is the API message for policy.
type PolicyMessage struct {
UID string `json:"uid"`
Name string `json:"name"`
State State `json:"state,omitempty"`
InheritFromParent bool `json:"inheritFromParent"`
Type PolicyType `json:"type"`
Enforce bool `json:"enforce"`

// The policy payload
DeploymentApprovalPolicy *DeploymentApprovalPolicy `json:"deploymentApprovalPolicy"`
BackupPlanPolicy *BackupPlanPolicy `json:"backupPlanPolicy"`
SensitiveDataPolicy *SensitiveDataPolicy `json:"sensitiveDataPolicy"`
AccessControlPolicy *AccessControlPolicy `json:"accessControlPolicy"`
SQLReviewPolicy *SQLReviewPolicy `json:"sqlReviewPolicy"`
}

// PolicyPatchMessage is the API message to patch the policy.
type PolicyPatchMessage struct {
InheritFromParent *bool `json:"inheritFromParent"`
Type PolicyType `json:"type"`
Enforce *bool `json:"enforce"`
Name string `json:"name"`
InheritFromParent *bool `json:"inheritFromParent"`
Enforce *bool `json:"enforce"`

// The policy payload
DeploymentApprovalPolicy *DeploymentApprovalPolicy `json:"deploymentApprovalPolicy"`
BackupPlanPolicy *BackupPlanPolicy `json:"backupPlanPolicy"`
SensitiveDataPolicy *SensitiveDataPolicy `json:"sensitiveDataPolicy"`
AccessControlPolicy *AccessControlPolicy `json:"accessControlPolicy"`
SQLReviewPolicy *SQLReviewPolicy `json:"sqlReviewPolicy"`
}

// ListPolicyMessage is the API message for list policy response.
Expand Down
55 changes: 10 additions & 45 deletions api/project.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,47 +10,14 @@ const (
ProjectWorkflowVCS ProjectWorkflow = "VCS"
)

// ProjectVisibility is the visibility for project.
type ProjectVisibility string

const (
// ProjectVisibilityPublic is the public visibility type for project.
ProjectVisibilityPublic ProjectVisibility = "VISIBILITY_PUBLIC"
// ProjectVisibilityPrivate is the private visibility type for project.
ProjectVisibilityPrivate ProjectVisibility = "VISIBILITY_PRIVATE"
)

// ProjectTenantMode is the tenant mode for project.
type ProjectTenantMode string

const (
// ProjectTenantModeDisabled means the tenant mode for the project is disabled.
ProjectTenantModeDisabled ProjectTenantMode = "TENANT_MODE_DISABLED"
// ProjectTenantModeEnabled means the tenant mode for the project is enabled.
ProjectTenantModeEnabled ProjectTenantMode = "TENANT_MODE_ENABLED"
)

// ProjectSchemaChange is the schema change type for project.
type ProjectSchemaChange string

const (
// ProjectSchemaChangeDDL the DDL schema change type in the project.
ProjectSchemaChangeDDL ProjectSchemaChange = "DDL"
// ProjectSchemaChangeSDL the SDL schema change type in the project.
ProjectSchemaChangeSDL ProjectSchemaChange = "SDL"
)

// ProjectMessage is the API message for project.
type ProjectMessage struct {
Name string `json:"name"`
Title string `json:"title"`
Key string `json:"key"`
Workflow ProjectWorkflow `json:"workflow"`
Visibility ProjectVisibility `json:"visibility"`
TenantMode ProjectTenantMode `json:"tenantMode"`
DBNameTemplate string `json:"dbNameTemplate"`
SchemaChange ProjectSchemaChange `json:"schemaChange"`
State State `json:"state,omitempty"`
// Format: projects/{unique resource id}
Name string `json:"name"`
Title string `json:"title"`
Key string `json:"key"`
Workflow ProjectWorkflow `json:"workflow"`
State State `json:"state,omitempty"`
}

// ListProjectMessage is the API message for list project response.
Expand All @@ -61,10 +28,8 @@ type ListProjectMessage struct {

// ProjectPatchMessage is the API message to patch the project.
type ProjectPatchMessage struct {
Title *string `json:"title,omitempty"`
Key *string `json:"key,omitempty"`
Workflow *ProjectWorkflow `json:"workflow"`
TenantMode *ProjectTenantMode `json:"tenantMode"`
DBNameTemplate *string `json:"dbNameTemplate"`
SchemaChange *ProjectSchemaChange `json:"schemaChange"`
// Format: projects/{unique resource id}
Name string `json:"name"`
Title *string `json:"title,omitempty"`
Key *string `json:"key,omitempty"`
}
Loading
Loading