2021-01-10 12:08:40 +00:00
|
|
|
package api
|
|
|
|
|
2021-11-03 16:26:13 +00:00
|
|
|
import (
|
|
|
|
"github.com/hashicorp/go-retryablehttp"
|
|
|
|
|
|
|
|
"github.com/xanzy/go-gitlab"
|
|
|
|
)
|
2021-01-10 12:08:40 +00:00
|
|
|
|
|
|
|
var CreateProjectVariable = func(client *gitlab.Client, projectID interface{}, opts *gitlab.CreateProjectVariableOptions) (*gitlab.ProjectVariable, error) {
|
|
|
|
if client == nil {
|
|
|
|
client = apiClient.Lab()
|
|
|
|
}
|
|
|
|
vars, _, err := client.ProjectVariables.CreateVariable(projectID, opts)
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
|
|
|
return vars, nil
|
|
|
|
}
|
|
|
|
|
2021-08-02 05:38:16 +00:00
|
|
|
var ListProjectVariables = func(client *gitlab.Client, projectID interface{}, opts *gitlab.ListProjectVariablesOptions) ([]*gitlab.ProjectVariable, error) {
|
|
|
|
if client == nil {
|
|
|
|
client = apiClient.Lab()
|
|
|
|
}
|
|
|
|
vars, _, err := client.ProjectVariables.ListVariables(projectID, opts)
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
|
|
|
return vars, nil
|
|
|
|
}
|
|
|
|
|
2023-01-18 18:18:24 +00:00
|
|
|
var GetProjectVariable = func(client *gitlab.Client, projectID interface{}, key string, scope string) (*gitlab.ProjectVariable, error) {
|
2022-09-19 18:04:54 +00:00
|
|
|
if client == nil {
|
|
|
|
client = apiClient.Lab()
|
|
|
|
}
|
2022-10-04 19:29:02 +00:00
|
|
|
|
2023-01-18 18:18:24 +00:00
|
|
|
reqOpts := &gitlab.GetProjectVariableOptions{
|
|
|
|
Filter: &gitlab.VariableFilter{
|
|
|
|
EnvironmentScope: scope,
|
|
|
|
},
|
|
|
|
}
|
2022-10-04 19:29:02 +00:00
|
|
|
vars, _, err := client.ProjectVariables.GetVariable(projectID, key, reqOpts)
|
2022-09-19 18:04:54 +00:00
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
|
|
|
return vars, nil
|
|
|
|
}
|
|
|
|
|
2021-11-03 16:26:13 +00:00
|
|
|
var DeleteProjectVariable = func(client *gitlab.Client, projectID interface{}, key string, scope string) error {
|
|
|
|
if client == nil {
|
|
|
|
client = apiClient.Lab()
|
|
|
|
}
|
|
|
|
|
2022-10-04 19:29:02 +00:00
|
|
|
reqOpts := &gitlab.RemoveProjectVariableOptions{
|
|
|
|
Filter: &gitlab.VariableFilter{
|
|
|
|
EnvironmentScope: scope,
|
|
|
|
},
|
2021-11-03 16:26:13 +00:00
|
|
|
}
|
2022-10-04 19:29:02 +00:00
|
|
|
_, err := client.ProjectVariables.RemoveVariable(projectID, key, reqOpts)
|
2021-11-03 16:26:13 +00:00
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2021-11-18 14:49:48 +00:00
|
|
|
var UpdateProjectVariable = func(client *gitlab.Client, projectID interface{}, key string, opts *gitlab.UpdateProjectVariableOptions) (*gitlab.ProjectVariable, error) {
|
|
|
|
if client == nil {
|
|
|
|
client = apiClient.Lab()
|
|
|
|
}
|
|
|
|
|
2022-11-17 18:36:09 +00:00
|
|
|
filter := func(request *retryablehttp.Request) error {
|
2021-11-18 14:49:48 +00:00
|
|
|
q := request.URL.Query()
|
|
|
|
q.Add("filter[environment_scope]", *opts.EnvironmentScope)
|
|
|
|
|
|
|
|
request.URL.RawQuery = q.Encode()
|
|
|
|
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
vars, _, err := client.ProjectVariables.UpdateVariable(projectID, key, opts, filter)
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
|
|
|
return vars, nil
|
|
|
|
}
|
|
|
|
|
2021-08-02 05:38:16 +00:00
|
|
|
var ListGroupVariables = func(client *gitlab.Client, groupID interface{}, opts *gitlab.ListGroupVariablesOptions) ([]*gitlab.GroupVariable, error) {
|
|
|
|
if client == nil {
|
|
|
|
client = apiClient.Lab()
|
|
|
|
}
|
|
|
|
vars, _, err := client.GroupVariables.ListVariables(groupID, opts)
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
|
|
|
return vars, nil
|
|
|
|
}
|
|
|
|
|
2021-01-10 12:08:40 +00:00
|
|
|
var CreateGroupVariable = func(client *gitlab.Client, groupID interface{}, opts *gitlab.CreateGroupVariableOptions) (*gitlab.GroupVariable, error) {
|
|
|
|
if client == nil {
|
|
|
|
client = apiClient.Lab()
|
|
|
|
}
|
|
|
|
vars, _, err := client.GroupVariables.CreateVariable(groupID, opts)
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
|
|
|
return vars, nil
|
|
|
|
}
|
2021-11-03 16:26:13 +00:00
|
|
|
|
2022-09-19 18:04:54 +00:00
|
|
|
var GetGroupVariable = func(client *gitlab.Client, groupID interface{}, key string, opts *gitlab.RequestOptionFunc) (*gitlab.GroupVariable, error) {
|
|
|
|
if client == nil {
|
|
|
|
client = apiClient.Lab()
|
|
|
|
}
|
|
|
|
vars, _, err := client.GroupVariables.GetVariable(groupID, key)
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
|
|
|
return vars, nil
|
|
|
|
}
|
|
|
|
|
2021-11-03 16:26:13 +00:00
|
|
|
var DeleteGroupVariable = func(client *gitlab.Client, groupID interface{}, key string) error {
|
|
|
|
if client == nil {
|
|
|
|
client = apiClient.Lab()
|
|
|
|
}
|
|
|
|
|
|
|
|
_, err := client.GroupVariables.RemoveVariable(groupID, key)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
return nil
|
|
|
|
}
|
2021-11-18 14:49:48 +00:00
|
|
|
|
|
|
|
var UpdateGroupVariable = func(client *gitlab.Client, groupID interface{}, key string, opts *gitlab.UpdateGroupVariableOptions) (*gitlab.GroupVariable, error) {
|
|
|
|
if client == nil {
|
|
|
|
client = apiClient.Lab()
|
|
|
|
}
|
|
|
|
|
|
|
|
vars, _, err := client.GroupVariables.UpdateVariable(groupID, key, opts)
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
|
|
|
return vars, nil
|
|
|
|
}
|