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 InstanceVariablesService struct {
31 client *Client
32 }
33
34
35
36
37
38 type InstanceVariable 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 Description string `json:"description"`
46 }
47
48 func (v InstanceVariable) String() string {
49 return Stringify(v)
50 }
51
52
53
54
55
56
57 type ListInstanceVariablesOptions ListOptions
58
59
60
61
62
63 func (s *InstanceVariablesService) ListVariables(opt *ListInstanceVariablesOptions, options ...RequestOptionFunc) ([]*InstanceVariable, *Response, error) {
64 u := "admin/ci/variables"
65
66 req, err := s.client.NewRequest(http.MethodGet, u, opt, options)
67 if err != nil {
68 return nil, nil, err
69 }
70
71 var vs []*InstanceVariable
72 resp, err := s.client.Do(req, &vs)
73 if err != nil {
74 return nil, resp, err
75 }
76
77 return vs, resp, nil
78 }
79
80
81
82
83
84 func (s *InstanceVariablesService) GetVariable(key string, options ...RequestOptionFunc) (*InstanceVariable, *Response, error) {
85 u := fmt.Sprintf("admin/ci/variables/%s", url.PathEscape(key))
86
87 req, err := s.client.NewRequest(http.MethodGet, u, nil, options)
88 if err != nil {
89 return nil, nil, err
90 }
91
92 v := new(InstanceVariable)
93 resp, err := s.client.Do(req, v)
94 if err != nil {
95 return nil, resp, err
96 }
97
98 return v, resp, nil
99 }
100
101
102
103
104
105
106 type CreateInstanceVariableOptions struct {
107 Key *string `url:"key,omitempty" json:"key,omitempty"`
108 Value *string `url:"value,omitempty" json:"value,omitempty"`
109 Description *string `url:"description,omitempty" json:"description,omitempty"`
110 Masked *bool `url:"masked,omitempty" json:"masked,omitempty"`
111 Protected *bool `url:"protected,omitempty" json:"protected,omitempty"`
112 Raw *bool `url:"raw,omitempty" json:"raw,omitempty"`
113 VariableType *VariableTypeValue `url:"variable_type,omitempty" json:"variable_type,omitempty"`
114 }
115
116
117
118
119
120 func (s *InstanceVariablesService) CreateVariable(opt *CreateInstanceVariableOptions, options ...RequestOptionFunc) (*InstanceVariable, *Response, error) {
121 u := "admin/ci/variables"
122
123 req, err := s.client.NewRequest(http.MethodPost, u, opt, options)
124 if err != nil {
125 return nil, nil, err
126 }
127
128 v := new(InstanceVariable)
129 resp, err := s.client.Do(req, v)
130 if err != nil {
131 return nil, resp, err
132 }
133
134 return v, resp, nil
135 }
136
137
138
139
140
141
142 type UpdateInstanceVariableOptions struct {
143 Value *string `url:"value,omitempty" json:"value,omitempty"`
144 Description *string `url:"description,omitempty" json:"description,omitempty"`
145 Masked *bool `url:"masked,omitempty" json:"masked,omitempty"`
146 Protected *bool `url:"protected,omitempty" json:"protected,omitempty"`
147 Raw *bool `url:"raw,omitempty" json:"raw,omitempty"`
148 VariableType *VariableTypeValue `url:"variable_type,omitempty" json:"variable_type,omitempty"`
149 }
150
151
152
153
154
155
156 func (s *InstanceVariablesService) UpdateVariable(key string, opt *UpdateInstanceVariableOptions, options ...RequestOptionFunc) (*InstanceVariable, *Response, error) {
157 u := fmt.Sprintf("admin/ci/variables/%s", url.PathEscape(key))
158
159 req, err := s.client.NewRequest(http.MethodPut, u, opt, options)
160 if err != nil {
161 return nil, nil, err
162 }
163
164 v := new(InstanceVariable)
165 resp, err := s.client.Do(req, v)
166 if err != nil {
167 return nil, resp, err
168 }
169
170 return v, resp, nil
171 }
172
173
174
175
176
177 func (s *InstanceVariablesService) RemoveVariable(key string, options ...RequestOptionFunc) (*Response, error) {
178 u := fmt.Sprintf("admin/ci/variables/%s", url.PathEscape(key))
179
180 req, err := s.client.NewRequest(http.MethodDelete, u, nil, options)
181 if err != nil {
182 return nil, err
183 }
184
185 return s.client.Do(req, nil)
186 }
187
View as plain text