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 ProjectVariablesService struct {
31 client *Client
32 }
33
34
35
36
37
38 type ProjectVariable 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 ProjectVariable) String() string {
50 return Stringify(v)
51 }
52
53
54 type VariableFilter struct {
55 EnvironmentScope string `url:"environment_scope, omitempty" json:"environment_scope,omitempty"`
56 }
57
58
59
60
61
62
63 type ListProjectVariablesOptions ListOptions
64
65
66
67
68
69 func (s *ProjectVariablesService) ListVariables(pid interface{}, opt *ListProjectVariablesOptions, options ...RequestOptionFunc) ([]*ProjectVariable, *Response, error) {
70 project, err := parseID(pid)
71 if err != nil {
72 return nil, nil, err
73 }
74 u := fmt.Sprintf("projects/%s/variables", PathEscape(project))
75
76 req, err := s.client.NewRequest(http.MethodGet, u, opt, options)
77 if err != nil {
78 return nil, nil, err
79 }
80
81 var vs []*ProjectVariable
82 resp, err := s.client.Do(req, &vs)
83 if err != nil {
84 return nil, resp, err
85 }
86
87 return vs, resp, nil
88 }
89
90
91
92
93
94
95 type GetProjectVariableOptions struct {
96 Filter *VariableFilter `url:"filter,omitempty" json:"filter,omitempty"`
97 }
98
99
100
101
102
103 func (s *ProjectVariablesService) GetVariable(pid interface{}, key string, opt *GetProjectVariableOptions, options ...RequestOptionFunc) (*ProjectVariable, *Response, error) {
104 project, err := parseID(pid)
105 if err != nil {
106 return nil, nil, err
107 }
108 u := fmt.Sprintf("projects/%s/variables/%s", PathEscape(project), url.PathEscape(key))
109
110 req, err := s.client.NewRequest(http.MethodGet, u, opt, options)
111 if err != nil {
112 return nil, nil, err
113 }
114
115 v := new(ProjectVariable)
116 resp, err := s.client.Do(req, v)
117 if err != nil {
118 return nil, resp, err
119 }
120
121 return v, resp, nil
122 }
123
124
125
126
127
128
129 type CreateProjectVariableOptions struct {
130 Key *string `url:"key,omitempty" json:"key,omitempty"`
131 Value *string `url:"value,omitempty" json:"value,omitempty"`
132 Description *string `url:"description,omitempty" json:"description,omitempty"`
133 EnvironmentScope *string `url:"environment_scope,omitempty" json:"environment_scope,omitempty"`
134 Masked *bool `url:"masked,omitempty" json:"masked,omitempty"`
135 Protected *bool `url:"protected,omitempty" json:"protected,omitempty"`
136 Raw *bool `url:"raw,omitempty" json:"raw,omitempty"`
137 VariableType *VariableTypeValue `url:"variable_type,omitempty" json:"variable_type,omitempty"`
138 }
139
140
141
142
143
144 func (s *ProjectVariablesService) CreateVariable(pid interface{}, opt *CreateProjectVariableOptions, options ...RequestOptionFunc) (*ProjectVariable, *Response, error) {
145 project, err := parseID(pid)
146 if err != nil {
147 return nil, nil, err
148 }
149 u := fmt.Sprintf("projects/%s/variables", PathEscape(project))
150
151 req, err := s.client.NewRequest(http.MethodPost, u, opt, options)
152 if err != nil {
153 return nil, nil, err
154 }
155
156 v := new(ProjectVariable)
157 resp, err := s.client.Do(req, v)
158 if err != nil {
159 return nil, resp, err
160 }
161
162 return v, resp, nil
163 }
164
165
166
167
168
169
170 type UpdateProjectVariableOptions struct {
171 Value *string `url:"value,omitempty" json:"value,omitempty"`
172 Description *string `url:"description,omitempty" json:"description,omitempty"`
173 EnvironmentScope *string `url:"environment_scope,omitempty" json:"environment_scope,omitempty"`
174 Filter *VariableFilter `url:"filter,omitempty" json:"filter,omitempty"`
175 Masked *bool `url:"masked,omitempty" json:"masked,omitempty"`
176 Protected *bool `url:"protected,omitempty" json:"protected,omitempty"`
177 Raw *bool `url:"raw,omitempty" json:"raw,omitempty"`
178 VariableType *VariableTypeValue `url:"variable_type,omitempty" json:"variable_type,omitempty"`
179 }
180
181
182
183
184
185 func (s *ProjectVariablesService) UpdateVariable(pid interface{}, key string, opt *UpdateProjectVariableOptions, options ...RequestOptionFunc) (*ProjectVariable, *Response, error) {
186 project, err := parseID(pid)
187 if err != nil {
188 return nil, nil, err
189 }
190 u := fmt.Sprintf("projects/%s/variables/%s", PathEscape(project), url.PathEscape(key))
191
192 req, err := s.client.NewRequest(http.MethodPut, u, opt, options)
193 if err != nil {
194 return nil, nil, err
195 }
196
197 v := new(ProjectVariable)
198 resp, err := s.client.Do(req, v)
199 if err != nil {
200 return nil, resp, err
201 }
202
203 return v, resp, nil
204 }
205
206
207
208
209
210
211 type RemoveProjectVariableOptions struct {
212 Filter *VariableFilter `url:"filter,omitempty" json:"filter,omitempty"`
213 }
214
215
216
217
218
219 func (s *ProjectVariablesService) RemoveVariable(pid interface{}, key string, opt *RemoveProjectVariableOptions, options ...RequestOptionFunc) (*Response, error) {
220 project, err := parseID(pid)
221 if err != nil {
222 return nil, err
223 }
224 u := fmt.Sprintf("projects/%s/variables/%s", PathEscape(project), url.PathEscape(key))
225
226 req, err := s.client.NewRequest(http.MethodDelete, u, opt, options)
227 if err != nil {
228 return nil, err
229 }
230
231 return s.client.Do(req, nil)
232 }
233
View as plain text