Skip to content
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
11 changes: 9 additions & 2 deletions CLAUDE.md
Original file line number Diff line number Diff line change
Expand Up @@ -83,14 +83,21 @@ the API client and printer.
(falls back to listing + case-insensitive name match when the arg doesn't
look like a UUID). `login.go` accepts `--api-key` plus optional product URLs.
- `cmd/wf.go` — the `eds wf` parent command; just groups `newAppCmd()`,
`newRunCmd()`, `newJobCmd()` as children. Doesn't hold any logic itself.
`newRunCmd()`, `newJobCmd()`, `newSpaceCmd()`, `newDBCmd()`,
`newVariableCmd()` and `newPipelineCmd()` as children. Doesn't hold any
logic itself.
- `cmd/app.go`, `cmd/run.go`, `cmd/job.go` — Workflow Studio subcommand
trees, nested under `eds wf`. `app.go` holds `eds wf app create|list|show|
update|delete|deploy|deployments` (an **application** wires a
repo+branch to a deploy pipeline; a **deployment** runs that pipeline and
publishes it). `app create --repository` reuses `resolveRepoID` from
`repo.go` to accept either a Repo-product UUID or name. `run.go`/`job.go`
are the lower-level primitives behind it.
are the lower-level primitives behind it. `db.go` holds `eds wf db
list|create|show|bind|reset-password|dsn|delete`: managed DBaaS databases
attached to application spaces. "Bind" moves a database to a space
(`--space-id`), and `dsn` returns the connection string containing the
password, so agents must not log it. `space.go`, `variable.go` and
`pipeline.go` are the remaining Workflow Studio subcommand trees.
Note (observed empirically, not documented in the spec): `application.status`
and `application.run.status` are separate lifecycles. Creating an
application auto-triggers its first run; even after `run.status` reaches
Expand Down
36 changes: 36 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,14 @@ eds wf space show <id> show an application space
eds wf space update <id> --name <name> update an application space
eds wf space delete <id> delete an application space

eds wf db list [--space-id S] [--search S] [--sort ...] [--limit N] [--offset N] list databases in a space
eds wf db create <name> [--space-id S] create a managed database (Default space if omitted)
eds wf db show <id> show a database
eds wf db bind <id> --space-id <S> bind (move) a database to another space
eds wf db reset-password <id> reset the database user password
eds wf db dsn <id> get the connection string with its password (secret)
eds wf db delete <id> delete a database, its user and password

eds wf variable list --pipeline-id <id> list variables for a pipeline
eds wf variable create <name> <value> --pipeline-id create a variable
eds wf variable update <name> <value> --pipeline-id update a variable
Expand Down Expand Up @@ -180,6 +188,34 @@ eds wf app show "$APP_ID" --json | jq -r '.run.stages[].jobs[] | select(.status=
app show` — use them directly when you need to inspect or control a
particular run (e.g. `eds wf run stop`) or stream job logs (`eds wf job logs`).

## Managed databases (agent scenario)

An agent can provision and wire up a managed DBaaS database without the UI:
create it, bind it to the space its application lives in, then read the DSN
and pass it to the application as a variable.

```bash
export EDS_API_KEY="..."
export EDS_PROJECT_ID="..."

# 1. Find the space of the service you are wiring the database to.
SPACE_ID=$(eds wf app show "$APP_ID" --json | jq -r '.space_id')

# 2. Create the database (prints its id).
DB_ID=$(eds wf db create orders --space-id "$SPACE_ID" --json | jq -r '.id')

# 3. If the database already existed, bind it to that service's space instead:
eds wf db bind "$DB_ID" --space-id "$SPACE_ID"

