mirror of
https://github.com/semaphoreui/semaphore.git
synced 2024-12-04 23:31: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":
|
case "environment":
|
||||||
pwd := "test-pass"
|
pwd := "test-pass"
|
||||||
env := "{}"
|
env := "{}"
|
||||||
|
secret := db.EnvironmentSecret{
|
||||||
|
Type: db.EnvironmentSecretEnv,
|
||||||
|
Name: "TEST",
|
||||||
|
Secret: "VALUE",
|
||||||
|
Operation: "create",
|
||||||
|
}
|
||||||
res, err := store.CreateEnvironment(db.Environment{
|
res, err := store.CreateEnvironment(db.Environment{
|
||||||
ProjectID: userProject.ID,
|
ProjectID: userProject.ID,
|
||||||
Name: "ITI-" + uid,
|
Name: "ITI-" + uid,
|
||||||
@ -122,6 +128,14 @@ func resolveCapability(caps []string, resolved []string, uid string) {
|
|||||||
ENV: &env,
|
ENV: &env,
|
||||||
})
|
})
|
||||||
printError(err)
|
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
|
environmentID = res.ID
|
||||||
case "template":
|
case "template":
|
||||||
args := "[]"
|
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} > 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}/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} > Update environment > 204 > application/json", capabilityWrapper("environment"))
|
||||||
h.Before("project > /api/project/{project_id}/environment/{environment_id} > Removes 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:
|
project_id:
|
||||||
type: integer
|
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:
|
EnvironmentRequest:
|
||||||
type: object
|
type: object
|
||||||
properties:
|
properties:
|
||||||
|
id:
|
||||||
|
type: integer
|
||||||
name:
|
name:
|
||||||
type: string
|
type: string
|
||||||
example: Test
|
example: Test
|
||||||
@ -428,6 +457,10 @@ definitions:
|
|||||||
env:
|
env:
|
||||||
type: string
|
type: string
|
||||||
example: '{}'
|
example: '{}'
|
||||||
|
secrets:
|
||||||
|
type: array
|
||||||
|
items:
|
||||||
|
$ref: '#/definitions/EnvironmentSecretRequest'
|
||||||
|
|
||||||
Environment:
|
Environment:
|
||||||
type: object
|
type: object
|
||||||
@ -449,6 +482,10 @@ definitions:
|
|||||||
env:
|
env:
|
||||||
type: string
|
type: string
|
||||||
example: '{}'
|
example: '{}'
|
||||||
|
secrets:
|
||||||
|
type: array
|
||||||
|
items:
|
||||||
|
$ref: '#/definitions/EnvironmentSecret'
|
||||||
|
|
||||||
InventoryRequest:
|
InventoryRequest:
|
||||||
type: object
|
type: object
|
||||||
@ -1945,12 +1982,23 @@ paths:
|
|||||||
schema:
|
schema:
|
||||||
$ref: "#/definitions/EnvironmentRequest"
|
$ref: "#/definitions/EnvironmentRequest"
|
||||||
responses:
|
responses:
|
||||||
204:
|
201:
|
||||||
description: Environment created
|
description: Environment created
|
||||||
|
schema:
|
||||||
|
$ref: "#/definitions/Environment"
|
||||||
/project/{project_id}/environment/{environment_id}:
|
/project/{project_id}/environment/{environment_id}:
|
||||||
parameters:
|
parameters:
|
||||||
- $ref: "#/parameters/project_id"
|
- $ref: "#/parameters/project_id"
|
||||||
- $ref: "#/parameters/environment_id"
|
- $ref: "#/parameters/environment_id"
|
||||||
|
get:
|
||||||
|
tags:
|
||||||
|
- project
|
||||||
|
summary: Get environment
|
||||||
|
responses:
|
||||||
|
200:
|
||||||
|
description: environment object
|
||||||
|
schema:
|
||||||
|
$ref: "#/definitions/Environment"
|
||||||
put:
|
put:
|
||||||
tags:
|
tags:
|
||||||
- project
|
- project
|
||||||
|
@ -197,7 +197,16 @@ func AddEnvironment(w http.ResponseWriter, r *http.Request) {
|
|||||||
//return
|
//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
|
// RemoveEnvironment deletes an environment from the database
|
||||||
|
Loading…
Reference in New Issue
Block a user