1
0
Fork 0
mirror of https://github.com/external-secrets/external-secrets.git synced 2024-12-14 11:57:59 +00:00

fix: error handling for gitlab variable fetch (#4177)

This commit is contained in:
Gergely Brautigam 2024-12-05 15:12:34 +01:00 committed by GitHub
parent bd3511601c
commit 5350b03308
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -225,21 +225,16 @@ func (g *gitlabBase) GetSecret(_ context.Context, ref esv1beta1.ExternalSecretDa
data, resp, err := g.projectVariablesClient.GetVariable(g.store.ProjectID, ref.Key, vopts) data, resp, err := g.projectVariablesClient.GetVariable(g.store.ProjectID, ref.Key, vopts)
metrics.ObserveAPICall(constants.ProviderGitLab, constants.CallGitLabProjectVariableGet, err) metrics.ObserveAPICall(constants.ProviderGitLab, constants.CallGitLabProjectVariableGet, err)
if err != nil { if err != nil {
return nil, err if resp != nil && resp.StatusCode == http.StatusNotFound && !isEmptyOrWildcard(g.store.Environment) {
}
if resp == nil {
return nil, errors.New("gitlab response is nil")
}
if !isEmptyOrWildcard(g.store.Environment) && resp.StatusCode == http.StatusNotFound {
vopts.Filter.EnvironmentScope = "*" vopts.Filter.EnvironmentScope = "*"
data, resp, err = g.projectVariablesClient.GetVariable(g.store.ProjectID, ref.Key, vopts) data, resp, err = g.projectVariablesClient.GetVariable(g.store.ProjectID, ref.Key, vopts)
metrics.ObserveAPICall(constants.ProviderGitLab, constants.CallGitLabProjectVariableGet, err) metrics.ObserveAPICall(constants.ProviderGitLab, constants.CallGitLabProjectVariableGet, err)
if err != nil || resp == nil {
return nil, fmt.Errorf("error getting variable %s from GitLab: %w", ref.Key, err)
}
} else {
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() err = g.ResolveGroupIds()