Skip to content

Commit e535c71

Browse files
committed
Merge branch 'develop' of github.com:rmtsrc/semaphore into prefers-color-scheme
2 parents a31aa03 + 6443764 commit e535c71

File tree

428 files changed

+43510
-15502
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

428 files changed

+43510
-15502
lines changed

.codacy.yml

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
---
2+
exclude_paths:
3+
- .dredd/**

.devcontainer/config-runner.json

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
{
2+
"web_host": "http://localhost:3000",
3+
"runner": {
4+
"token_file": "/home/codespace/.semaphore-runner-token"
5+
}
6+
}

.devcontainer/config.json

+12
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
{
2+
"bolt": {
3+
"host": "/workspaces/semaphore/database.boltdb",
4+
"options": {
5+
"sessionConnection": "true"
6+
}
7+
},
8+
"dialect": "bolt",
9+
"cookie_hash": "5WJjXCLpvf3Cn5t+C/IV9F0asZUQLakOhCT+eSdIwP0=",
10+
"cookie_encryption": "6x6mmQWGn6YcsHN1rN0HiQjhYA+7HukcbCxUGHuT2CE="
11+
}
12+

.devcontainer/devcontainer.json

+2-1
Original file line numberDiff line numberDiff line change
@@ -3,5 +3,6 @@
33
"features": {
44
"ghcr.io/devcontainers/features/go:1": {},
55
"ghcr.io/devcontainers/features/node:1": {}
6-
}
6+
},
7+
"postCreateCommand": "./.devcontainer/postCreateCommand.sh"
78
}

.devcontainer/postCreateCommand.sh

+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
go install github.com/go-task/task/v3/cmd/task@latest
2+
3+
(cd ./web && npm install)
4+
5+
python3 -m venv .venv
6+
7+
./.venv/bin/pip3 install ansible
8+
9+
task build
10+
task e2e:goodman
11+
task e2e:hooks
12+
13+
cp ./.devcontainer/config.json ./.dredd/config.json
14+
15+
./bin/semaphore user add \
16+
--admin \
17+
--login admin \
18+
--name Admin \
19+
20+
--password changeme \
21+
--config ./.devcontainer/config.json

.dockerignore

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
web/node_modules/
2+
vendor/

.dredd/dredd.dev.yml renamed to .dredd/dredd.docker.yml

+2-3
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
11
dry-run: null
22
hookfiles: ./.dredd/compiled_hooks
33
language: go
4-
#server: context=dev task dc:up
5-
server-wait: 240
4+
server-wait: 5
65
init: false
76
custom: {}
87
names: false
@@ -28,4 +27,4 @@ hooks-worker-handler-host: 0.0.0.0
2827
hooks-worker-handler-port: 61321
2928
config: ./.dredd/dredd.yml
3029
blueprint: api-docs.yml
31-
endpoint: 'http://semaphore_ci:3000'
30+
endpoint: 'http://server:3000'

.dredd/dredd.local.yml

+1-2
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
11
dry-run: null
22
hookfiles: ./.dredd/compiled_hooks
33
language: go
4-
#server: context=dev task dc:up
5-
server-wait: 240
4+
server-wait: 5
65
init: false
76
custom: {}
87
names: false

.dredd/dredd.yml renamed to .dredd/dredd.testing.yml

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
dry-run: null
22
hookfiles: ./.dredd/compiled_hooks
33
language: go
4-
#server: context=dev task dc:up
5-
server-wait: 240
4+
server: ./.dredd/server-wrapper.sh
5+
server-wait: 5
66
init: false
77
custom: {}
88
names: false
@@ -28,4 +28,4 @@ hooks-worker-handler-host: 0.0.0.0
2828
hooks-worker-handler-port: 61321
2929
config: ./.dredd/dredd.yml
3030
blueprint: api-docs.yml
31-
endpoint: 'http://semaphore_ci:3000'
31+
endpoint: 'http://localhost:3000'

.dredd/dredd.windows.yml

+1-2
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
11
dry-run: null
22
hookfiles: ./.dredd/compiled_hooks.exe
33
language: go
4-
#server: context=dev task dc:up
5-
server-wait: 240
4+
server-wait: 5
65
init: false
76
custom: {}
87
names: false

.dredd/hooks/capabilities.go

+80-22
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,12 @@ package main
22

33
import (
44
"encoding/json"
5-
"github.com/ansible-semaphore/semaphore/db"
6-
trans "github.com/snikch/goodman/transaction"
75
"regexp"
86
"strconv"
97
"strings"
8+
9+
"github.com/semaphoreui/semaphore/db"
10+
trans "github.com/snikch/goodman/transaction"
1011
)
1112

1213
// STATE
@@ -18,23 +19,32 @@ var userKey *db.AccessKey
1819
var task *db.Task
1920
var schedule *db.Schedule
2021
var view *db.View
22+
var integration *db.Integration
23+
var integrationextractvalue *db.IntegrationExtractValue
24+
var integrationmatch *db.IntegrationMatcher
2125

2226
// Runtime created simple ID values for some items we need to reference in other objects
2327
var repoID int
2428
var inventoryID int
2529
var environmentID int
2630
var templateID int
31+
var integrationID int
32+
var integrationExtractValueID int
33+
var integrationMatchID int
2734

2835
var capabilities = map[string][]string{
29-
"user": {},
30-
"project": {"user"},
31-
"repository": {"access_key"},
32-
"inventory": {"repository"},
33-
"environment": {"repository"},
34-
"template": {"repository", "inventory", "environment", "view"},
35-
"task": {"template"},
36-
"schedule": {"template"},
37-
"view": {},
36+
"user": {},
37+
"project": {"user"},
38+
"repository": {"access_key"},
39+
"inventory": {"repository"},
40+
"environment": {"repository"},
41+
"template": {"repository", "inventory", "environment", "view"},
42+
"task": {"template"},
43+
"schedule": {"template"},
44+
"view": {},
45+
"integration": {"project", "template"},
46+
"integrationextractvalue": {"integration"},
47+
"integrationmatcher": {"integration"},
3848
}
3949

4050
func capabilityWrapper(cap string) func(t *trans.Transaction) {
@@ -91,17 +101,25 @@ func resolveCapability(caps []string, resolved []string, uid string) {
91101
repoID = pRepo.ID
92102
case "inventory":
93103
res, err := store.CreateInventory(db.Inventory{
94-
ProjectID: userProject.ID,
95-
Name: "ITI-" + uid,
96-
Type: "static",
97-
SSHKeyID: &userKey.ID,
98-
Inventory: "Test Inventory",
104+
ProjectID: userProject.ID,
105+
Name: "ITI-" + uid,
106+
Type: "static",
107+
SSHKeyID: &userKey.ID,
108+
BecomeKeyID: &userKey.ID,
109+
Inventory: "Test Inventory",
110+
RepositoryID: &repoID,
99111
})
100112
printError(err)
101113
inventoryID = res.ID
102114
case "environment":
103115
pwd := "test-pass"
104116
env := "{}"
117+
secret := db.EnvironmentSecret{
118+
Type: db.EnvironmentSecretEnv,
119+
Name: "TEST",
120+
Secret: "VALUE",
121+
Operation: "create",
122+
}
105123
res, err := store.CreateEnvironment(db.Environment{
106124
ProjectID: userProject.ID,
107125
Name: "ITI-" + uid,
@@ -110,13 +128,22 @@ func resolveCapability(caps []string, resolved []string, uid string) {
110128
ENV: &env,
111129
})
112130
printError(err)
131+
_, err = store.CreateAccessKey(db.AccessKey{
132+
Name: string(secret.Type) + "." + secret.Name,
133+
String: secret.Secret,
134+
EnvironmentID: &res.ID,
135+
ProjectID: &userProject.ID,
136+
Type: db.AccessKeyString,
137+
})
138+
printError(err)
113139
environmentID = res.ID
114140
case "template":
115141
args := "[]"
116142
desc := "Hello, World!"
143+
branch := "main"
117144
res, err := store.CreateTemplate(db.Template{
118145
ProjectID: userProject.ID,
119-
InventoryID: inventoryID,
146+
InventoryID: &inventoryID,
120147
RepositoryID: repoID,
121148
EnvironmentID: &environmentID,
122149
Name: "Test-" + uid,
@@ -125,12 +152,24 @@ func resolveCapability(caps []string, resolved []string, uid string) {
125152
AllowOverrideArgsInTask: false,
126153
Description: &desc,
127154
ViewID: &view.ID,
155+
App: db.AppAnsible,
156+
GitBranch: &branch,
157+
SurveyVars: []db.SurveyVar{},
128158
})
129159

130160
printError(err)
131161
templateID = res.ID
132162
case "task":
133163
task = addTask()
164+
case "integration":
165+
integration = addIntegration()
166+
integrationID = integration.ID
167+
case "integrationextractvalue":
168+
integrationextractvalue = addIntegrationExtractValue()
169+
integrationExtractValueID = integrationextractvalue.ID
170+
case "integrationmatcher":
171+
integrationmatch = addIntegrationMatcher()
172+
integrationMatchID = integrationmatch.ID
134173
default:
135174
panic("unknown capability " + v)
136175
}
@@ -150,13 +189,16 @@ var pathSubPatterns = []func() string{
150189
func() string { return strconv.Itoa(userProject.ID) },
151190
func() string { return strconv.Itoa(userPathTestUser.ID) },
152191
func() string { return strconv.Itoa(userKey.ID) },
153-
func() string { return strconv.Itoa(int(repoID)) },
154-
func() string { return strconv.Itoa(int(inventoryID)) },
155-
func() string { return strconv.Itoa(int(environmentID)) },
156-
func() string { return strconv.Itoa(int(templateID)) },
192+
func() string { return strconv.Itoa(repoID) },
193+
func() string { return strconv.Itoa(inventoryID) },
194+
func() string { return strconv.Itoa(environmentID) },
195+
func() string { return strconv.Itoa(templateID) },
157196
func() string { return strconv.Itoa(task.ID) },
158197
func() string { return strconv.Itoa(schedule.ID) },
159198
func() string { return strconv.Itoa(view.ID) },
199+
func() string { return strconv.Itoa(integration.ID) },
200+
func() string { return strconv.Itoa(integrationextractvalue.ID) },
201+
func() string { return strconv.Itoa(integrationmatch.ID) },
160202
}
161203

162204
// alterRequestPath with the above slice of functions
@@ -165,12 +207,14 @@ func alterRequestPath(t *trans.Transaction) {
165207
exploded := make([]string, len(pathArgs))
166208
copy(exploded, pathArgs)
167209
for k, v := range pathSubPatterns {
210+
168211
pos, exists := stringInSlice(strconv.Itoa(k+1), exploded)
169212
if exists {
170213
pathArgs[pos] = v()
171214
}
172215
}
173216
t.FullPath = strings.Join(pathArgs, "/")
217+
174218
t.Request.URI = t.FullPath
175219
}
176220

@@ -184,11 +228,13 @@ func alterRequestBody(t *trans.Transaction) {
184228
bodyFieldProcessor("json", "{}", &request)
185229
if userKey != nil {
186230
bodyFieldProcessor("ssh_key_id", userKey.ID, &request)
231+
bodyFieldProcessor("become_key_id", userKey.ID, &request)
187232
}
188233
bodyFieldProcessor("environment_id", environmentID, &request)
189234
bodyFieldProcessor("inventory_id", inventoryID, &request)
190235
bodyFieldProcessor("repository_id", repoID, &request)
191236
bodyFieldProcessor("template_id", templateID, &request)
237+
bodyFieldProcessor("build_template_id", nil, &request)
192238
if task != nil {
193239
bodyFieldProcessor("task_id", task.ID, &request)
194240
}
@@ -198,9 +244,21 @@ func alterRequestBody(t *trans.Transaction) {
198244
if view != nil {
199245
bodyFieldProcessor("view_id", view.ID, &request)
200246
}
247+
248+
if integration != nil {
249+
bodyFieldProcessor("integration_id", integration.ID, &request)
250+
}
251+
if integrationextractvalue != nil {
252+
bodyFieldProcessor("value_id", integrationextractvalue.ID, &request)
253+
}
254+
if integrationmatch != nil {
255+
bodyFieldProcessor("matcher_id", integrationmatch.ID, &request)
256+
}
257+
201258
// Inject object ID to body for PUT requests
202259
if strings.ToLower(t.Request.Method) == "put" {
203-
putRequestPathRE := regexp.MustCompile(`/api/(?:project/\d+/)?\w+/(\d+)/?$`)
260+
261+
putRequestPathRE := regexp.MustCompile(`\w+/(\d+)/?$`)
204262
m := putRequestPathRE.FindStringSubmatch(t.FullPath)
205263
if len(m) > 0 {
206264
objectID, err := strconv.Atoi(m[1])

0 commit comments

Comments
 (0)