# 4. Read the connection string (contains the password — never log it).
DSN=$(eds wf db dsn "$DB_ID" --json | jq -r '.dsn')
```

`eds wf db list`, `show`, `reset-password` and `delete` provide the remaining
operations. The same endpoints are available in the public API under
`/public-api/v1/project/{project_id}/application-db` (tag `databases`); each
CLI command maps to one public API method.

## File upload / push

This CLI does **not** implement a custom upload path. To push code, use
Expand Down
272 changes: 272 additions & 0 deletions cmd/db.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,272 @@
package cmd

import (
"fmt"

workflowclient "github.com/cloud-ru/evolution-devservices-cli/internal/workflow_client"
"github.com/spf13/cobra"
)

type (
dbCreateRequest = workflowclient.GitSbercloudTechDsworksServicesPipelineSrcInternalApplicationRequestApplicationdbCreate
dbBindRequest = workflowclient.GitSbercloudTechDsworksServicesPipelineSrcInternalApplicationRequestApplicationdbUpdate
)

// newDBCmd creates the parent `eds wf db` command. A database belongs to an
// application space: creating, binding (moving) it to a space, and reading its
// DSN are enough for an agent to wire a service to a managed database.
func newDBCmd() *cobra.Command {
cmd := &cobra.Command{
Use: "db",
Short: "Manage Workflow Studio application databases",
Long: `Manage DBaaS databases attached to Workflow Studio application spaces.

