mirror of
https://github.com/coder/coder.git
synced 2025-07-13 21:36:50 +00:00
feat: Add APIs for querying workspaces (#61)
* Add SQL migration * Add query functions for workspaces * Add create routes * Add tests for codersdk * Add workspace parameter route * Add workspace query * Move workspace function * Add querying for workspace history * Fix query * Fix syntax error * Move workspace routes * Fix version * Add CLI tests * Fix syntax error * Remove error * Fix history error * Add new user test * Fix test * Lower target to 70% * Improve comments * Add comment
This commit is contained in:
@ -11,6 +11,29 @@ import (
|
||||
"github.com/google/uuid"
|
||||
)
|
||||
|
||||
type LogLevel string
|
||||
|
||||
const (
|
||||
LogLevelTrace LogLevel = "trace"
|
||||
LogLevelDebug LogLevel = "debug"
|
||||
LogLevelInfo LogLevel = "info"
|
||||
LogLevelWarn LogLevel = "warn"
|
||||
LogLevelError LogLevel = "error"
|
||||
LogLevelFatal LogLevel = "fatal"
|
||||
)
|
||||
|
||||
func (e *LogLevel) Scan(src interface{}) error {
|
||||
switch s := src.(type) {
|
||||
case []byte:
|
||||
*e = LogLevel(s)
|
||||
case string:
|
||||
*e = LogLevel(s)
|
||||
default:
|
||||
return fmt.Errorf("unsupported scan type for LogLevel: %T", src)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
type LoginType string
|
||||
|
||||
const (
|
||||
@ -106,6 +129,27 @@ func (e *UserStatus) Scan(src interface{}) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
type WorkspaceTransition string
|
||||
|
||||
const (
|
||||
WorkspaceTransitionCreate WorkspaceTransition = "create"
|
||||
WorkspaceTransitionStart WorkspaceTransition = "start"
|
||||
WorkspaceTransitionStop WorkspaceTransition = "stop"
|
||||
WorkspaceTransitionDelete WorkspaceTransition = "delete"
|
||||
)
|
||||
|
||||
func (e *WorkspaceTransition) Scan(src interface{}) error {
|
||||
switch s := src.(type) {
|
||||
case []byte:
|
||||
*e = WorkspaceTransition(s)
|
||||
case string:
|
||||
*e = WorkspaceTransition(s)
|
||||
default:
|
||||
return fmt.Errorf("unsupported scan type for WorkspaceTransition: %T", src)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
type APIKey struct {
|
||||
ID string `db:"id" json:"id"`
|
||||
HashedSecret []byte `db:"hashed_secret" json:"hashed_secret"`
|
||||
@ -212,3 +256,55 @@ type User struct {
|
||||
Decomissioned bool `db:"_decomissioned" json:"_decomissioned"`
|
||||
Shell string `db:"shell" json:"shell"`
|
||||
}
|
||||
|
||||
type Workspace struct {
|
||||
ID uuid.UUID `db:"id" json:"id"`
|
||||
CreatedAt time.Time `db:"created_at" json:"created_at"`
|
||||
UpdatedAt time.Time `db:"updated_at" json:"updated_at"`
|
||||
OwnerID string `db:"owner_id" json:"owner_id"`
|
||||
ProjectID uuid.UUID `db:"project_id" json:"project_id"`
|
||||
Name string `db:"name" json:"name"`
|
||||
}
|
||||
|
||||
type WorkspaceAgent struct {
|
||||
ID uuid.UUID `db:"id" json:"id"`
|
||||
WorkspaceResourceID uuid.UUID `db:"workspace_resource_id" json:"workspace_resource_id"`
|
||||
CreatedAt time.Time `db:"created_at" json:"created_at"`
|
||||
UpdatedAt time.Time `db:"updated_at" json:"updated_at"`
|
||||
InstanceMetadata json.RawMessage `db:"instance_metadata" json:"instance_metadata"`
|
||||
ResourceMetadata json.RawMessage `db:"resource_metadata" json:"resource_metadata"`
|
||||
}
|
||||
|
||||
type WorkspaceHistory struct {
|
||||
ID uuid.UUID `db:"id" json:"id"`
|
||||
CreatedAt time.Time `db:"created_at" json:"created_at"`
|
||||
UpdatedAt time.Time `db:"updated_at" json:"updated_at"`
|
||||
CompletedAt sql.NullTime `db:"completed_at" json:"completed_at"`
|
||||
WorkspaceID uuid.UUID `db:"workspace_id" json:"workspace_id"`
|
||||
ProjectHistoryID uuid.UUID `db:"project_history_id" json:"project_history_id"`
|
||||
BeforeID uuid.NullUUID `db:"before_id" json:"before_id"`
|
||||
AfterID uuid.NullUUID `db:"after_id" json:"after_id"`
|
||||
Transition WorkspaceTransition `db:"transition" json:"transition"`
|
||||
Initiator string `db:"initiator" json:"initiator"`
|
||||
ProvisionerState []byte `db:"provisioner_state" json:"provisioner_state"`
|
||||
ProvisionJobID uuid.UUID `db:"provision_job_id" json:"provision_job_id"`
|
||||
}
|
||||
|
||||
type WorkspaceLog struct {
|
||||
WorkspaceID uuid.UUID `db:"workspace_id" json:"workspace_id"`
|
||||
WorkspaceHistoryID uuid.UUID `db:"workspace_history_id" json:"workspace_history_id"`
|
||||
Created time.Time `db:"created" json:"created"`
|
||||
LoggedBy sql.NullString `db:"logged_by" json:"logged_by"`
|
||||
Level LogLevel `db:"level" json:"level"`
|
||||
Log json.RawMessage `db:"log" json:"log"`
|
||||
}
|
||||
|
||||
type WorkspaceResource struct {
|
||||
ID uuid.UUID `db:"id" json:"id"`
|
||||
CreatedAt time.Time `db:"created_at" json:"created_at"`
|
||||
WorkspaceHistoryID uuid.UUID `db:"workspace_history_id" json:"workspace_history_id"`
|
||||
Type string `db:"type" json:"type"`
|
||||
Name string `db:"name" json:"name"`
|
||||
WorkspaceAgentToken string `db:"workspace_agent_token" json:"workspace_agent_token"`
|
||||
WorkspaceAgentID uuid.NullUUID `db:"workspace_agent_id" json:"workspace_agent_id"`
|
||||
}
|
||||
|
Reference in New Issue
Block a user