@@ -30,7 +30,10 @@ package commands
30
30
31
31
import (
32
32
"context"
33
+ "crypto/rand"
34
+ "encoding/hex"
33
35
"fmt"
36
+ "io"
34
37
"os"
35
38
"strconv"
36
39
"strings"
81
84
RuntimeInstallOptions struct {
82
85
RuntimeName string
83
86
RuntimeToken string
87
+ RuntimeStoreIV string
84
88
IngressHost string
85
89
Insecure bool
86
90
InstallDemoResources bool
@@ -118,16 +122,16 @@ type (
118
122
}
119
123
120
124
summaryLogLevels string
121
- summaryLog struct {
125
+ summaryLog struct {
122
126
message string
123
- level summaryLogLevels
127
+ level summaryLogLevels
124
128
}
125
129
)
126
130
127
131
const (
128
132
Success summaryLogLevels = "Success"
129
- Failed summaryLogLevels = "Failed"
130
- Info summaryLogLevels = "Info"
133
+ Failed summaryLogLevels = "Failed"
134
+ Info summaryLogLevels = "Info"
131
135
)
132
136
133
137
var summaryArr []summaryLog
@@ -313,14 +317,20 @@ func getComponents(rt *runtime.Runtime, opts *RuntimeInstallOptions) []string {
313
317
return componentNames
314
318
}
315
319
316
- func createRuntimeOnPlatform (ctx context.Context , opts * model.RuntimeInstallationArgs ) (string , error ) {
320
+ func createRuntimeOnPlatform (ctx context.Context , opts * model.RuntimeInstallationArgs ) (string , string , error ) {
317
321
runtimeCreationResponse , err := cfConfig .NewClient ().V2 ().Runtime ().Create (ctx , opts )
322
+ if err != nil {
323
+ return "" , "" , fmt .Errorf ("failed to create a new runtime: %s. Error: %w" , opts .RuntimeName , err )
324
+ }
318
325
326
+ const IV_LENGTH = 16
327
+ iv := make ([]byte , IV_LENGTH )
328
+ _ , err = io .ReadFull (rand .Reader , iv )
319
329
if err != nil {
320
- return "" , fmt .Errorf ("failed to create a new runtime : %s. Error: %w" , opts .RuntimeName , err )
330
+ return "" , "" , fmt .Errorf ("failed to create an initialization vector : %s. Error: %w" , opts .RuntimeName , err )
321
331
}
322
332
323
- return runtimeCreationResponse .NewAccessToken , nil
333
+ return runtimeCreationResponse .NewAccessToken , hex . EncodeToString ( iv ), nil
324
334
}
325
335
326
336
func RunRuntimeInstall (ctx context.Context , opts * RuntimeInstallOptions ) error {
@@ -353,7 +363,7 @@ func RunRuntimeInstall(ctx context.Context, opts *RuntimeInstallOptions) error {
353
363
354
364
defer postInstallationHandler (ctx , opts , & err )
355
365
356
- token , err := createRuntimeOnPlatform (ctx , & model.RuntimeInstallationArgs {
366
+ token , iv , err := createRuntimeOnPlatform (ctx , & model.RuntimeInstallationArgs {
357
367
RuntimeName : opts .RuntimeName ,
358
368
Cluster : server ,
359
369
RuntimeVersion : runtimeVersion ,
@@ -367,6 +377,7 @@ func RunRuntimeInstall(ctx context.Context, opts *RuntimeInstallOptions) error {
367
377
}
368
378
369
379
opts .RuntimeToken = token
380
+ opts .RuntimeStoreIV = iv
370
381
rt .Spec .Cluster = server
371
382
rt .Spec .IngressHost = opts .IngressHost
372
383
rt .Spec .Repo = opts .InsCloneOpts .Repo
@@ -1155,7 +1166,7 @@ func configureAppProxy(ctx context.Context, opts *RuntimeInstallOptions, rt *run
1155
1166
}
1156
1167
1157
1168
func createEventsReporter (ctx context.Context , cloneOpts * git.CloneOptions , opts * RuntimeInstallOptions , rt * runtime.Runtime ) error {
1158
- runtimeTokenSecret , err := getRuntimeTokenSecret (opts .RuntimeName , opts .RuntimeToken )
1169
+ runtimeTokenSecret , err := getRuntimeTokenSecret (opts .RuntimeName , opts .RuntimeToken , opts . RuntimeStoreIV )
1159
1170
if err != nil {
1160
1171
return fmt .Errorf ("failed to create codefresh token secret: %w" , err )
1161
1172
}
@@ -1289,7 +1300,7 @@ var getProjectInfoFromFile = func(repofs fs.FS, name string) (*argocdv1alpha1.Ap
1289
1300
return proj , appSet , nil
1290
1301
}
1291
1302
1292
- func getRuntimeTokenSecret (namespace string , token string ) ([]byte , error ) {
1303
+ func getRuntimeTokenSecret (namespace string , token string , iv string ) ([]byte , error ) {
1293
1304
return yaml .Marshal (& v1.Secret {
1294
1305
TypeMeta : metav1.TypeMeta {
1295
1306
APIVersion : "v1" ,
@@ -1300,7 +1311,8 @@ func getRuntimeTokenSecret(namespace string, token string) ([]byte, error) {
1300
1311
Namespace : namespace ,
1301
1312
},
1302
1313
Data : map [string ][]byte {
1303
- store .Get ().CFTokenSecretKey : []byte (token ),
1314
+ store .Get ().CFTokenSecretKey : []byte (token ),
1315
+ store .Get ().CFStoreIVSecretKey : []byte (iv ),
1304
1316
},
1305
1317
})
1306
1318
}
@@ -1514,12 +1526,12 @@ func postInstallationHandler(ctx context.Context, opts *RuntimeInstallOptions, e
1514
1526
log .G (ctx ).Warn ("installation failed, performing installation rollback" )
1515
1527
err := RunRuntimeUninstall (ctx , & RuntimeUninstallOptions {
1516
1528
RuntimeName : opts .RuntimeName ,
1517
- Timeout : store .Get ().WaitTimeout ,
1518
- CloneOpts : opts .InsCloneOpts ,
1529
+ Timeout : store .Get ().WaitTimeout ,
1530
+ CloneOpts : opts .InsCloneOpts ,
1519
1531
KubeFactory : opts .KubeFactory ,
1520
- SkipChecks : true ,
1521
- Force : true ,
1522
- FastExit : false ,
1532
+ SkipChecks : true ,
1533
+ Force : true ,
1534
+ FastExit : false ,
1523
1535
})
1524
1536
if err != nil {
1525
1537
log .G (ctx ).Errorf ("installation rollback failed: %w" , err )
@@ -1529,7 +1541,7 @@ func postInstallationHandler(ctx context.Context, opts *RuntimeInstallOptions, e
1529
1541
printSummaryToUser ()
1530
1542
}
1531
1543
1532
- func appendLogToSummary (message string , err error ){
1544
+ func appendLogToSummary (message string , err error ) {
1533
1545
if err != nil {
1534
1546
summaryArr = append (summaryArr , summaryLog {message , Failed })
1535
1547
} else {
@@ -1546,7 +1558,7 @@ func printSummaryToUser() {
1546
1558
} else {
1547
1559
fmt .Printf ("%s\n " , summaryArr [i ].message )
1548
1560
}
1549
- }
1561
+ }
1550
1562
//clear array to avoid double printing
1551
1563
summaryArr = []summaryLog {}
1552
1564
}
0 commit comments