A database lives in an application space (Default if none is given). "Bind"
moves an existing database to another space, so the applications in that space
can use it. The DSN contains the database user password: treat it as a secret.`,
}
cmd.AddCommand(newDBListCmd())
cmd.AddCommand(newDBCreateCmd())
cmd.AddCommand(newDBShowCmd())
cmd.AddCommand(newDBBindCmd())
cmd.AddCommand(newDBResetPasswordCmd())
cmd.AddCommand(newDBDSNCmd())
cmd.AddCommand(newDBDeleteCmd())
return cmd
}

func newDBListCmd() *cobra.Command {
var spaceID, search, sort string
var limit, offset int

cmd := &cobra.Command{
Use: "list",
Short: "List databases in an application space",
Example: ` eds wf db list
eds wf db list --space-id 6f1c2a0e-3b7d-4c5e-9a8f-1d2e3f4a5b6c --search ord --limit 20`,
RunE: func(cmd *cobra.Command, _ []string) error {
ctx, err := resolveContext(cmd)
if err != nil {
return err
}
if err := ctx.ensureWorkflowAuth(cmd.Context()); err != nil {
return err
}

req := ctx.WorkflowClient.DatabasesAPI.ListApplicationDatabases(cmd.Context(), ctx.ProjectID)
if cmd.Flags().Changed("space-id") {
req = req.SpaceId(spaceID)
}
if cmd.Flags().Changed("search") {
req = req.Search(search)
}
if cmd.Flags().Changed("sort") {
req = req.Sort(sort)
}
if cmd.Flags().Changed("limit") {
req = req.Limit(limit)
}
if cmd.Flags().Changed("offset") {
req = req.Offset(offset)
}

resp, _, err := req.Execute()
if err != nil {
return fmt.Errorf("workflow client database list: %w", err)
}

return ctx.Printer.Print(resp)
},
}

cmd.Flags().StringVar(&spaceID, "space-id", "", "space ID (default: Default space)")
cmd.Flags().StringVar(&search, "search", "", "search by database name")
cmd.Flags().StringVar(&sort, "sort", "created_at_desc", "sort order: created_at_asc or created_at_desc")
cmd.Flags().IntVar(&limit, "limit", 10, "page size (0-100)")
cmd.Flags().IntVar(&offset, "offset", 0, "page offset")
return cmd
}

func newDBCreateCmd() *cobra.Command {
var spaceID string

cmd := &cobra.Command{
Use: "create <name>",
Short: "Create a database in an application space",
Args: cobra.ExactArgs(1),
Example: ` eds wf db create orders --space-id 6f1c2a0e-3b7d-4c5e-9a8f-1d2e3f4a5b6c`,
RunE: func(cmd *cobra.Command, args []string) error {
ctx, err := resolveContext(cmd)
if err != nil {
return err
}
if err := ctx.ensureWorkflowAuth(cmd.Context()); err != nil {
return err
}

req := dbCreateRequest{Name: args[0]}
if spaceID != "" {
req.SpaceId = &spaceID
}

resp, _, err := ctx.WorkflowClient.DatabasesAPI.CreateApplicationDatabase(cmd.Context(), ctx.ProjectID).
Request(req).
Execute()
if err != nil {
return fmt.Errorf("workflow client database create: %w", err)
}

return ctx.Printer.Print(resp)
},
}

cmd.Flags().StringVar(&spaceID, "space-id", "", "space ID (default: Default space)")
return cmd
}

func newDBShowCmd() *cobra.Command {
cmd := &cobra.Command{
Use: "show <db-id>",
Short: "Show a database",
Args: cobra.ExactArgs(1),
Example: ` eds wf db show 6f1c2a0e-3b7d-4c5e-9a8f-1d2e3f4a5b6c`,
RunE: func(cmd *cobra.Command, args []string) error {
ctx, err := resolveContext(cmd)
if err != nil {
return err
}
if err := ctx.ensureWorkflowAuth(cmd.Context()); err != nil {
return err
}

resp, _, err := ctx.WorkflowClient.DatabasesAPI.GetApplicationDatabase(cmd.Context(), ctx.ProjectID, args[0]).
Execute()
if err != nil {
return fmt.Errorf("workflow client database get: %w", err)
}

return ctx.Printer.Print(resp)
},
}

return cmd
}

func newDBBindCmd() *cobra.Command {
var spaceID string

cmd := &cobra.Command{
Use: "bind <db-id>",
Short: "Bind a database to an application space (move it there)",
Args: cobra.ExactArgs(1),
Example: ` eds wf db bind 6f1c2a0e-3b7d-4c5e-9a8f-1d2e3f4a5b6c --space-id 1d2e3f4a-5b6c-4c5e-9a8f-6f1c2a0e3b7d`,
RunE: func(cmd *cobra.Command, args []string) error {
ctx, err := resolveContext(cmd)
if err != nil {
return err
}
if err := ctx.ensureWorkflowAuth(cmd.Context()); err != nil {
return err
}
if spaceID == "" {
return fmt.Errorf("--space-id is required")
}

resp, _, err := ctx.WorkflowClient.DatabasesAPI.BindApplicationDatabase(cmd.Context(), ctx.ProjectID, args[0]).
Request(dbBindRequest{SpaceId: spaceID}).
Execute()
if err != nil {
return fmt.Errorf("workflow client database bind: %w", err)
}

return ctx.Printer.Print(resp)
},
}

cmd.Flags().StringVar(&spaceID, "space-id", "", "target space ID (required)")
return cmd
}

func newDBResetPasswordCmd() *cobra.Command {
cmd := &cobra.Command{
Use: "reset-password <db-id>",
Short: "Reset the database user password",
Args: cobra.ExactArgs(1),
Example: ` eds wf db reset-password 6f1c2a0e-3b7d-4c5e-9a8f-1d2e3f4a5b6c`,
RunE: func(cmd *cobra.Command, args []string) error {
ctx, err := resolveContext(cmd)
if err != nil {
return err
}
if err := ctx.ensureWorkflowAuth(cmd.Context()); err != nil {
return err
}

_, err = ctx.WorkflowClient.DatabasesAPI.ResetApplicationDatabasePassword(cmd.Context(), ctx.ProjectID, args[0]).
Execute()
if err != nil {
return fmt.Errorf("workflow client database reset password: %w", err)
}

return nil
},
}

return cmd
}

func newDBDSNCmd() *cobra.Command {
cmd := &cobra.Command{
Use: "dsn <db-id>",
Short: "Get the database connection string with its password (secret)",
Args: cobra.ExactArgs(1),
Example: ` eds wf db dsn 6f1c2a0e-3b7d-4c5e-9a8f-1d2e3f4a5b6c`,
RunE: func(cmd *cobra.Command, args []string) error {
ctx, err := resolveContext(cmd)
if err != nil {
return err
}
if err := ctx.ensureWorkflowAuth(cmd.Context()); err != nil {
return err
}

resp, _, err := ctx.WorkflowClient.DatabasesAPI.GetApplicationDatabaseDSN(cmd.Context(), ctx.ProjectID, args[0]).
Execute()
if err != nil {
return fmt.Errorf("workflow client database dsn: %w", err)
}

return ctx.Printer.Print(resp)
},
}

return cmd
}

func newDBDeleteCmd() *cobra.Command {
cmd := &cobra.Command{
Use: "delete <db-id>",
Short: "Delete a database, its user and password",
Args: cobra.ExactArgs(1),
Example: ` eds wf db delete 6f1c2a0e-3b7d-4c5e-9a8f-1d2e3f4a5b6c`,
RunE: func(cmd *cobra.Command, args []string) error {
ctx, err := resolveContext(cmd)
if err != nil {
return err
}
if err := ctx.ensureWorkflowAuth(cmd.Context()); err != nil {
return err
}

_, err = ctx.WorkflowClient.DatabasesAPI.DeleteApplicationDatabase(cmd.Context(), ctx.ProjectID, args[0]).
Execute()
if err != nil {
return fmt.Errorf("workflow client database delete: %w", err)
}

return nil
},
}

return cmd
}
1 change: 1 addition & 0 deletions cmd/wf.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ func newWFCmd() *cobra.Command {
cmd.AddCommand(newPipelineCmd())
cmd.AddCommand(newRunCmd())
cmd.AddCommand(newSpaceCmd())
cmd.AddCommand(newDBCmd())
cmd.AddCommand(newVariableCmd())
cmd.AddCommand(newJobCmd())
return cmd
Expand Down
9 changes: 9 additions & 0 deletions internal/workflow_client/.openapi-generator/FILES
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,15 @@
README.md
api/openapi.yaml
api_application_space.go
api_databases.go
api_pipelines.go
api_services.go
api_workflows.go
client.go
configuration.go
git_push.sh
model_git_sbercloud_tech_dsworks_services_pipeline_src_internal_application_model_application.go
model_git_sbercloud_tech_dsworks_services_pipeline_src_internal_application_model_application_db.go
model_git_sbercloud_tech_dsworks_services_pipeline_src_internal_application_model_application_space.go
model_git_sbercloud_tech_dsworks_services_pipeline_src_internal_application_model_config_storage_type.go
model_git_sbercloud_tech_dsworks_services_pipeline_src_internal_application_model_deployment.go
Expand All @@ -25,6 +27,8 @@ model_git_sbercloud_tech_dsworks_services_pipeline_src_internal_application_requ
model_git_sbercloud_tech_dsworks_services_pipeline_src_internal_application_request_application_space_create.go
model_git_sbercloud_tech_dsworks_services_pipeline_src_internal_application_request_application_space_update.go
model_git_sbercloud_tech_dsworks_services_pipeline_src_internal_application_request_application_update.go
model_git_sbercloud_tech_dsworks_services_pipeline_src_internal_application_request_applicationdb_create.go
model_git_sbercloud_tech_dsworks_services_pipeline_src_internal_application_request_applicationdb_update.go
model_git_sbercloud_tech_dsworks_services_pipeline_src_internal_application_request_job_log_list.go
model_git_sbercloud_tech_dsworks_services_pipeline_src_internal_application_request_variable_create.go
model_git_sbercloud_tech_dsworks_services_pipeline_src_internal_application_request_variable_update.go
Expand All @@ -35,6 +39,11 @@ model_git_sbercloud_tech_dsworks_services_pipeline_src_internal_application_resp
model_git_sbercloud_tech_dsworks_services_pipeline_src_internal_application_response_application_space_get.go
model_git_sbercloud_tech_dsworks_services_pipeline_src_internal_application_response_application_space_list.go
model_git_sbercloud_tech_dsworks_services_pipeline_src_internal_application_response_application_space_update.go
model_git_sbercloud_tech_dsworks_services_pipeline_src_internal_application_response_applicationdb_create.go
model_git_sbercloud_tech_dsworks_services_pipeline_src_internal_application_response_applicationdb_get.go
model_git_sbercloud_tech_dsworks_services_pipeline_src_internal_application_response_applicationdb_get_dsn.go
model_git_sbercloud_tech_dsworks_services_pipeline_src_internal_application_response_applicationdb_list.go
model_git_sbercloud_tech_dsworks_services_pipeline_src_internal_application_response_applicationdb_update.go
model_git_sbercloud_tech_dsworks_services_pipeline_src_internal_application_response_clone.go
model_git_sbercloud_tech_dsworks_services_pipeline_src_internal_application_response_deployment_create.go
model_git_sbercloud_tech_dsworks_services_pipeline_src_internal_application_response_deployment_list.go
Expand Down
Loading
Loading