mirror of
https://github.com/semaphoreui/semaphore.git
synced 2024-12-04 15:21:05 +01:00
Add response to Create (POST) and add secrets.
This commit is contained in:
parent
17e68ababb
commit
3499ed0a2b
@ -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 := "[]"
|
||||
|
@ -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"))
|
||||
|
||||
|
50
api-docs.yml
50
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
|
||||
|
@ -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
|
||||
|
Loading…
Reference in New Issue
Block a user