@@ -28,6 +28,7 @@ import (
28
28
29
29
securejoin "github.com/cyphar/filepath-securejoin"
30
30
"github.com/fluxcd/pkg/auth/azure"
31
+ "github.com/fluxcd/pkg/auth/github"
31
32
"github.com/fluxcd/pkg/runtime/logger"
32
33
"github.com/go-git/go-git/v5/plumbing/transport"
33
34
corev1 "k8s.io/api/core/v1"
@@ -613,10 +614,11 @@ func (r *GitRepositoryReconciler) reconcileSource(ctx context.Context, sp *patch
613
614
// transport.ProxyOptions object using those settings and then returns it.
614
615
func (r * GitRepositoryReconciler ) getProxyOpts (ctx context.Context , proxySecretName ,
615
616
proxySecretNamespace string ) (* transport.ProxyOptions , error ) {
616
- proxyData , err := r .getSecretData (ctx , proxySecretName , proxySecretNamespace )
617
+ proxySecret , err := r .getSecret (ctx , proxySecretName , proxySecretNamespace )
617
618
if err != nil {
618
619
return nil , fmt .Errorf ("failed to get proxy secret '%s/%s': %w" , proxySecretNamespace , proxySecretName , err )
619
620
}
621
+ proxyData := proxySecret .Data
620
622
address , ok := proxyData ["address" ]
621
623
if ! ok {
622
624
return nil , fmt .Errorf ("invalid proxy secret '%s/%s': key 'address' is missing" , proxySecretNamespace , proxySecretName )
@@ -635,12 +637,14 @@ func (r *GitRepositoryReconciler) getProxyOpts(ctx context.Context, proxySecretN
635
637
// URL and returns it.
636
638
func (r * GitRepositoryReconciler ) getAuthOpts (ctx context.Context , obj * sourcev1.GitRepository , u url.URL ) (* git.AuthOptions , error ) {
637
639
var authData map [string ][]byte
640
+ var authSecret corev1.Secret
638
641
if obj .Spec .SecretRef != nil {
639
642
var err error
640
- authData , err = r .getSecretData (ctx , obj .Spec .SecretRef .Name , obj .GetNamespace ())
643
+ authSecret , err = r .getSecret (ctx , obj .Spec .SecretRef .Name , obj .GetNamespace ())
641
644
if err != nil {
642
645
return nil , fmt .Errorf ("failed to get secret '%s/%s': %w" , obj .GetNamespace (), obj .Spec .SecretRef .Name , err )
643
646
}
647
+ authData = authSecret .Data
644
648
}
645
649
646
650
// Configure authentication strategy to access the source
@@ -650,28 +654,36 @@ func (r *GitRepositoryReconciler) getAuthOpts(ctx context.Context, obj *sourcev1
650
654
}
651
655
652
656
// Configure provider authentication if specified in spec
653
- if obj .GetProvider () == sourcev1 .GitProviderAzure {
657
+ switch obj .GetProvider () {
658
+ case sourcev1 .GitProviderAzure :
654
659
authOpts .ProviderOpts = & git.ProviderOptions {
655
- Name : obj . GetProvider () ,
660
+ Name : sourcev1 . GitProviderAzure ,
656
661
AzureOpts : []azure.OptFunc {
657
662
azure .WithAzureDevOpsScope (),
658
663
},
659
664
}
665
+ case sourcev1 .GitProviderGitHub :
666
+ authOpts .ProviderOpts = & git.ProviderOptions {
667
+ Name : sourcev1 .GitProviderGitHub ,
668
+ GitHubOpts : []github.OptFunc {
669
+ github .WithSecret (authSecret ),
670
+ },
671
+ }
660
672
}
661
673
662
674
return authOpts , nil
663
675
}
664
676
665
- func (r * GitRepositoryReconciler ) getSecretData (ctx context.Context , name , namespace string ) (map [ string ][] byte , error ) {
677
+ func (r * GitRepositoryReconciler ) getSecret (ctx context.Context , name , namespace string ) (corev1. Secret , error ) {
666
678
key := types.NamespacedName {
667
679
Namespace : namespace ,
668
680
Name : name ,
669
681
}
670
682
var secret corev1.Secret
671
683
if err := r .Client .Get (ctx , key , & secret ); err != nil {
672
- return nil , err
684
+ return secret , err
673
685
}
674
- return secret . Data , nil
686
+ return secret , nil
675
687
}
676
688
677
689
// reconcileArtifact archives a new Artifact to the Storage, if the current
0 commit comments