From b518bae15fe8a6d4287c6aa6f59d897fd785337d Mon Sep 17 00:00:00 2001 From: Gergely Brautigam <182850+Skarlso@users.noreply.github.com> Date: Tue, 26 Nov 2024 08:14:47 +0100 Subject: [PATCH] fix: gitlab empty response (#4152) Signed-off-by: Gergely Brautigam <182850+Skarlso@users.noreply.github.com> --- pkg/provider/gitlab/gitlab.go | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/pkg/provider/gitlab/gitlab.go b/pkg/provider/gitlab/gitlab.go index 5f5c600e3..4e1158ea7 100644 --- a/pkg/provider/gitlab/gitlab.go +++ b/pkg/provider/gitlab/gitlab.go @@ -224,14 +224,22 @@ func (g *gitlabBase) GetSecret(_ context.Context, ref esv1beta1.ExternalSecretDa data, resp, err := g.projectVariablesClient.GetVariable(g.store.ProjectID, ref.Key, vopts) metrics.ObserveAPICall(constants.ProviderGitLab, constants.CallGitLabProjectVariableGet, err) + if err != nil { + return nil, err + } + + if resp == nil { + return nil, errors.New("gitlab response is nil") + } + if !isEmptyOrWildcard(g.store.Environment) && resp.StatusCode == http.StatusNotFound { vopts.Filter.EnvironmentScope = "*" data, resp, err = g.projectVariablesClient.GetVariable(g.store.ProjectID, ref.Key, vopts) metrics.ObserveAPICall(constants.ProviderGitLab, constants.CallGitLabProjectVariableGet, err) } - if resp.StatusCode >= 400 && resp.StatusCode != http.StatusNotFound && err != nil { - return nil, err + if resp.StatusCode >= 400 && resp.StatusCode != http.StatusNotFound { + return nil, fmt.Errorf("gitlab response status code was not OK: %d", resp.StatusCode) } err = g.ResolveGroupIds()