1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17 package gitlab
18
19 import (
20 "fmt"
21 "net/http"
22 "net/url"
23 )
24
25
26
27
28
29
30 type GroupVariablesService struct {
31 client *Client
32 }
33
34
35
36
37
38 type GroupVariable struct {
39 Key string `json:"key"`
40 Value string `json:"value"`
41 VariableType VariableTypeValue `json:"variable_type"`
42 Protected bool `json:"protected"`
43 Masked bool `json:"masked"`
44 Raw bool `json:"raw"`
45 EnvironmentScope string `json:"environment_scope"`
46 Description string `json:"description"`
47 }
48
49 func (v GroupVariable) String() string {
50 return Stringify(v)
51 }
52
53
54
55
56
57
58 type ListGroupVariablesOptions ListOptions
59
60
61
62
63
64 func (s *GroupVariablesService) ListVariables(gid interface{}, opt *ListGroupVariablesOptions, options ...RequestOptionFunc) ([]*GroupVariable, *Response, error) {
65 group, err := parseID(gid)
66 if err != nil {
67 return nil, nil, err
68 }
69 u := fmt.Sprintf("groups/%s/variables", PathEscape(group))
70
71 req, err := s.client.NewRequest(http.MethodGet, u, opt, options)
72 if err != nil {
73 return nil, nil, err
74 }
75
76 var vs []*GroupVariable
77 resp, err := s.client.Do(req, &vs)
78 if err != nil {
79 return nil, resp, err
80 }
81
82 return vs, resp, nil
83 }
84
85
86
87
88
89 func (s *GroupVariablesService) GetVariable(gid interface{}, key string, options ...RequestOptionFunc) (*GroupVariable, *Response, error) {
90 group, err := parseID(gid)
91 if err != nil {
92 return nil, nil, err
93 }
94 u := fmt.Sprintf("groups/%s/variables/%s", PathEscape(group), url.PathEscape(key))
95
96 req, err := s.client.NewRequest(http.MethodGet, u, nil, options)
97 if err != nil {
98 return nil, nil, err
99 }
100
101 v := new(GroupVariable)
102 resp, err := s.client.Do(req, v)
103 if err != nil {
104 return nil, resp, err
105 }
106
107 return v, resp, nil
108 }
109
110
111
112
113
114
115 type CreateGroupVariableOptions struct {
116 Key *string `url:"key,omitempty" json:"key,omitempty"`
117 Value *string `url:"value,omitempty" json:"value,omitempty"`
118 Description *string `url:"description,omitempty" json:"description,omitempty"`
119 EnvironmentScope *string `url:"environment_scope,omitempty" json:"environment_scope,omitempty"`
120 Masked *bool `url:"masked,omitempty" json:"masked,omitempty"`
121 Protected *bool `url:"protected,omitempty" json:"protected,omitempty"`
122 Raw *bool `url:"raw,omitempty" json:"raw,omitempty"`
123 VariableType *VariableTypeValue `url:"variable_type,omitempty" json:"variable_type,omitempty"`
124 }
125
126
127
128
129
130 func (s *GroupVariablesService) CreateVariable(gid interface{}, opt *CreateGroupVariableOptions, options ...RequestOptionFunc) (*GroupVariable, *Response, error) {
131 group, err := parseID(gid)
132 if err != nil {
133 return nil, nil, err
134 }
135 u := fmt.Sprintf("groups/%s/variables", PathEscape(group))
136
137 req, err := s.client.NewRequest(http.MethodPost, u, opt, options)
138 if err != nil {
139 return nil, nil, err
140 }
141
142 v := new(GroupVariable)
143 resp, err := s.client.Do(req, v)
144 if err != nil {
145 return nil, resp, err
146 }
147
148 return v, resp, nil
149 }
150
151
152
153
154
155
156 type UpdateGroupVariableOptions struct {
157 Value *string `url:"value,omitempty" json:"value,omitempty"`
158 Description *string `url:"description,omitempty" json:"description,omitempty"`
159 EnvironmentScope *string `url:"environment_scope,omitempty" json:"environment_scope,omitempty"`
160 Masked *bool `url:"masked,omitempty" json:"masked,omitempty"`
161 Protected *bool `url:"protected,omitempty" json:"protected,omitempty"`
162 Raw *bool `url:"raw,omitempty" json:"raw,omitempty"`
163 VariableType *VariableTypeValue `url:"variable_type,omitempty" json:"variable_type,omitempty"`
164 }
165
166
167
168
169
170
171 func (s *GroupVariablesService) UpdateVariable(gid interface{}, key string, opt *UpdateGroupVariableOptions, options ...RequestOptionFunc) (*GroupVariable, *Response, error) {
172 group, err := parseID(gid)
173 if err != nil {
174 return nil, nil, err
175 }
176 u := fmt.Sprintf("groups/%s/variables/%s", PathEscape(group), url.PathEscape(key))
177
178 req, err := s.client.NewRequest(http.MethodPut, u, opt, options)
179 if err != nil {
180 return nil, nil, err
181 }
182
183 v := new(GroupVariable)
184 resp, err := s.client.Do(req, v)
185 if err != nil {
186 return nil, resp, err
187 }
188
189 return v, resp, nil
190 }
191
192
193
194
195
196 func (s *GroupVariablesService) RemoveVariable(gid interface{}, key string, options ...RequestOptionFunc) (*Response, error) {
197 group, err := parseID(gid)
198 if err != nil {
199 return nil, err
200 }
201 u := fmt.Sprintf("groups/%s/variables/%s", PathEscape(group), url.PathEscape(key))
202
203 req, err := s.client.NewRequest(http.MethodDelete, u, nil, options)
204 if err != nil {
205 return nil, err
206 }
207
208 return s.client.Do(req, nil)
209 }
210
View as plain text