From c38dbca84e865d3232a67095b4356a3055ba6155 Mon Sep 17 00:00:00 2001 From: Brian Zoetewey Date: Tue, 29 Oct 2024 10:00:45 -0400 Subject: [PATCH 01/14] Add project.type Add response scheme when creating a project Add body to project update Fix create/update project not saving some fields. Add demo flag to Project Request --- api-docs.yml | 29 ++++++++++++++++++++++++----- db/sql/project.go | 7 ++++--- 2 files changed, 28 insertions(+), 8 deletions(-) diff --git a/api-docs.yml b/api-docs.yml index 8e0b9726..fe4cc024 100644 --- a/api-docs.yml +++ b/api-docs.yml @@ -136,7 +136,7 @@ definitions: ProjectBackup: type: object - example: {"meta":{"name":"homelab","alert":true,"alert_chat":"Test","max_parallel_tasks":0},"templates":[{"inventory":"Build","repository":"Demo","environment":"Empty","name":"Build","playbook":"build.yml","arguments":"[]","allow_override_args_in_task":false,"description":"Build Job","vault_key":null,"type":"build","start_version":"1.0.0","build_template":null,"view":"Build","autorun":false,"survey_vars":[],"suppress_success_alerts":false,"cron":"* * * * *"}],"repositories":[{"name":"Demo","git_url":"https://github.com/semaphoreui/demo-project.git","git_branch":"main","ssh_key":"None"}],"keys":[{"name":"None","type":"none"},{"name":"Vault Password","type":"login_password"}],"views":[{"title":"Build","position":0}],"inventories":[{"name":"Build","inventory":"","ssh_key":"None","become_key":"None","type":"static"},{"name":"Dev","inventory":"","ssh_key":"None","become_key":"None","type":"file"},{"name":"Prod","inventory":"","ssh_key":"None","become_key":"None","type":"file"}],"environments":[{"name":"Empty","password":null,"json":"{}","env":null}]} + example: {"meta":{"name":"homelab","alert":true,"alert_chat":"Test","max_parallel_tasks":0,"type":null},"templates":[{"inventory":"Build","repository":"Demo","environment":"Empty","name":"Build","playbook":"build.yml","arguments":"[]","allow_override_args_in_task":false,"description":"Build Job","vault_key":null,"type":"build","start_version":"1.0.0","build_template":null,"view":"Build","autorun":false,"survey_vars":[],"suppress_success_alerts":false,"cron":"* * * * *"}],"repositories":[{"name":"Demo","git_url":"https://github.com/semaphoreui/demo-project.git","git_branch":"main","ssh_key":"None"}],"keys":[{"name":"None","type":"none"},{"name":"Vault Password","type":"login_password"}],"views":[{"title":"Build","position":0}],"inventories":[{"name":"Build","inventory":"","ssh_key":"None","become_key":"None","type":"static"},{"name":"Dev","inventory":"","ssh_key":"None","become_key":"None","type":"file"},{"name":"Prod","inventory":"","ssh_key":"None","become_key":"None","type":"file"}],"environments":[{"name":"Empty","password":null,"json":"{}","env":null}]} properties: meta: type: object @@ -152,6 +152,10 @@ definitions: max_parallel_tasks: type: integer minimum: 0 + type: + type: + - string + - 'null' templates: type: array items: @@ -304,6 +308,13 @@ definitions: max_parallel_tasks: type: integer minimum: 0 + type: + type: + - string + - 'null' + demo: + description: Create Demo project resources? + type: boolean Project: type: object properties: @@ -326,6 +337,10 @@ definitions: max_parallel_tasks: type: integer minimum: 0 + type: + type: + - string + - 'null' AccessKeyRequest: type: object @@ -1283,6 +1298,8 @@ paths: responses: 201: description: Created project + schema: + $ref: "#/definitions/Project" /projects/restore: post: tags: @@ -1344,10 +1361,12 @@ paths: in: body required: true schema: - type: object - properties: - name: - type: string + allOf: + - $ref: '#/definitions/ProjectRequest' + - properties: + id: + type: integer + minimum: 1 responses: 204: description: Project saved diff --git a/db/sql/project.go b/db/sql/project.go index ba13d5ac..508eb9e3 100644 --- a/db/sql/project.go +++ b/db/sql/project.go @@ -11,8 +11,8 @@ func (d *SqlDb) CreateProject(project db.Project) (newProject db.Project, err er insertId, err := d.insert( "id", - "insert into project(name, created, type) values (?, ?, ?)", - project.Name, project.Created, project.Type) + "insert into project(name, created, type, alert, alert_chat, max_parallel_tasks) values (?, ?, ?, ?, ?, ?)", + project.Name, project.Created, project.Type, project.Alert, project.AlertChat, project.MaxParallelTasks) if err != nil { return @@ -110,11 +110,12 @@ func (d *SqlDb) DeleteProject(projectID int) error { func (d *SqlDb) UpdateProject(project db.Project) error { _, err := d.exec( - "update project set name=?, alert=?, alert_chat=?, max_parallel_tasks=? where id=?", + "update project set name=?, alert=?, alert_chat=?, max_parallel_tasks=?, type=? where id=?", project.Name, project.Alert, project.AlertChat, project.MaxParallelTasks, + project.Type, project.ID) return err } From 36413a023d68442f339e39c014c73226d7af58a6 Mon Sep 17 00:00:00 2001 From: Brian Zoetewey Date: Fri, 1 Nov 2024 11:48:45 -0400 Subject: [PATCH 02/14] Add password and external to POST /users and external to user response. --- api-docs.yml | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/api-docs.yml b/api-docs.yml index fe4cc024..764b28bf 100644 --- a/api-docs.yml +++ b/api-docs.yml @@ -80,10 +80,15 @@ definitions: type: string x-example: test@ansiblesemaphore.test example: test@ansiblesemaphore.test + password: + type: string + format: password alert: type: boolean admin: type: boolean + external: + type: boolean UserPutRequest: type: object @@ -104,6 +109,7 @@ definitions: type: boolean admin: type: boolean + User: type: object properties: @@ -122,6 +128,8 @@ definitions: type: boolean admin: type: boolean + external: + type: boolean ProjectUser: type: object From 50cdd5789c2c0d939a958ec141437d1fdf6daee9 Mon Sep 17 00:00:00 2001 From: Brian Zoetewey Date: Wed, 6 Nov 2024 11:59:32 -0500 Subject: [PATCH 03/14] Fix project user API endpoints --- api-docs.yml | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/api-docs.yml b/api-docs.yml index 764b28bf..84332ee9 100644 --- a/api-docs.yml +++ b/api-docs.yml @@ -141,6 +141,9 @@ definitions: type: string username: type: string + role: + type: string + enum: [owner, manager, task_runner, guest] ProjectBackup: type: object @@ -1510,6 +1513,8 @@ paths: enum: [owner, manager, task_runner, guest] example: owner summary: Update user role + tags: + - project responses: 204: description: User updated From c8935eabdb58a6530919788a2877768dffb77d89 Mon Sep 17 00:00:00 2001 From: Brian Zoetewey Date: Wed, 6 Nov 2024 14:50:03 -0500 Subject: [PATCH 04/14] Add missing types, repository_id and GET inventory by ID. --- .dredd/hooks/capabilities.go | 13 +++++++------ .dredd/hooks/main.go | 1 + api-docs.yml | 18 ++++++++++++++++-- 3 files changed, 24 insertions(+), 8 deletions(-) diff --git a/.dredd/hooks/capabilities.go b/.dredd/hooks/capabilities.go index 7e55362d..ac886bdd 100644 --- a/.dredd/hooks/capabilities.go +++ b/.dredd/hooks/capabilities.go @@ -101,12 +101,13 @@ func resolveCapability(caps []string, resolved []string, uid string) { repoID = pRepo.ID case "inventory": res, err := store.CreateInventory(db.Inventory{ - ProjectID: userProject.ID, - Name: "ITI-" + uid, - Type: "static", - SSHKeyID: &userKey.ID, - BecomeKeyID: &userKey.ID, - Inventory: "Test Inventory", + ProjectID: userProject.ID, + Name: "ITI-" + uid, + Type: "static", + SSHKeyID: &userKey.ID, + BecomeKeyID: &userKey.ID, + Inventory: "Test Inventory", + RepositoryID: &repoID, }) printError(err) inventoryID = res.ID diff --git a/.dredd/hooks/main.go b/.dredd/hooks/main.go index 8027143c..f561af0b 100644 --- a/.dredd/hooks/main.go +++ b/.dredd/hooks/main.go @@ -101,6 +101,7 @@ func main() { h.Before("project > /api/project/{project_id}/repositories/{repository_id} > Removes repository > 204 > application/json", capabilityWrapper("repository")) h.Before("project > /api/project/{project_id}/inventory > create inventory > 201 > application/json", capabilityWrapper("inventory")) + h.Before("project > /api/project/{project_id}/inventory/{inventory_id} > Get inventory > 200 > application/json", capabilityWrapper("inventory")) h.Before("project > /api/project/{project_id}/inventory/{inventory_id} > Updates inventory > 204 > application/json", capabilityWrapper("inventory")) h.Before("project > /api/project/{project_id}/inventory/{inventory_id} > Removes inventory > 204 > application/json", capabilityWrapper("inventory")) diff --git a/api-docs.yml b/api-docs.yml index 84332ee9..9461187d 100644 --- a/api-docs.yml +++ b/api-docs.yml @@ -483,9 +483,12 @@ definitions: become_key_id: type: integer minimum: 1 + repository_id: + type: integer + minimum: 1 type: type: string - enum: [static, static-yaml, file] + enum: [static, static-yaml, file, terraform-workspace, tofu-workspace] Inventory: type: object @@ -503,9 +506,11 @@ definitions: type: integer become_key_id: type: integer + repository_id: + type: integer type: type: string - enum: [static, static-yaml, file] + enum: [static, static-yaml, file, terraform-workspace, tofu-workspace] Integration: type: object @@ -1883,6 +1888,15 @@ paths: parameters: - $ref: "#/parameters/project_id" - $ref: "#/parameters/inventory_id" + get: + tags: + - project + summary: Get inventory + responses: + 200: + description: inventory object + schema: + $ref: "#/definitions/Inventory" put: tags: - project From aac032db96acc4ff0211f67d9444c7f5b8b6b6c8 Mon Sep 17 00:00:00 2001 From: Brian Zoetewey Date: Thu, 7 Nov 2024 11:15:36 -0500 Subject: [PATCH 05/14] Return key ID on create, add passphrase --- .dredd/hooks/main.go | 1 + api-docs.yml | 10 +++++++++- api/projects/keys.go | 9 ++++++++- 3 files changed, 18 insertions(+), 2 deletions(-) diff --git a/.dredd/hooks/main.go b/.dredd/hooks/main.go index f561af0b..361864ac 100644 --- a/.dredd/hooks/main.go +++ b/.dredd/hooks/main.go @@ -93,6 +93,7 @@ func main() { h.Before("integration > /api/project/{project_id}/integrations/{integration_id}/matchers > Add Integration Matcher > 204 > application/json", capabilityWrapper("integration")) h.Before("integration > /api/project/{project_id}/integrations/{integration_id}/matchers/{matcher_id} > Updates Integration Matcher > 204 > application/json", capabilityWrapper("integrationmatcher")) + h.Before("project > /api/project/{project_id}/keys > Add access key > 201 > application/json", capabilityWrapper("access_key")) h.Before("project > /api/project/{project_id}/keys/{key_id} > Updates access key > 204 > application/json", capabilityWrapper("access_key")) h.Before("project > /api/project/{project_id}/keys/{key_id} > Removes access key > 204 > application/json", capabilityWrapper("access_key")) diff --git a/api-docs.yml b/api-docs.yml index 9461187d..e10e238d 100644 --- a/api-docs.yml +++ b/api-docs.yml @@ -368,6 +368,8 @@ definitions: type: integer minimum: 1 x-example: 2 + override_secret: + type: boolean login_password: type: object properties: @@ -386,6 +388,10 @@ definitions: type: string x-example: user example: user + passphrase: + type: string + x-example: passphrase + example: passphrase private_key: type: string x-example: private key @@ -1741,8 +1747,10 @@ paths: schema: $ref: "#/definitions/AccessKeyRequest" responses: - 204: + 201: description: Access Key created + schema: + $ref: "#/definitions/AccessKey" 400: description: Bad type /project/{project_id}/keys/{key_id}: diff --git a/api/projects/keys.go b/api/projects/keys.go index c3922454..02e9c31d 100644 --- a/api/projects/keys.go +++ b/api/projects/keys.go @@ -101,7 +101,14 @@ func AddKey(w http.ResponseWriter, r *http.Request) { Description: fmt.Sprintf("Access Key %s created", key.Name), }) - w.WriteHeader(http.StatusNoContent) + // Reload key to drop sensitive fields + key, err = helpers.Store(r).GetAccessKey(*newKey.ProjectID, newKey.ID) + if err != nil { + helpers.WriteError(w, err) + return + } + + helpers.WriteJSON(w, http.StatusCreated, key) } // UpdateKey updates key in database From 17e68ababb6ebc8abb812ef2636ae48b42ebeaa8 Mon Sep 17 00:00:00 2001 From: Brian Zoetewey Date: Thu, 7 Nov 2024 11:16:52 -0500 Subject: [PATCH 06/14] Api doesn't return secrets, so no need to document structure --- api-docs.yml | 22 ---------------------- 1 file changed, 22 deletions(-) diff --git a/api-docs.yml b/api-docs.yml index e10e238d..eb97fffe 100644 --- a/api-docs.yml +++ b/api-docs.yml @@ -410,28 +410,6 @@ definitions: enum: [none, ssh, login_password] project_id: type: integer - login_password: - type: object - properties: - password: - type: string - x-example: password - example: password - login: - type: string - x-example: username - example: username - ssh: - type: object - properties: - login: - type: string - x-example: user - example: user - private_key: - type: string - x-example: private key - example: private key EnvironmentRequest: type: object From 3499ed0a2bef879a783740a1702ddfb3c0f13f6d Mon Sep 17 00:00:00 2001 From: Brian Zoetewey Date: Mon, 11 Nov 2024 16:30:46 -0500 Subject: [PATCH 07/14] Add response to Create (POST) and add secrets. --- .dredd/hooks/capabilities.go | 14 ++++++++++ .dredd/hooks/main.go | 2 ++ api-docs.yml | 50 +++++++++++++++++++++++++++++++++++- api/projects/environment.go | 11 +++++++- 4 files changed, 75 insertions(+), 2 deletions(-) diff --git a/.dredd/hooks/capabilities.go b/.dredd/hooks/capabilities.go index ac886bdd..e565aa1d 100644 --- a/.dredd/hooks/capabilities.go +++ b/.dredd/hooks/capabilities.go @@ -114,6 +114,12 @@ func resolveCapability(caps []string, resolved []string, uid string) { case "environment": pwd := "test-pass" env := "{}" + secret := db.EnvironmentSecret{ + Type: db.EnvironmentSecretEnv, + Name: "TEST", + Secret: "VALUE", + Operation: "create", + } res, err := store.CreateEnvironment(db.Environment{ ProjectID: userProject.ID, Name: "ITI-" + uid, @@ -122,6 +128,14 @@ func resolveCapability(caps []string, resolved []string, uid string) { ENV: &env, }) printError(err) + _, err = store.CreateAccessKey(db.AccessKey{ + Name: string(secret.Type) + "." + secret.Name, + String: secret.Secret, + EnvironmentID: &res.ID, + ProjectID: &userProject.ID, + Type: db.AccessKeyString, + }) + printError(err) environmentID = res.ID case "template": args := "[]" diff --git a/.dredd/hooks/main.go b/.dredd/hooks/main.go index 361864ac..a52db633 100644 --- a/.dredd/hooks/main.go +++ b/.dredd/hooks/main.go @@ -106,6 +106,8 @@ func main() { h.Before("project > /api/project/{project_id}/inventory/{inventory_id} > Updates inventory > 204 > application/json", capabilityWrapper("inventory")) h.Before("project > /api/project/{project_id}/inventory/{inventory_id} > Removes inventory > 204 > application/json", capabilityWrapper("inventory")) + h.Before("project > /api/project/{project_id}/environment > Add environment > 201 > application/json", capabilityWrapper("environment")) + h.Before("project > /api/project/{project_id}/environment/{environment_id} > Get environment > 200 > application/json", capabilityWrapper("environment")) h.Before("project > /api/project/{project_id}/environment/{environment_id} > Update environment > 204 > application/json", capabilityWrapper("environment")) h.Before("project > /api/project/{project_id}/environment/{environment_id} > Removes environment > 204 > application/json", capabilityWrapper("environment")) diff --git a/api-docs.yml b/api-docs.yml index eb97fffe..f10a5e1b 100644 --- a/api-docs.yml +++ b/api-docs.yml @@ -411,9 +411,38 @@ definitions: project_id: type: integer + EnvironmentSecret: + type: object + properties: + id: + type: integer + name: + type: string + type: + type: string + enum: [env, var] + + EnvironmentSecretRequest: + type: object + properties: + id: + type: integer + name: + type: string + secret: + type: string + type: + type: string + enum: [env, var] + operation: + type: string + enum: [create, update, delete] + EnvironmentRequest: type: object properties: + id: + type: integer name: type: string example: Test @@ -428,6 +457,10 @@ definitions: env: type: string example: '{}' + secrets: + type: array + items: + $ref: '#/definitions/EnvironmentSecretRequest' Environment: type: object @@ -449,6 +482,10 @@ definitions: env: type: string example: '{}' + secrets: + type: array + items: + $ref: '#/definitions/EnvironmentSecret' InventoryRequest: type: object @@ -1945,12 +1982,23 @@ paths: schema: $ref: "#/definitions/EnvironmentRequest" responses: - 204: + 201: description: Environment created + schema: + $ref: "#/definitions/Environment" /project/{project_id}/environment/{environment_id}: parameters: - $ref: "#/parameters/project_id" - $ref: "#/parameters/environment_id" + get: + tags: + - project + summary: Get environment + responses: + 200: + description: environment object + schema: + $ref: "#/definitions/Environment" put: tags: - project diff --git a/api/projects/environment.go b/api/projects/environment.go index acc0cdab..4a33e004 100644 --- a/api/projects/environment.go +++ b/api/projects/environment.go @@ -197,7 +197,16 @@ func AddEnvironment(w http.ResponseWriter, r *http.Request) { //return } - w.WriteHeader(http.StatusNoContent) + // Reload env + env, err = helpers.Store(r).GetEnvironment(newEnv.ProjectID, newEnv.ID) + if err != nil { + helpers.WriteError(w, err) + return + } + // Use empty array to avoid null in JSON + env.Secrets = []db.EnvironmentSecret{} + + helpers.WriteJSON(w, http.StatusCreated, env) } // RemoveEnvironment deletes an environment from the database From 7adcf8b41e52e61e09954556ad82063e1e82b3fb Mon Sep 17 00:00:00 2001 From: Brian Zoetewey Date: Mon, 11 Nov 2024 16:56:05 -0500 Subject: [PATCH 08/14] Add response to Create (POST) and document get request. --- .dredd/hooks/main.go | 3 ++- api-docs.yml | 16 +++++++++++++++- api/projects/repository.go | 4 ++-- 3 files changed, 19 insertions(+), 4 deletions(-) diff --git a/.dredd/hooks/main.go b/.dredd/hooks/main.go index a52db633..06ac6bc6 100644 --- a/.dredd/hooks/main.go +++ b/.dredd/hooks/main.go @@ -97,7 +97,8 @@ func main() { h.Before("project > /api/project/{project_id}/keys/{key_id} > Updates access key > 204 > application/json", capabilityWrapper("access_key")) h.Before("project > /api/project/{project_id}/keys/{key_id} > Removes access key > 204 > application/json", capabilityWrapper("access_key")) - h.Before("project > /api/project/{project_id}/repositories > Add repository > 204 > application/json", capabilityWrapper("access_key")) + h.Before("project > /api/project/{project_id}/repositories > Add repository > 201 > application/json", capabilityWrapper("access_key")) + h.Before("project > /api/project/{project_id}/repositories/{repository_id} > Get repository > 200 > application/json", capabilityWrapper("repository")) h.Before("project > /api/project/{project_id}/repositories/{repository_id} > Updates repository > 204 > application/json", capabilityWrapper("repository")) h.Before("project > /api/project/{project_id}/repositories/{repository_id} > Removes repository > 204 > application/json", capabilityWrapper("repository")) diff --git a/api-docs.yml b/api-docs.yml index f10a5e1b..a99dc15b 100644 --- a/api-docs.yml +++ b/api-docs.yml @@ -652,6 +652,8 @@ definitions: RepositoryRequest: type: object properties: + id: + type: integer name: type: string example: Test @@ -1835,12 +1837,24 @@ paths: schema: $ref: "#/definitions/RepositoryRequest" responses: - 204: + 201: description: Repository created + schema: + $ref: "#/definitions/Repository" + /project/{project_id}/repositories/{repository_id}: parameters: - $ref: "#/parameters/project_id" - $ref: "#/parameters/repository_id" + get: + tags: + - project + summary: Get repository + responses: + 200: + description: repository object + schema: + $ref: "#/definitions/Repository" put: tags: - project diff --git a/api/projects/repository.go b/api/projects/repository.go index 699a3292..d4387c40 100644 --- a/api/projects/repository.go +++ b/api/projects/repository.go @@ -5,10 +5,10 @@ import ( "fmt" "net/http" + "github.com/gorilla/context" "github.com/semaphoreui/semaphore/api/helpers" "github.com/semaphoreui/semaphore/db" "github.com/semaphoreui/semaphore/util" - "github.com/gorilla/context" ) // RepositoryMiddleware ensures a repository exists and loads it to the context @@ -98,7 +98,7 @@ func AddRepository(w http.ResponseWriter, r *http.Request) { Description: fmt.Sprintf("Repository %s created", repository.GitURL), }) - w.WriteHeader(http.StatusNoContent) + helpers.WriteJSON(w, http.StatusCreated, newRepo) } // UpdateRepository updates the values of a repository in the database From f9746215efdaf383b76f903ad244a5b63584b07e Mon Sep 17 00:00:00 2001 From: Brian Zoetewey Date: Thu, 14 Nov 2024 15:24:34 -0500 Subject: [PATCH 09/14] Additional api-docs updates from testing. --- api-docs.yml | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/api-docs.yml b/api-docs.yml index a99dc15b..c7d4ac76 100644 --- a/api-docs.yml +++ b/api-docs.yml @@ -356,6 +356,8 @@ definitions: AccessKeyRequest: type: object properties: + id: + type: integer name: type: string x-example: None @@ -490,6 +492,8 @@ definitions: InventoryRequest: type: object properties: + id: + type: integer name: type: string example: Test @@ -509,7 +513,7 @@ definitions: minimum: 1 type: type: string - enum: [static, static-yaml, file, terraform-workspace, tofu-workspace] + enum: [static, static-yaml, file, terraform-workspace] Inventory: type: object @@ -531,7 +535,7 @@ definitions: type: integer type: type: string - enum: [static, static-yaml, file, terraform-workspace, tofu-workspace] + enum: [static, static-yaml, file, terraform-workspace] Integration: type: object From 3b156a59b913d0826689eb0caeedbb71028f841f Mon Sep 17 00:00:00 2001 From: Brian Zoetewey Date: Thu, 14 Nov 2024 15:25:09 -0500 Subject: [PATCH 10/14] Correctly update environment secrets --- api/projects/environment.go | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) diff --git a/api/projects/environment.go b/api/projects/environment.go index 4a33e004..ef528f62 100644 --- a/api/projects/environment.go +++ b/api/projects/environment.go @@ -50,11 +50,18 @@ func updateEnvironmentSecrets(store db.Store, env db.Environment) error { continue } - err = store.UpdateAccessKey(db.AccessKey{ - Name: string(secret.Type) + "." + secret.Name, - String: secret.Secret, - Type: db.AccessKeyString, - }) + updateKey := db.AccessKey{ + ID: key.ID, + ProjectID: key.ProjectID, + Name: string(secret.Type) + "." + secret.Name, + Type: db.AccessKeyString, + } + if secret.Secret != "" { + updateKey.String = secret.Secret + updateKey.OverrideSecret = true + } + + err = store.UpdateAccessKey(updateKey) } } From c4548b017a4a0897287714a5289c47d7bc7166fc Mon Sep 17 00:00:00 2001 From: Brian Zoetewey Date: Wed, 20 Nov 2024 15:32:13 -0500 Subject: [PATCH 11/14] Update templates API docs. --- .dredd/hooks/capabilities.go | 1 + api-docs.yml | 60 ++++++++++++++++++++++++++++++++++-- 2 files changed, 58 insertions(+), 3 deletions(-) diff --git a/.dredd/hooks/capabilities.go b/.dredd/hooks/capabilities.go index e565aa1d..cc10ee4c 100644 --- a/.dredd/hooks/capabilities.go +++ b/.dredd/hooks/capabilities.go @@ -154,6 +154,7 @@ func resolveCapability(caps []string, resolved []string, uid string) { ViewID: &view.ID, App: db.AppAnsible, GitBranch: &branch, + SurveyVars: []db.SurveyVar{}, }) printError(err) diff --git a/api-docs.yml b/api-docs.yml index c7d4ac76..d5a94c4e 100644 --- a/api-docs.yml +++ b/api-docs.yml @@ -732,6 +732,8 @@ definitions: TemplateRequest: type: object properties: + id: + type: integer project_id: type: integer minimum: 1 @@ -781,6 +783,16 @@ definitions: type: array items: $ref: "#/definitions/TemplateSurveyVar" + type: + type: string + enum: ["", build, deploy] + start_version: + type: string + build_template_id: + type: integer + autorun: + type: boolean + Template: type: object properties: @@ -823,6 +835,28 @@ definitions: git_branch: type: string example: main + type: + type: string + enum: ["", build, deploy] + start_version: + type: + - string + - 'null' + build_template_id: + type: + - integer + - 'null' + autorun: + type: boolean + survey_vars: + type: array + items: + $ref: "#/definitions/TemplateSurveyVar" + vaults: + type: array + items: + $ref: "#/definitions/TemplateVault" + TemplateSurveyVar: type: object properties: @@ -834,12 +868,32 @@ definitions: type: string type: type: string - example: String => "", Integer => "int" + enum: ["", int, enum, secret] # String => "", Integer => "int" + example: int required: type: boolean + values: + type: array + items: + $ref: "#/definitions/TemplateSurveyVarValue" + + TemplateSurveyVarValue: + type: object + properties: + name: + type: string + value: + type: string + TemplateVault: type: object properties: + id: + type: integer + template_id: + type: integer + project_id: + type: integer name: type: string example: default @@ -2078,7 +2132,7 @@ paths: - project summary: create template parameters: - - name: templateyes + - name: template in: body required: true schema: @@ -2087,7 +2141,7 @@ paths: 201: description: template created schema: - $ref: "#/definitions/TemplateRequest" + $ref: "#/definitions/Template" /project/{project_id}/templates/{template_id}: parameters: - $ref: "#/parameters/project_id" From d601dba3312ee0072a4afeeb24fbf93550ecfee7 Mon Sep 17 00:00:00 2001 From: Brian Zoetewey Date: Thu, 21 Nov 2024 15:13:41 -0500 Subject: [PATCH 12/14] Fix foreign key on build template with postgresql --- .dredd/hooks/capabilities.go | 1 + api-docs.yml | 5 +---- 2 files changed, 2 insertions(+), 4 deletions(-) diff --git a/.dredd/hooks/capabilities.go b/.dredd/hooks/capabilities.go index cc10ee4c..5eca5f97 100644 --- a/.dredd/hooks/capabilities.go +++ b/.dredd/hooks/capabilities.go @@ -234,6 +234,7 @@ func alterRequestBody(t *trans.Transaction) { bodyFieldProcessor("inventory_id", inventoryID, &request) bodyFieldProcessor("repository_id", repoID, &request) bodyFieldProcessor("template_id", templateID, &request) + bodyFieldProcessor("build_template_id", nil, &request) if task != nil { bodyFieldProcessor("task_id", task.ID, &request) } diff --git a/api-docs.yml b/api-docs.yml index d5a94c4e..d58d97a5 100644 --- a/api-docs.yml +++ b/api-docs.yml @@ -890,10 +890,6 @@ definitions: properties: id: type: integer - template_id: - type: integer - project_id: - type: integer name: type: string example: default @@ -909,6 +905,7 @@ definitions: type: - string - 'null' + example: path/to/script-client.py ScheduleRequest: type: object From 67f2e2bed29de9612d181a00927b8af0f1b6c8a8 Mon Sep 17 00:00:00 2001 From: Brian Zoetewey Date: Thu, 21 Nov 2024 16:04:30 -0500 Subject: [PATCH 13/14] Set example values so boltdb tests pass --- api-docs.yml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/api-docs.yml b/api-docs.yml index d58d97a5..b5c0f81e 100644 --- a/api-docs.yml +++ b/api-docs.yml @@ -445,6 +445,7 @@ definitions: properties: id: type: integer + example: 1 name: type: string example: Test @@ -734,6 +735,7 @@ definitions: properties: id: type: integer + example: 1 project_id: type: integer minimum: 1 From c71d5f2994a788200831242532240485b70753d6 Mon Sep 17 00:00:00 2001 From: Brian Zoetewey Date: Mon, 25 Nov 2024 10:32:50 -0500 Subject: [PATCH 14/14] Project type can't be updated. --- db/sql/project.go | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/db/sql/project.go b/db/sql/project.go index 508eb9e3..794926fd 100644 --- a/db/sql/project.go +++ b/db/sql/project.go @@ -110,12 +110,11 @@ func (d *SqlDb) DeleteProject(projectID int) error { func (d *SqlDb) UpdateProject(project db.Project) error { _, err := d.exec( - "update project set name=?, alert=?, alert_chat=?, max_parallel_tasks=?, type=? where id=?", + "update project set name=?, alert=?, alert_chat=?, max_parallel_tasks=? where id=?", project.Name, project.Alert, project.AlertChat, project.MaxParallelTasks, - project.Type, project.ID) return err }