@@ -34,9 +34,9 @@ func (s *secretsRepositoryBackend) CreateRepository(ctx context.Context, reposit
34
34
},
35
35
}
36
36
37
- s .repositoryToSecret (repository , repositorySecret )
37
+ updatedSecret := s .repositoryToSecret (repository , repositorySecret )
38
38
39
- _ , err := s .db .createSecret (ctx , repositorySecret )
39
+ _ , err := s .db .createSecret (ctx , updatedSecret )
40
40
if err != nil {
41
41
if apierrors .IsAlreadyExists (err ) {
42
42
hasLabel , err := s .hasRepoTypeLabel (secName )
@@ -142,9 +142,9 @@ func (s *secretsRepositoryBackend) UpdateRepository(ctx context.Context, reposit
142
142
return nil , err
143
143
}
144
144
145
- s .repositoryToSecret (repository , repositorySecret )
145
+ updatedSecret := s .repositoryToSecret (repository , repositorySecret )
146
146
147
- _ , err = s .db .kubeclientset .CoreV1 ().Secrets (s .db .ns ).Update (ctx , repositorySecret , metav1.UpdateOptions {})
147
+ _ , err = s .db .kubeclientset .CoreV1 ().Secrets (s .db .ns ).Update (ctx , updatedSecret , metav1.UpdateOptions {})
148
148
if err != nil {
149
149
return nil , err
150
150
}
@@ -187,9 +187,9 @@ func (s *secretsRepositoryBackend) CreateRepoCreds(ctx context.Context, repoCred
187
187
},
188
188
}
189
189
190
- repoCredsToSecret (repoCreds , repoCredsSecret )
190
+ updatedSecret := repoCredsToSecret (repoCreds , repoCredsSecret )
191
191
192
- _ , err := s .db .createSecret (ctx , repoCredsSecret )
192
+ _ , err := s .db .createSecret (ctx , updatedSecret )
193
193
if err != nil {
194
194
if apierrors .IsAlreadyExists (err ) {
195
195
return nil , status .Errorf (codes .AlreadyExists , "repository credentials %q already exists" , repoCreds .URL )
@@ -237,9 +237,9 @@ func (s *secretsRepositoryBackend) UpdateRepoCreds(ctx context.Context, repoCred
237
237
return nil , err
238
238
}
239
239
240
- repoCredsToSecret (repoCreds , repoCredsSecret )
240
+ updatedSecret := repoCredsToSecret (repoCreds , repoCredsSecret )
241
241
242
- repoCredsSecret , err = s .db .kubeclientset .CoreV1 ().Secrets (s .db .ns ).Update (ctx , repoCredsSecret , metav1.UpdateOptions {})
242
+ repoCredsSecret , err = s .db .kubeclientset .CoreV1 ().Secrets (s .db .ns ).Update (ctx , updatedSecret , metav1.UpdateOptions {})
243
243
if err != nil {
244
244
return nil , err
245
245
}
@@ -323,73 +323,75 @@ func (s *secretsRepositoryBackend) GetAllOCIRepoCreds(_ context.Context) ([]*app
323
323
}
324
324
325
325
func secretToRepository (secret * corev1.Secret ) (* appsv1.Repository , error ) {
326
+ secretCopy := secret .DeepCopy ()
327
+
326
328
repository := & appsv1.Repository {
327
- Name : string (secret .Data ["name" ]),
328
- Repo : string (secret .Data ["url" ]),
329
- Username : string (secret .Data ["username" ]),
330
- Password : string (secret .Data ["password" ]),
331
- BearerToken : string (secret .Data ["bearerToken" ]),
332
- SSHPrivateKey : string (secret .Data ["sshPrivateKey" ]),
333
- TLSClientCertData : string (secret .Data ["tlsClientCertData" ]),
334
- TLSClientCertKey : string (secret .Data ["tlsClientCertKey" ]),
335
- Type : string (secret .Data ["type" ]),
336
- GithubAppPrivateKey : string (secret .Data ["githubAppPrivateKey" ]),
337
- GitHubAppEnterpriseBaseURL : string (secret .Data ["githubAppEnterpriseBaseUrl" ]),
338
- Proxy : string (secret .Data ["proxy" ]),
339
- NoProxy : string (secret .Data ["noProxy" ]),
340
- Project : string (secret .Data ["project" ]),
341
- GCPServiceAccountKey : string (secret .Data ["gcpServiceAccountKey" ]),
342
- }
343
-
344
- insecureIgnoreHostKey , err := boolOrFalse (secret , "insecureIgnoreHostKey" )
329
+ Name : string (secretCopy .Data ["name" ]),
330
+ Repo : string (secretCopy .Data ["url" ]),
331
+ Username : string (secretCopy .Data ["username" ]),
332
+ Password : string (secretCopy .Data ["password" ]),
333
+ BearerToken : string (secretCopy .Data ["bearerToken" ]),
334
+ SSHPrivateKey : string (secretCopy .Data ["sshPrivateKey" ]),
335
+ TLSClientCertData : string (secretCopy .Data ["tlsClientCertData" ]),
336
+ TLSClientCertKey : string (secretCopy .Data ["tlsClientCertKey" ]),
337
+ Type : string (secretCopy .Data ["type" ]),
338
+ GithubAppPrivateKey : string (secretCopy .Data ["githubAppPrivateKey" ]),
339
+ GitHubAppEnterpriseBaseURL : string (secretCopy .Data ["githubAppEnterpriseBaseUrl" ]),
340
+ Proxy : string (secretCopy .Data ["proxy" ]),
341
+ NoProxy : string (secretCopy .Data ["noProxy" ]),
342
+ Project : string (secretCopy .Data ["project" ]),
343
+ GCPServiceAccountKey : string (secretCopy .Data ["gcpServiceAccountKey" ]),
344
+ }
345
+
346
+ insecureIgnoreHostKey , err := boolOrFalse (secretCopy , "insecureIgnoreHostKey" )
345
347
if err != nil {
346
348
return repository , err
347
349
}
348
350
repository .InsecureIgnoreHostKey = insecureIgnoreHostKey
349
351
350
- insecure , err := boolOrFalse (secret , "insecure" )
352
+ insecure , err := boolOrFalse (secretCopy , "insecure" )
351
353
if err != nil {
352
354
return repository , err
353
355
}
354
356
repository .Insecure = insecure
355
357
356
- enableLfs , err := boolOrFalse (secret , "enableLfs" )
358
+ enableLfs , err := boolOrFalse (secretCopy , "enableLfs" )
357
359
if err != nil {
358
360
return repository , err
359
361
}
360
362
repository .EnableLFS = enableLfs
361
363
362
- enableOCI , err := boolOrFalse (secret , "enableOCI" )
364
+ enableOCI , err := boolOrFalse (secretCopy , "enableOCI" )
363
365
if err != nil {
364
366
return repository , err
365
367
}
366
368
repository .EnableOCI = enableOCI
367
369
368
- insecureOCIForceHTTP , err := boolOrFalse (secret , "insecureOCIForceHttp" )
370
+ insecureOCIForceHTTP , err := boolOrFalse (secretCopy , "insecureOCIForceHttp" )
369
371
if err != nil {
370
372
return repository , err
371
373
}
372
374
repository .InsecureOCIForceHttp = insecureOCIForceHTTP
373
375
374
- githubAppID , err := intOrZero (secret , "githubAppID" )
376
+ githubAppID , err := intOrZero (secretCopy , "githubAppID" )
375
377
if err != nil {
376
378
return repository , err
377
379
}
378
380
repository .GithubAppId = githubAppID
379
381
380
- githubAppInstallationID , err := intOrZero (secret , "githubAppInstallationID" )
382
+ githubAppInstallationID , err := intOrZero (secretCopy , "githubAppInstallationID" )
381
383
if err != nil {
382
384
return repository , err
383
385
}
384
386
repository .GithubAppInstallationId = githubAppInstallationID
385
387
386
- forceBasicAuth , err := boolOrFalse (secret , "forceHttpBasicAuth" )
388
+ forceBasicAuth , err := boolOrFalse (secretCopy , "forceHttpBasicAuth" )
387
389
if err != nil {
388
390
return repository , err
389
391
}
390
392
repository .ForceHttpBasicAuth = forceBasicAuth
391
393
392
- useAzureWorkloadIdentity , err := boolOrFalse (secret , "useAzureWorkloadIdentity" )
394
+ useAzureWorkloadIdentity , err := boolOrFalse (secretCopy , "useAzureWorkloadIdentity" )
393
395
if err != nil {
394
396
return repository , err
395
397
}
@@ -398,86 +400,92 @@ func secretToRepository(secret *corev1.Secret) (*appsv1.Repository, error) {
398
400
return repository , nil
399
401
}
400
402
401
- func (s * secretsRepositoryBackend ) repositoryToSecret (repository * appsv1.Repository , secret * corev1.Secret ) {
402
- if secret .Data == nil {
403
- secret .Data = make (map [string ][]byte )
404
- }
405
-
406
- updateSecretString (secret , "name" , repository .Name )
407
- updateSecretString (secret , "project" , repository .Project )
408
- updateSecretString (secret , "url" , repository .Repo )
409
- updateSecretString (secret , "username" , repository .Username )
410
- updateSecretString (secret , "password" , repository .Password )
411
- updateSecretString (secret , "bearerToken" , repository .BearerToken )
412
- updateSecretString (secret , "sshPrivateKey" , repository .SSHPrivateKey )
413
- updateSecretBool (secret , "enableOCI" , repository .EnableOCI )
414
- updateSecretBool (secret , "insecureOCIForceHttp" , repository .InsecureOCIForceHttp )
415
- updateSecretString (secret , "tlsClientCertData" , repository .TLSClientCertData )
416
- updateSecretString (secret , "tlsClientCertKey" , repository .TLSClientCertKey )
417
- updateSecretString (secret , "type" , repository .Type )
418
- updateSecretString (secret , "githubAppPrivateKey" , repository .GithubAppPrivateKey )
419
- updateSecretInt (secret , "githubAppID" , repository .GithubAppId )
420
- updateSecretInt (secret , "githubAppInstallationID" , repository .GithubAppInstallationId )
421
- updateSecretString (secret , "githubAppEnterpriseBaseUrl" , repository .GitHubAppEnterpriseBaseURL )
422
- updateSecretBool (secret , "insecureIgnoreHostKey" , repository .InsecureIgnoreHostKey )
423
- updateSecretBool (secret , "insecure" , repository .Insecure )
424
- updateSecretBool (secret , "enableLfs" , repository .EnableLFS )
425
- updateSecretString (secret , "proxy" , repository .Proxy )
426
- updateSecretString (secret , "noProxy" , repository .NoProxy )
427
- updateSecretString (secret , "gcpServiceAccountKey" , repository .GCPServiceAccountKey )
428
- updateSecretBool (secret , "forceHttpBasicAuth" , repository .ForceHttpBasicAuth )
429
- updateSecretBool (secret , "useAzureWorkloadIdentity" , repository .UseAzureWorkloadIdentity )
430
- addSecretMetadata (secret , s .getSecretType ())
403
+ func (s * secretsRepositoryBackend ) repositoryToSecret (repository * appsv1.Repository , secret * corev1.Secret ) * corev1.Secret {
404
+ secretCopy := secret .DeepCopy ()
405
+
406
+ if secretCopy .Data == nil {
407
+ secretCopy .Data = make (map [string ][]byte )
408
+ }
409
+
410
+ updateSecretString (secretCopy , "name" , repository .Name )
411
+ updateSecretString (secretCopy , "project" , repository .Project )
412
+ updateSecretString (secretCopy , "url" , repository .Repo )
413
+ updateSecretString (secretCopy , "username" , repository .Username )
414
+ updateSecretString (secretCopy , "password" , repository .Password )
415
+ updateSecretString (secretCopy , "bearerToken" , repository .BearerToken )
416
+ updateSecretString (secretCopy , "sshPrivateKey" , repository .SSHPrivateKey )
417
+ updateSecretBool (secretCopy , "enableOCI" , repository .EnableOCI )
418
+ updateSecretBool (secretCopy , "insecureOCIForceHttp" , repository .InsecureOCIForceHttp )
419
+ updateSecretString (secretCopy , "tlsClientCertData" , repository .TLSClientCertData )
420
+ updateSecretString (secretCopy , "tlsClientCertKey" , repository .TLSClientCertKey )
421
+ updateSecretString (secretCopy , "type" , repository .Type )
422
+ updateSecretString (secretCopy , "githubAppPrivateKey" , repository .GithubAppPrivateKey )
423
+ updateSecretInt (secretCopy , "githubAppID" , repository .GithubAppId )
424
+ updateSecretInt (secretCopy , "githubAppInstallationID" , repository .GithubAppInstallationId )
425
+ updateSecretString (secretCopy , "githubAppEnterpriseBaseUrl" , repository .GitHubAppEnterpriseBaseURL )
426
+ updateSecretBool (secretCopy , "insecureIgnoreHostKey" , repository .InsecureIgnoreHostKey )
427
+ updateSecretBool (secretCopy , "insecure" , repository .Insecure )
428
+ updateSecretBool (secretCopy , "enableLfs" , repository .EnableLFS )
429
+ updateSecretString (secretCopy , "proxy" , repository .Proxy )
430
+ updateSecretString (secretCopy , "noProxy" , repository .NoProxy )
431
+ updateSecretString (secretCopy , "gcpServiceAccountKey" , repository .GCPServiceAccountKey )
432
+ updateSecretBool (secretCopy , "forceHttpBasicAuth" , repository .ForceHttpBasicAuth )
433
+ updateSecretBool (secretCopy , "useAzureWorkloadIdentity" , repository .UseAzureWorkloadIdentity )
434
+ addSecretMetadata (secretCopy , s .getSecretType ())
435
+
436
+ return secretCopy
431
437
}
432
438
433
439
func (s * secretsRepositoryBackend ) secretToRepoCred (secret * corev1.Secret ) (* appsv1.RepoCreds , error ) {
440
+ secretCopy := secret .DeepCopy ()
441
+
434
442
repository := & appsv1.RepoCreds {
435
- URL : string (secret .Data ["url" ]),
436
- Username : string (secret .Data ["username" ]),
437
- Password : string (secret .Data ["password" ]),
438
- BearerToken : string (secret .Data ["bearerToken" ]),
439
- SSHPrivateKey : string (secret .Data ["sshPrivateKey" ]),
440
- TLSClientCertData : string (secret .Data ["tlsClientCertData" ]),
441
- TLSClientCertKey : string (secret .Data ["tlsClientCertKey" ]),
442
- Type : string (secret .Data ["type" ]),
443
- GithubAppPrivateKey : string (secret .Data ["githubAppPrivateKey" ]),
444
- GitHubAppEnterpriseBaseURL : string (secret .Data ["githubAppEnterpriseBaseUrl" ]),
445
- GCPServiceAccountKey : string (secret .Data ["gcpServiceAccountKey" ]),
446
- Proxy : string (secret .Data ["proxy" ]),
447
- NoProxy : string (secret .Data ["noProxy" ]),
448
- }
449
-
450
- enableOCI , err := boolOrFalse (secret , "enableOCI" )
443
+ URL : string (secretCopy .Data ["url" ]),
444
+ Username : string (secretCopy .Data ["username" ]),
445
+ Password : string (secretCopy .Data ["password" ]),
446
+ BearerToken : string (secretCopy .Data ["bearerToken" ]),
447
+ SSHPrivateKey : string (secretCopy .Data ["sshPrivateKey" ]),
448
+ TLSClientCertData : string (secretCopy .Data ["tlsClientCertData" ]),
449
+ TLSClientCertKey : string (secretCopy .Data ["tlsClientCertKey" ]),
450
+ Type : string (secretCopy .Data ["type" ]),
451
+ GithubAppPrivateKey : string (secretCopy .Data ["githubAppPrivateKey" ]),
452
+ GitHubAppEnterpriseBaseURL : string (secretCopy .Data ["githubAppEnterpriseBaseUrl" ]),
453
+ GCPServiceAccountKey : string (secretCopy .Data ["gcpServiceAccountKey" ]),
454
+ Proxy : string (secretCopy .Data ["proxy" ]),
455
+ NoProxy : string (secretCopy .Data ["noProxy" ]),
456
+ }
457
+
458
+ enableOCI , err := boolOrFalse (secretCopy , "enableOCI" )
451
459
if err != nil {
452
460
return repository , err
453
461
}
454
462
repository .EnableOCI = enableOCI
455
463
456
- insecureOCIForceHTTP , err := boolOrFalse (secret , "insecureOCIForceHttp" )
464
+ insecureOCIForceHTTP , err := boolOrFalse (secretCopy , "insecureOCIForceHttp" )
457
465
if err != nil {
458
466
return repository , err
459
467
}
460
468
repository .InsecureOCIForceHttp = insecureOCIForceHTTP
461
469
462
- githubAppID , err := intOrZero (secret , "githubAppID" )
470
+ githubAppID , err := intOrZero (secretCopy , "githubAppID" )
463
471
if err != nil {
464
472
return repository , err
465
473
}
466
474
repository .GithubAppId = githubAppID
467
475
468
- githubAppInstallationID , err := intOrZero (secret , "githubAppInstallationID" )
476
+ githubAppInstallationID , err := intOrZero (secretCopy , "githubAppInstallationID" )
469
477
if err != nil {
470
478
return repository , err
471
479
}
472
480
repository .GithubAppInstallationId = githubAppInstallationID
473
481
474
- forceBasicAuth , err := boolOrFalse (secret , "forceHttpBasicAuth" )
482
+ forceBasicAuth , err := boolOrFalse (secretCopy , "forceHttpBasicAuth" )
475
483
if err != nil {
476
484
return repository , err
477
485
}
478
486
repository .ForceHttpBasicAuth = forceBasicAuth
479
487
480
- useAzureWorkloadIdentity , err := boolOrFalse (secret , "useAzureWorkloadIdentity" )
488
+ useAzureWorkloadIdentity , err := boolOrFalse (secretCopy , "useAzureWorkloadIdentity" )
481
489
if err != nil {
482
490
return repository , err
483
491
}
@@ -486,31 +494,35 @@ func (s *secretsRepositoryBackend) secretToRepoCred(secret *corev1.Secret) (*app
486
494
return repository , nil
487
495
}
488
496
489
- func repoCredsToSecret (repoCreds * appsv1.RepoCreds , secret * corev1.Secret ) {
490
- if secret .Data == nil {
491
- secret .Data = make (map [string ][]byte )
492
- }
493
-
494
- updateSecretString (secret , "url" , repoCreds .URL )
495
- updateSecretString (secret , "username" , repoCreds .Username )
496
- updateSecretString (secret , "password" , repoCreds .Password )
497
- updateSecretString (secret , "bearerToken" , repoCreds .BearerToken )
498
- updateSecretString (secret , "sshPrivateKey" , repoCreds .SSHPrivateKey )
499
- updateSecretBool (secret , "enableOCI" , repoCreds .EnableOCI )
500
- updateSecretBool (secret , "insecureOCIForceHttp" , repoCreds .InsecureOCIForceHttp )
501
- updateSecretString (secret , "tlsClientCertData" , repoCreds .TLSClientCertData )
502
- updateSecretString (secret , "tlsClientCertKey" , repoCreds .TLSClientCertKey )
503
- updateSecretString (secret , "type" , repoCreds .Type )
504
- updateSecretString (secret , "githubAppPrivateKey" , repoCreds .GithubAppPrivateKey )
505
- updateSecretInt (secret , "githubAppID" , repoCreds .GithubAppId )
506
- updateSecretInt (secret , "githubAppInstallationID" , repoCreds .GithubAppInstallationId )
507
- updateSecretString (secret , "githubAppEnterpriseBaseUrl" , repoCreds .GitHubAppEnterpriseBaseURL )
508
- updateSecretString (secret , "gcpServiceAccountKey" , repoCreds .GCPServiceAccountKey )
509
- updateSecretString (secret , "proxy" , repoCreds .Proxy )
510
- updateSecretString (secret , "noProxy" , repoCreds .NoProxy )
511
- updateSecretBool (secret , "forceHttpBasicAuth" , repoCreds .ForceHttpBasicAuth )
512
- updateSecretBool (secret , "useAzureWorkloadIdentity" , repoCreds .UseAzureWorkloadIdentity )
513
- addSecretMetadata (secret , common .LabelValueSecretTypeRepoCreds )
497
+ func repoCredsToSecret (repoCreds * appsv1.RepoCreds , secret * corev1.Secret ) * corev1.Secret {
498
+ secretCopy := secret .DeepCopy ()
499
+
500
+ if secretCopy .Data == nil {
501
+ secretCopy .Data = make (map [string ][]byte )
502
+ }
503
+
504
+ updateSecretString (secretCopy , "url" , repoCreds .URL )
505
+ updateSecretString (secretCopy , "username" , repoCreds .Username )
506
+ updateSecretString (secretCopy , "password" , repoCreds .Password )
507
+ updateSecretString (secretCopy , "bearerToken" , repoCreds .BearerToken )
508
+ updateSecretString (secretCopy , "sshPrivateKey" , repoCreds .SSHPrivateKey )
509
+ updateSecretBool (secretCopy , "enableOCI" , repoCreds .EnableOCI )
510
+ updateSecretBool (secretCopy , "insecureOCIForceHttp" , repoCreds .InsecureOCIForceHttp )
511
+ updateSecretString (secretCopy , "tlsClientCertData" , repoCreds .TLSClientCertData )
512
+ updateSecretString (secretCopy , "tlsClientCertKey" , repoCreds .TLSClientCertKey )
513
+ updateSecretString (secretCopy , "type" , repoCreds .Type )
514
+ updateSecretString (secretCopy , "githubAppPrivateKey" , repoCreds .GithubAppPrivateKey )
515
+ updateSecretInt (secretCopy , "githubAppID" , repoCreds .GithubAppId )
516
+ updateSecretInt (secretCopy , "githubAppInstallationID" , repoCreds .GithubAppInstallationId )
517
+ updateSecretString (secretCopy , "githubAppEnterpriseBaseUrl" , repoCreds .GitHubAppEnterpriseBaseURL )
518
+ updateSecretString (secretCopy , "gcpServiceAccountKey" , repoCreds .GCPServiceAccountKey )
519
+ updateSecretString (secretCopy , "proxy" , repoCreds .Proxy )
520
+ updateSecretString (secretCopy , "noProxy" , repoCreds .NoProxy )
521
+ updateSecretBool (secretCopy , "forceHttpBasicAuth" , repoCreds .ForceHttpBasicAuth )
522
+ updateSecretBool (secretCopy , "useAzureWorkloadIdentity" , repoCreds .UseAzureWorkloadIdentity )
523
+ addSecretMetadata (secretCopy , common .LabelValueSecretTypeRepoCreds )
524
+
525
+ return secretCopy
514
526
}
515
527
516
528
func (s * secretsRepositoryBackend ) getRepositorySecret (repoURL , project string , allowFallback bool ) (* corev1.Secret , error ) {
0 commit comments