@@ -25,7 +25,6 @@ import (
25
25
"github.com/gimlet-io/gimlet-cli/pkg/git/customScm/customGitlab"
26
26
"github.com/gimlet-io/gimlet-cli/pkg/git/genericScm"
27
27
"github.com/gimlet-io/gimlet-cli/pkg/git/nativeGit"
28
- "github.com/gimlet-io/gimlet-cli/pkg/gitops"
29
28
"github.com/gimlet-io/gimlet-cli/pkg/server/token"
30
29
"github.com/gimlet-io/gimlet-cli/pkg/stack"
31
30
"github.com/go-chi/chi/v5"
@@ -89,23 +88,7 @@ func main() {
89
88
Stack : dx.StackRef {
90
89
Repository : stackUrl ,
91
90
},
92
- Config : map [string ]interface {}{
93
- "k3s" : map [string ]interface {}{
94
- "host" : os .Getenv ("HOST" ),
95
- },
96
- "civo" : map [string ]interface {}{
97
- "host" : os .Getenv ("HOST" ),
98
- },
99
- "nginx" : map [string ]interface {}{
100
- "enabled" : true ,
101
- "host" : os .Getenv ("HOST" ),
102
- },
103
- "gimletd" : map [string ]interface {}{
104
- "environments" : []map [string ]interface {}{
105
- {},
106
- },
107
- },
108
- },
91
+ Config : map [string ]interface {}{},
109
92
}
110
93
111
94
stackDefinition , err := loadStackDefinition (stackConfig )
@@ -170,21 +153,15 @@ func main() {
170
153
srv .Shutdown (context .TODO ())
171
154
}
172
155
173
- func initStackConfig (data * data ) string {
156
+ func initStackConfig (data * data ) {
174
157
jwtSecret , _ := randomHex (32 )
175
158
agentAuth := jwtauth .New ("HS256" , []byte (jwtSecret ), nil )
176
159
_ , agentToken , _ := agentAuth .Encode (map [string ]interface {}{"user_id" : "gimlet-agent" })
177
160
178
161
webhookSecret , _ := randomHex (32 )
179
- privateKeyBytes , publicKeyBytes , err := gitops .GenerateEd25519 ()
180
- if err != nil {
181
- panic (err )
182
- }
183
- gimletdPublicKey := string (publicKeyBytes )
184
162
185
163
postgresPassword := base32 .StdEncoding .EncodeToString (securecookie .GenerateRandomKey (32 ))
186
164
dashboardPassword := base32 .StdEncoding .EncodeToString (securecookie .GenerateRandomKey (32 ))
187
- gimletdPassword := base32 .StdEncoding .EncodeToString (securecookie .GenerateRandomKey (32 ))
188
165
189
166
gimletdAdminToken := base32 .StdEncoding .EncodeToString (securecookie .GenerateRandomKey (32 ))
190
167
token := token .New (token .UserToken , "admin" )
@@ -197,40 +174,19 @@ func initStackConfig(data *data) string {
197
174
"install" : true ,
198
175
"hostAndPort" : "postgresql:5432" ,
199
176
"postgresPassword" : postgresPassword ,
200
- "db" : "gimlet_dashboard " ,
201
- "user" : "gimlet_dashboard " ,
177
+ "db" : "gimlet " ,
178
+ "user" : "gimlet " ,
202
179
"password" : dashboardPassword ,
203
180
}
204
- gimletdPostgresConfig := map [string ]interface {}{
205
- "install" : true ,
206
- "hostAndPort" : "postgresql:5432" ,
207
- "postgresPassword" : postgresPassword ,
208
- "db" : "gimletd" ,
209
- "user" : "gimletd" ,
210
- "password" : gimletdPassword ,
211
- }
212
-
213
- data .stackConfig .Config ["gimletd" ] = map [string ]interface {}{
214
- "enabled" : true ,
215
- "environments" : []map [string ]interface {}{{
216
- "name" : "will be set from user input on the ui" ,
217
- "repoPerEnv" : "will be set from user input on the ui" ,
218
- "gitopsRepo" : "will be set from user input on the ui" ,
219
- "deployKey" : string (privateKeyBytes ),
220
- },
221
- },
222
- "adminToken" : gimletdAdminToken ,
223
- "postgresql" : gimletdPostgresConfig ,
224
- }
225
181
226
182
data .stackConfig .Config ["gimletAgent" ] = map [string ]interface {}{
227
183
"enabled" : true ,
228
184
"environment" : "will be set from user input on the ui" ,
229
- "dashboardAddress" : "http://gimlet-dashboard :9000" ,
185
+ "dashboardAddress" : "http://gimlet:9000" ,
230
186
"agentKey" : agentToken ,
231
187
}
232
188
233
- data .stackConfig .Config ["gimletDashboard " ] = map [string ]interface {}{
189
+ data .stackConfig .Config ["gimlet " ] = map [string ]interface {}{
234
190
"enabled" : true ,
235
191
"jwtSecret" : jwtSecret ,
236
192
"gimletdToken" : gimletdSignedAdminToken ,
@@ -239,14 +195,13 @@ func initStackConfig(data *data) string {
239
195
"postgresql" : dashboardPostgresConfig ,
240
196
"gimletdURL" : "http://gimletd:8888" ,
241
197
"host" : fmt .Sprintf ("http://gimlet.%s:%s" , os .Getenv ("HOST" ), "9000" ),
198
+ "adminToken" : gimletdAdminToken ,
242
199
}
243
-
244
- return gimletdPublicKey
245
200
}
246
201
247
202
func setGithubStackConfig (data * data ) {
248
203
data .github = true
249
- gimletDashboardConfig := data .stackConfig .Config ["gimletDashboard " ].(map [string ]interface {})
204
+ gimletDashboardConfig := data .stackConfig .Config ["gimlet " ].(map [string ]interface {})
250
205
251
206
gimletDashboardConfig ["githubOrg" ] = data .appOwner
252
207
gimletDashboardConfig ["githubAppId" ] = data .id
@@ -258,17 +213,16 @@ func setGithubStackConfig(data *data) {
258
213
259
214
func setGitlabStackConfig (data * data , token string ) {
260
215
data .gitlab = true
261
- gimletDashboardConfig := data .stackConfig .Config ["gimletDashboard " ].(map [string ]interface {})
216
+ gimletDashboardConfig := data .stackConfig .Config ["gimlet " ].(map [string ]interface {})
262
217
263
218
gimletDashboardConfig ["gitlabOrg" ] = data .appOwner
264
219
gimletDashboardConfig ["gitlabClientId" ] = data .clientId
265
220
gimletDashboardConfig ["gitlabClientSecret" ] = data .clientSecret
266
221
gimletDashboardConfig ["gitlabAdminToken" ] = token
267
222
gimletDashboardConfig ["gitlabUrl" ] = data .scmURL
268
223
269
- gimletdConfig := data .stackConfig .Config ["gimletd" ].(map [string ]interface {})
270
224
scmHost := strings .Split (data .scmURL , "://" )[1 ]
271
- gimletdConfig ["gitSSHAddressFormat" ] = "git@" + scmHost + ":%s.git"
225
+ gimletDashboardConfig ["gitSSHAddressFormat" ] = "git@" + scmHost + ":%s.git"
272
226
}
273
227
274
228
func getContext (w http.ResponseWriter , r * http.Request ) {
@@ -289,7 +243,6 @@ func getContext(w http.ResponseWriter, r *http.Request) {
289
243
"clientSecret" : data .clientSecret ,
290
244
"pem" : data .pem ,
291
245
"org" : data .appOwner ,
292
- "gimletdPublicKey" : data .gimletdPublicKey ,
293
246
"infraGitopsRepoFileName" : data .infraGitopsRepoFileName ,
294
247
"infraPublicKey" : data .infraPublicKey ,
295
248
"infraSecretFileName" : data .infraSecretFileName ,
@@ -451,8 +404,7 @@ func auth(w http.ResponseWriter, r *http.Request) {
451
404
}
452
405
data .loggedInUser = scmUser .Login
453
406
454
- gimletdPublicKey := initStackConfig (data )
455
- data .gimletdPublicKey = gimletdPublicKey
407
+ initStackConfig (data )
456
408
457
409
data .scmURL = "https://github.com"
458
410
setGithubStackConfig (data )
@@ -508,26 +460,16 @@ func bootstrap(w http.ResponseWriter, r *http.Request) {
508
460
infraRepo := formValues .Get ("infra" )
509
461
appsRepo := formValues .Get ("apps" )
510
462
envName := formValues .Get ("env" )
511
- stackConfigString := formValues .Get ("stackConfig" )
512
- err = json .Unmarshal ([]byte (stackConfigString ), & data .stackConfig .Config )
513
- if err != nil {
514
- panic (err )
515
- }
516
463
repoPerEnv , err := strconv .ParseBool (formValues .Get ("repoPerEnv" ))
517
464
if err != nil {
518
465
panic (err )
519
466
}
520
467
521
- gimletdConfig := data .stackConfig .Config ["gimletd" ].(map [string ]interface {})
522
- environments := gimletdConfig ["environments" ].([]interface {})
523
- envConfig := environments [0 ].(map [string ]interface {})
524
-
525
468
if ! strings .Contains (infraRepo , "/" ) {
526
469
infraRepo = filepath .Join (data .appOwner , infraRepo )
527
470
}
528
471
if ! strings .Contains (appsRepo , "/" ) {
529
472
appsRepo = filepath .Join (data .appOwner , appsRepo )
530
- envConfig ["gitopsRepo" ] = appsRepo
531
473
}
532
474
533
475
data .infraRepo = infraRepo
@@ -619,14 +561,14 @@ func bootstrap(w http.ResponseWriter, r *http.Request) {
619
561
panic (err )
620
562
}
621
563
622
- gimletDashboardConfig := data .stackConfig .Config ["gimletDashboard " ].(map [string ]interface {})
623
- gimletdURL := "http://gimletd .infrastructure.svc.cluster.local:8888"
624
- gimletdSignedAdminToken := gimletDashboardConfig ["gimletdToken" ].(string )
564
+ gimletDashboardConfig := data .stackConfig .Config ["gimlet " ].(map [string ]interface {})
565
+ gimletURL := "http://gimlet .infrastructure.svc.cluster.local:8888"
566
+ gimletSignedAdminToken := gimletDashboardConfig ["gimletdToken" ].(string )
625
567
626
568
notificationsFileName , err := server .BootstrapNotifications (
627
569
gitRepoCache ,
628
- gimletdURL ,
629
- gimletdSignedAdminToken ,
570
+ gimletURL ,
571
+ gimletSignedAdminToken ,
630
572
envName ,
631
573
appsRepo ,
632
574
repoPerEnv ,
@@ -640,6 +582,9 @@ func bootstrap(w http.ResponseWriter, r *http.Request) {
640
582
641
583
gimletDashboardConfig ["bootstrapEnv" ] = fmt .Sprintf ("name=%s&repoPerEnv=%t&infraRepo=%s&appsRepo=%s" , envName , repoPerEnv , infraRepo , appsRepo )
642
584
585
+ gimletAgentConfig := data .stackConfig .Config ["gimletAgent" ].(map [string ]interface {})
586
+ gimletAgentConfig ["environment" ] = envName
587
+
643
588
data .infraGitopsRepoFileName = infraGitopsRepoFileName
644
589
data .infraSecretFileName = infraSecretFileName
645
590
@@ -775,8 +720,7 @@ func gitlabInit(w http.ResponseWriter, r *http.Request) {
775
720
776
721
data .loggedInUser = user .Username
777
722
778
- gimletdPublicKey := initStackConfig (data )
779
- data .gimletdPublicKey = gimletdPublicKey
723
+ initStackConfig (data )
780
724
781
725
data .scmURL = gitlabUrl
782
726
setGitlabStackConfig (data , token )
0 commit comments