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:
parent
bd3511601c
commit
5350b03308
1 changed files with 10 additions and 15 deletions
|
@ -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()
|
||||||
|
|
Loading…
Reference in a new issue