Skip to content

Commit 94d1024

Browse files
author
Shivam Mukhade
committed
Fixes condition to use secret referred in Repository CR
this fixes cases when we try to look for secret but it is not set so pac was breaking due to accessing nil so we handle that. Signed-off-by: Shivam Mukhade <[email protected]>
1 parent f4ee846 commit 94d1024

File tree

2 files changed

+9
-3
lines changed

2 files changed

+9
-3
lines changed

pkg/pipelineascode/match.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -59,13 +59,13 @@ func (p *PacRun) matchRepoPR(ctx context.Context) ([]matcher.Match, *v1alpha1.Re
5959
// allow webhook providers users to have a global webhook secret to be used,
6060
// so instead of having to specify their in Repo each time, they use a
6161
// shared one from pac.
62-
if repo.Spec.GitProvider != nil && p.event.InstallationID <= 0 {
62+
if p.event.InstallationID > 0 {
63+
p.event.Provider.WebhookSecret, _ = GetCurrentNSWebhookSecret(ctx, p.k8int)
64+
} else {
6365
err := SecretFromRepository(ctx, p.run, p.k8int, p.vcx.GetConfig(), p.event, repo, p.logger)
6466
if err != nil {
6567
return nil, nil, err
6668
}
67-
} else {
68-
p.event.Provider.WebhookSecret, _ = GetCurrentNSWebhookSecret(ctx, p.k8int)
6969
}
7070

7171
// validate payload for webhook secret

pkg/pipelineascode/secret.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,12 +23,18 @@ const (
2323
// SecretFromRepository grab the secret from the repository CRD
2424
func SecretFromRepository(ctx context.Context, cs *params.Run, k8int kubeinteraction.Interface, config *info.ProviderConfig, event *info.Event, repo *apipac.Repository, logger *zap.SugaredLogger) error {
2525
var err error
26+
if repo.Spec.GitProvider == nil {
27+
return fmt.Errorf("failed to find git_provider details in repository spec: %v/%v", repo.Namespace, repo.Name)
28+
}
2629
if repo.Spec.GitProvider.URL == "" {
2730
repo.Spec.GitProvider.URL = config.APIURL
2831
} else {
2932
event.Provider.URL = repo.Spec.GitProvider.URL
3033
}
3134

35+
if repo.Spec.GitProvider.Secret == nil {
36+
return fmt.Errorf("failed to find secret in git_provider section in repository spec: %v/%v", repo.Namespace, repo.Name)
37+
}
3238
gitProviderSecretKey := repo.Spec.GitProvider.Secret.Key
3339
if gitProviderSecretKey == "" {
3440
gitProviderSecretKey = defaultGitProviderSecretKey

0 commit comments

Comments
 (0)