@@ -30,7 +30,10 @@ package commands
3030
3131import (
3232 "context"
33+ "crypto/rand"
34+ "encoding/hex"
3335 "fmt"
36+ "io"
3437 "os"
3538 "strconv"
3639 "strings"
8184 RuntimeInstallOptions struct {
8285 RuntimeName string
8386 RuntimeToken string
87+ RuntimeStoreIV string
8488 IngressHost string
8589 Insecure bool
8690 InstallDemoResources bool
@@ -118,16 +122,16 @@ type (
118122 }
119123
120124 summaryLogLevels string
121- summaryLog struct {
125+ summaryLog struct {
122126 message string
123- level summaryLogLevels
127+ level summaryLogLevels
124128 }
125129)
126130
127131const (
128132 Success summaryLogLevels = "Success"
129- Failed summaryLogLevels = "Failed"
130- Info summaryLogLevels = "Info"
133+ Failed summaryLogLevels = "Failed"
134+ Info summaryLogLevels = "Info"
131135)
132136
133137var summaryArr []summaryLog
@@ -313,14 +317,20 @@ func getComponents(rt *runtime.Runtime, opts *RuntimeInstallOptions) []string {
313317 return componentNames
314318}
315319
316- func createRuntimeOnPlatform (ctx context.Context , opts * model.RuntimeInstallationArgs ) (string , error ) {
320+ func createRuntimeOnPlatform (ctx context.Context , opts * model.RuntimeInstallationArgs ) (string , string , error ) {
317321 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+ }
318325
326+ const IV_LENGTH = 16
327+ iv := make ([]byte , IV_LENGTH )
328+ _ , err = io .ReadFull (rand .Reader , iv )
319329 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 )
321331 }
322332
323- return runtimeCreationResponse .NewAccessToken , nil
333+ return runtimeCreationResponse .NewAccessToken , hex . EncodeToString ( iv ), nil
324334}
325335
326336func RunRuntimeInstall (ctx context.Context , opts * RuntimeInstallOptions ) error {
@@ -353,7 +363,7 @@ func RunRuntimeInstall(ctx context.Context, opts *RuntimeInstallOptions) error {
353363
354364 defer postInstallationHandler (ctx , opts , & err )
355365
356- token , err := createRuntimeOnPlatform (ctx , & model.RuntimeInstallationArgs {
366+ token , iv , err := createRuntimeOnPlatform (ctx , & model.RuntimeInstallationArgs {
357367 RuntimeName : opts .RuntimeName ,
358368 Cluster : server ,
359369 RuntimeVersion : runtimeVersion ,
@@ -367,6 +377,7 @@ func RunRuntimeInstall(ctx context.Context, opts *RuntimeInstallOptions) error {
367377 }
368378
369379 opts .RuntimeToken = token
380+ opts .RuntimeStoreIV = iv
370381 rt .Spec .Cluster = server
371382 rt .Spec .IngressHost = opts .IngressHost
372383 rt .Spec .Repo = opts .InsCloneOpts .Repo
@@ -1155,7 +1166,7 @@ func configureAppProxy(ctx context.Context, opts *RuntimeInstallOptions, rt *run
11551166}
11561167
11571168func 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 )
11591170 if err != nil {
11601171 return fmt .Errorf ("failed to create codefresh token secret: %w" , err )
11611172 }
@@ -1289,7 +1300,7 @@ var getProjectInfoFromFile = func(repofs fs.FS, name string) (*argocdv1alpha1.Ap
12891300 return proj , appSet , nil
12901301}
12911302
1292- func getRuntimeTokenSecret (namespace string , token string ) ([]byte , error ) {
1303+ func getRuntimeTokenSecret (namespace string , token string , iv string ) ([]byte , error ) {
12931304 return yaml .Marshal (& v1.Secret {
12941305 TypeMeta : metav1.TypeMeta {
12951306 APIVersion : "v1" ,
@@ -1300,7 +1311,8 @@ func getRuntimeTokenSecret(namespace string, token string) ([]byte, error) {
13001311 Namespace : namespace ,
13011312 },
13021313 Data : map [string ][]byte {
1303- store .Get ().CFTokenSecretKey : []byte (token ),
1314+ store .Get ().CFTokenSecretKey : []byte (token ),
1315+ store .Get ().CFStoreIVSecretKey : []byte (iv ),
13041316 },
13051317 })
13061318}
@@ -1514,12 +1526,12 @@ func postInstallationHandler(ctx context.Context, opts *RuntimeInstallOptions, e
15141526 log .G (ctx ).Warn ("installation failed, performing installation rollback" )
15151527 err := RunRuntimeUninstall (ctx , & RuntimeUninstallOptions {
15161528 RuntimeName : opts .RuntimeName ,
1517- Timeout : store .Get ().WaitTimeout ,
1518- CloneOpts : opts .InsCloneOpts ,
1529+ Timeout : store .Get ().WaitTimeout ,
1530+ CloneOpts : opts .InsCloneOpts ,
15191531 KubeFactory : opts .KubeFactory ,
1520- SkipChecks : true ,
1521- Force : true ,
1522- FastExit : false ,
1532+ SkipChecks : true ,
1533+ Force : true ,
1534+ FastExit : false ,
15231535 })
15241536 if err != nil {
15251537 log .G (ctx ).Errorf ("installation rollback failed: %w" , err )
@@ -1529,7 +1541,7 @@ func postInstallationHandler(ctx context.Context, opts *RuntimeInstallOptions, e
15291541 printSummaryToUser ()
15301542}
15311543
1532- func appendLogToSummary (message string , err error ){
1544+ func appendLogToSummary (message string , err error ) {
15331545 if err != nil {
15341546 summaryArr = append (summaryArr , summaryLog {message , Failed })
15351547 } else {
@@ -1546,7 +1558,7 @@ func printSummaryToUser() {
15461558 } else {
15471559 fmt .Printf ("%s\n " , summaryArr [i ].message )
15481560 }
1549- }
1561+ }
15501562 //clear array to avoid double printing
15511563 summaryArr = []summaryLog {}
15521564}
0 commit comments