terraform-enterprise-client 0.0.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/LICENSE +353 -0
- data/README.md +60 -0
- data/lib/terraform-enterprise-client.rb +93 -0
- data/lib/terraform-enterprise-command-line.rb +21 -0
- data/lib/terraform-enterprise/commands/command.rb +42 -0
- data/lib/terraform-enterprise/commands/oauth_tokens_command.rb +17 -0
- data/lib/terraform-enterprise/commands/organizations_command.rb +30 -0
- data/lib/terraform-enterprise/commands/workspaces_command.rb +81 -0
- data/lib/terraform-enterprise/resources/oauth-tokens.rb +9 -0
- data/lib/terraform-enterprise/resources/organizations.rb +26 -0
- data/lib/terraform-enterprise/resources/workspaces.rb +43 -0
- data/lib/terraform-enterprise/resources_client.rb +8 -0
- data/lib/terraform-enterprise/version.rb +3 -0
- metadata +99 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: dd3bfe45c66283bcefba3424b90aa6200f733bcb5c8fff5c641b151171154cd7
|
4
|
+
data.tar.gz: 28d343ca7f4ec9529052a8e2243fa21a5732db677c494421c82391563e4f176f
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 63eedbbd3cee90a74bdafe3ed2bed614f0b1ce27dcf7037f83a77e1bbebbd1974b17192d6abf490f5246f152d9353900ca9ff255028cbe25a6a675413352a49f
|
7
|
+
data.tar.gz: be1d952da94e53b8748f6a4e1c2c710d12b2e547a3c16d7dd04da4485e4ec2bd08693d4cf70fb862be6b7cea6956a7121d68cd48865048ae5b831b9895da38ce
|
data/LICENSE
ADDED
@@ -0,0 +1,353 @@
|
|
1
|
+
Mozilla Public License, version 2.0
|
2
|
+
|
3
|
+
1. Definitions
|
4
|
+
|
5
|
+
1.1. “Contributor”
|
6
|
+
|
7
|
+
means each individual or legal entity that creates, contributes to the
|
8
|
+
creation of, or owns Covered Software.
|
9
|
+
|
10
|
+
1.2. “Contributor Version”
|
11
|
+
|
12
|
+
means the combination of the Contributions of others (if any) used by a
|
13
|
+
Contributor and that particular Contributor’s Contribution.
|
14
|
+
|
15
|
+
1.3. “Contribution”
|
16
|
+
|
17
|
+
means Covered Software of a particular Contributor.
|
18
|
+
|
19
|
+
1.4. “Covered Software”
|
20
|
+
|
21
|
+
means Source Code Form to which the initial Contributor has attached the
|
22
|
+
notice in Exhibit A, the Executable Form of such Source Code Form, and
|
23
|
+
Modifications of such Source Code Form, in each case including portions
|
24
|
+
thereof.
|
25
|
+
|
26
|
+
1.5. “Incompatible With Secondary Licenses”
|
27
|
+
means
|
28
|
+
|
29
|
+
a. that the initial Contributor has attached the notice described in
|
30
|
+
Exhibit B to the Covered Software; or
|
31
|
+
|
32
|
+
b. that the Covered Software was made available under the terms of version
|
33
|
+
1.1 or earlier of the License, but not also under the terms of a
|
34
|
+
Secondary License.
|
35
|
+
|
36
|
+
1.6. “Executable Form”
|
37
|
+
|
38
|
+
means any form of the work other than Source Code Form.
|
39
|
+
|
40
|
+
1.7. “Larger Work”
|
41
|
+
|
42
|
+
means a work that combines Covered Software with other material, in a separate
|
43
|
+
file or files, that is not Covered Software.
|
44
|
+
|
45
|
+
1.8. “License”
|
46
|
+
|
47
|
+
means this document.
|
48
|
+
|
49
|
+
1.9. “Licensable”
|
50
|
+
|
51
|
+
means having the right to grant, to the maximum extent possible, whether at the
|
52
|
+
time of the initial grant or subsequently, any and all of the rights conveyed by
|
53
|
+
this License.
|
54
|
+
|
55
|
+
1.10. “Modifications”
|
56
|
+
|
57
|
+
means any of the following:
|
58
|
+
|
59
|
+
a. any file in Source Code Form that results from an addition to, deletion
|
60
|
+
from, or modification of the contents of Covered Software; or
|
61
|
+
|
62
|
+
b. any new file in Source Code Form that contains any Covered Software.
|
63
|
+
|
64
|
+
1.11. “Patent Claims” of a Contributor
|
65
|
+
|
66
|
+
means any patent claim(s), including without limitation, method, process,
|
67
|
+
and apparatus claims, in any patent Licensable by such Contributor that
|
68
|
+
would be infringed, but for the grant of the License, by the making,
|
69
|
+
using, selling, offering for sale, having made, import, or transfer of
|
70
|
+
either its Contributions or its Contributor Version.
|
71
|
+
|
72
|
+
1.12. “Secondary License”
|
73
|
+
|
74
|
+
means either the GNU General Public License, Version 2.0, the GNU Lesser
|
75
|
+
General Public License, Version 2.1, the GNU Affero General Public
|
76
|
+
License, Version 3.0, or any later versions of those licenses.
|
77
|
+
|
78
|
+
1.13. “Source Code Form”
|
79
|
+
|
80
|
+
means the form of the work preferred for making modifications.
|
81
|
+
|
82
|
+
1.14. “You” (or “Your”)
|
83
|
+
|
84
|
+
means an individual or a legal entity exercising rights under this
|
85
|
+
License. For legal entities, “You” includes any entity that controls, is
|
86
|
+
controlled by, or is under common control with You. For purposes of this
|
87
|
+
definition, “control” means (a) the power, direct or indirect, to cause
|
88
|
+
the direction or management of such entity, whether by contract or
|
89
|
+
otherwise, or (b) ownership of more than fifty percent (50%) of the
|
90
|
+
outstanding shares or beneficial ownership of such entity.
|
91
|
+
|
92
|
+
|
93
|
+
2. License Grants and Conditions
|
94
|
+
|
95
|
+
2.1. Grants
|
96
|
+
|
97
|
+
Each Contributor hereby grants You a world-wide, royalty-free,
|
98
|
+
non-exclusive license:
|
99
|
+
|
100
|
+
a. under intellectual property rights (other than patent or trademark)
|
101
|
+
Licensable by such Contributor to use, reproduce, make available,
|
102
|
+
modify, display, perform, distribute, and otherwise exploit its
|
103
|
+
Contributions, either on an unmodified basis, with Modifications, or as
|
104
|
+
part of a Larger Work; and
|
105
|
+
|
106
|
+
b. under Patent Claims of such Contributor to make, use, sell, offer for
|
107
|
+
sale, have made, import, and otherwise transfer either its Contributions
|
108
|
+
or its Contributor Version.
|
109
|
+
|
110
|
+
2.2. Effective Date
|
111
|
+
|
112
|
+
The licenses granted in Section 2.1 with respect to any Contribution become
|
113
|
+
effective for each Contribution on the date the Contributor first distributes
|
114
|
+
such Contribution.
|
115
|
+
|
116
|
+
2.3. Limitations on Grant Scope
|
117
|
+
|
118
|
+
The licenses granted in this Section 2 are the only rights granted under this
|
119
|
+
License. No additional rights or licenses will be implied from the distribution
|
120
|
+
or licensing of Covered Software under this License. Notwithstanding Section
|
121
|
+
2.1(b) above, no patent license is granted by a Contributor:
|
122
|
+
|
123
|
+
a. for any code that a Contributor has removed from Covered Software; or
|
124
|
+
|
125
|
+
b. for infringements caused by: (i) Your and any other third party’s
|
126
|
+
modifications of Covered Software, or (ii) the combination of its
|
127
|
+
Contributions with other software (except as part of its Contributor
|
128
|
+
Version); or
|
129
|
+
|
130
|
+
c. under Patent Claims infringed by Covered Software in the absence of its
|
131
|
+
Contributions.
|
132
|
+
|
133
|
+
This License does not grant any rights in the trademarks, service marks, or
|
134
|
+
logos of any Contributor (except as may be necessary to comply with the
|
135
|
+
notice requirements in Section 3.4).
|
136
|
+
|
137
|
+
2.4. Subsequent Licenses
|
138
|
+
|
139
|
+
No Contributor makes additional grants as a result of Your choice to
|
140
|
+
distribute the Covered Software under a subsequent version of this License
|
141
|
+
(see Section 10.2) or under the terms of a Secondary License (if permitted
|
142
|
+
under the terms of Section 3.3).
|
143
|
+
|
144
|
+
2.5. Representation
|
145
|
+
|
146
|
+
Each Contributor represents that the Contributor believes its Contributions
|
147
|
+
are its original creation(s) or it has sufficient rights to grant the
|
148
|
+
rights to its Contributions conveyed by this License.
|
149
|
+
|
150
|
+
2.6. Fair Use
|
151
|
+
|
152
|
+
This License is not intended to limit any rights You have under applicable
|
153
|
+
copyright doctrines of fair use, fair dealing, or other equivalents.
|
154
|
+
|
155
|
+
2.7. Conditions
|
156
|
+
|
157
|
+
Sections 3.1, 3.2, 3.3, and 3.4 are conditions of the licenses granted in
|
158
|
+
Section 2.1.
|
159
|
+
|
160
|
+
|
161
|
+
3. Responsibilities
|
162
|
+
|
163
|
+
3.1. Distribution of Source Form
|
164
|
+
|
165
|
+
All distribution of Covered Software in Source Code Form, including any
|
166
|
+
Modifications that You create or to which You contribute, must be under the
|
167
|
+
terms of this License. You must inform recipients that the Source Code Form
|
168
|
+
of the Covered Software is governed by the terms of this License, and how
|
169
|
+
they can obtain a copy of this License. You may not attempt to alter or
|
170
|
+
restrict the recipients’ rights in the Source Code Form.
|
171
|
+
|
172
|
+
3.2. Distribution of Executable Form
|
173
|
+
|
174
|
+
If You distribute Covered Software in Executable Form then:
|
175
|
+
|
176
|
+
a. such Covered Software must also be made available in Source Code Form,
|
177
|
+
as described in Section 3.1, and You must inform recipients of the
|
178
|
+
Executable Form how they can obtain a copy of such Source Code Form by
|
179
|
+
reasonable means in a timely manner, at a charge no more than the cost
|
180
|
+
of distribution to the recipient; and
|
181
|
+
|
182
|
+
b. You may distribute such Executable Form under the terms of this License,
|
183
|
+
or sublicense it under different terms, provided that the license for
|
184
|
+
the Executable Form does not attempt to limit or alter the recipients’
|
185
|
+
rights in the Source Code Form under this License.
|
186
|
+
|
187
|
+
3.3. Distribution of a Larger Work
|
188
|
+
|
189
|
+
You may create and distribute a Larger Work under terms of Your choice,
|
190
|
+
provided that You also comply with the requirements of this License for the
|
191
|
+
Covered Software. If the Larger Work is a combination of Covered Software
|
192
|
+
with a work governed by one or more Secondary Licenses, and the Covered
|
193
|
+
Software is not Incompatible With Secondary Licenses, this License permits
|
194
|
+
You to additionally distribute such Covered Software under the terms of
|
195
|
+
such Secondary License(s), so that the recipient of the Larger Work may, at
|
196
|
+
their option, further distribute the Covered Software under the terms of
|
197
|
+
either this License or such Secondary License(s).
|
198
|
+
|
199
|
+
3.4. Notices
|
200
|
+
|
201
|
+
You may not remove or alter the substance of any license notices (including
|
202
|
+
copyright notices, patent notices, disclaimers of warranty, or limitations
|
203
|
+
of liability) contained within the Source Code Form of the Covered
|
204
|
+
Software, except that You may alter any license notices to the extent
|
205
|
+
required to remedy known factual inaccuracies.
|
206
|
+
|
207
|
+
3.5. Application of Additional Terms
|
208
|
+
|
209
|
+
You may choose to offer, and to charge a fee for, warranty, support,
|
210
|
+
indemnity or liability obligations to one or more recipients of Covered
|
211
|
+
Software. However, You may do so only on Your own behalf, and not on behalf
|
212
|
+
of any Contributor. You must make it absolutely clear that any such
|
213
|
+
warranty, support, indemnity, or liability obligation is offered by You
|
214
|
+
alone, and You hereby agree to indemnify every Contributor for any
|
215
|
+
liability incurred by such Contributor as a result of warranty, support,
|
216
|
+
indemnity or liability terms You offer. You may include additional
|
217
|
+
disclaimers of warranty and limitations of liability specific to any
|
218
|
+
jurisdiction.
|
219
|
+
|
220
|
+
4. Inability to Comply Due to Statute or Regulation
|
221
|
+
|
222
|
+
If it is impossible for You to comply with any of the terms of this License
|
223
|
+
with respect to some or all of the Covered Software due to statute, judicial
|
224
|
+
order, or regulation then You must: (a) comply with the terms of this License
|
225
|
+
to the maximum extent possible; and (b) describe the limitations and the code
|
226
|
+
they affect. Such description must be placed in a text file included with all
|
227
|
+
distributions of the Covered Software under this License. Except to the
|
228
|
+
extent prohibited by statute or regulation, such description must be
|
229
|
+
sufficiently detailed for a recipient of ordinary skill to be able to
|
230
|
+
understand it.
|
231
|
+
|
232
|
+
5. Termination
|
233
|
+
|
234
|
+
5.1. The rights granted under this License will terminate automatically if You
|
235
|
+
fail to comply with any of its terms. However, if You become compliant,
|
236
|
+
then the rights granted under this License from a particular Contributor
|
237
|
+
are reinstated (a) provisionally, unless and until such Contributor
|
238
|
+
explicitly and finally terminates Your grants, and (b) on an ongoing basis,
|
239
|
+
if such Contributor fails to notify You of the non-compliance by some
|
240
|
+
reasonable means prior to 60 days after You have come back into compliance.
|
241
|
+
Moreover, Your grants from a particular Contributor are reinstated on an
|
242
|
+
ongoing basis if such Contributor notifies You of the non-compliance by
|
243
|
+
some reasonable means, this is the first time You have received notice of
|
244
|
+
non-compliance with this License from such Contributor, and You become
|
245
|
+
compliant prior to 30 days after Your receipt of the notice.
|
246
|
+
|
247
|
+
5.2. If You initiate litigation against any entity by asserting a patent
|
248
|
+
infringement claim (excluding declaratory judgment actions, counter-claims,
|
249
|
+
and cross-claims) alleging that a Contributor Version directly or
|
250
|
+
indirectly infringes any patent, then the rights granted to You by any and
|
251
|
+
all Contributors for the Covered Software under Section 2.1 of this License
|
252
|
+
shall terminate.
|
253
|
+
|
254
|
+
5.3. In the event of termination under Sections 5.1 or 5.2 above, all end user
|
255
|
+
license agreements (excluding distributors and resellers) which have been
|
256
|
+
validly granted by You or Your distributors under this License prior to
|
257
|
+
termination shall survive termination.
|
258
|
+
|
259
|
+
6. Disclaimer of Warranty
|
260
|
+
|
261
|
+
Covered Software is provided under this License on an “as is” basis, without
|
262
|
+
warranty of any kind, either expressed, implied, or statutory, including,
|
263
|
+
without limitation, warranties that the Covered Software is free of defects,
|
264
|
+
merchantable, fit for a particular purpose or non-infringing. The entire
|
265
|
+
risk as to the quality and performance of the Covered Software is with You.
|
266
|
+
Should any Covered Software prove defective in any respect, You (not any
|
267
|
+
Contributor) assume the cost of any necessary servicing, repair, or
|
268
|
+
correction. This disclaimer of warranty constitutes an essential part of this
|
269
|
+
License. No use of any Covered Software is authorized under this License
|
270
|
+
except under this disclaimer.
|
271
|
+
|
272
|
+
7. Limitation of Liability
|
273
|
+
|
274
|
+
Under no circumstances and under no legal theory, whether tort (including
|
275
|
+
negligence), contract, or otherwise, shall any Contributor, or anyone who
|
276
|
+
distributes Covered Software as permitted above, be liable to You for any
|
277
|
+
direct, indirect, special, incidental, or consequential damages of any
|
278
|
+
character including, without limitation, damages for lost profits, loss of
|
279
|
+
goodwill, work stoppage, computer failure or malfunction, or any and all
|
280
|
+
other commercial damages or losses, even if such party shall have been
|
281
|
+
informed of the possibility of such damages. This limitation of liability
|
282
|
+
shall not apply to liability for death or personal injury resulting from such
|
283
|
+
party’s negligence to the extent applicable law prohibits such limitation.
|
284
|
+
Some jurisdictions do not allow the exclusion or limitation of incidental or
|
285
|
+
consequential damages, so this exclusion and limitation may not apply to You.
|
286
|
+
|
287
|
+
8. Litigation
|
288
|
+
|
289
|
+
Any litigation relating to this License may be brought only in the courts of
|
290
|
+
a jurisdiction where the defendant maintains its principal place of business
|
291
|
+
and such litigation shall be governed by laws of that jurisdiction, without
|
292
|
+
reference to its conflict-of-law provisions. Nothing in this Section shall
|
293
|
+
prevent a party’s ability to bring cross-claims or counter-claims.
|
294
|
+
|
295
|
+
9. Miscellaneous
|
296
|
+
|
297
|
+
This License represents the complete agreement concerning the subject matter
|
298
|
+
hereof. If any provision of this License is held to be unenforceable, such
|
299
|
+
provision shall be reformed only to the extent necessary to make it
|
300
|
+
enforceable. Any law or regulation which provides that the language of a
|
301
|
+
contract shall be construed against the drafter shall not be used to construe
|
302
|
+
this License against a Contributor.
|
303
|
+
|
304
|
+
|
305
|
+
10. Versions of the License
|
306
|
+
|
307
|
+
10.1. New Versions
|
308
|
+
|
309
|
+
Mozilla Foundation is the license steward. Except as provided in Section
|
310
|
+
10.3, no one other than the license steward has the right to modify or
|
311
|
+
publish new versions of this License. Each version will be given a
|
312
|
+
distinguishing version number.
|
313
|
+
|
314
|
+
10.2. Effect of New Versions
|
315
|
+
|
316
|
+
You may distribute the Covered Software under the terms of the version of
|
317
|
+
the License under which You originally received the Covered Software, or
|
318
|
+
under the terms of any subsequent version published by the license
|
319
|
+
steward.
|
320
|
+
|
321
|
+
10.3. Modified Versions
|
322
|
+
|
323
|
+
If you create software not governed by this License, and you want to
|
324
|
+
create a new license for such software, you may create and use a modified
|
325
|
+
version of this License if you rename the license and remove any
|
326
|
+
references to the name of the license steward (except to note that such
|
327
|
+
modified license differs from this License).
|
328
|
+
|
329
|
+
10.4. Distributing Source Code Form that is Incompatible With Secondary Licenses
|
330
|
+
If You choose to distribute Source Code Form that is Incompatible With
|
331
|
+
Secondary Licenses under the terms of this version of the License, the
|
332
|
+
notice described in Exhibit B of this License must be attached.
|
333
|
+
|
334
|
+
Exhibit A - Source Code Form License Notice
|
335
|
+
|
336
|
+
This Source Code Form is subject to the
|
337
|
+
terms of the Mozilla Public License, v.
|
338
|
+
2.0. If a copy of the MPL was not
|
339
|
+
distributed with this file, You can
|
340
|
+
obtain one at
|
341
|
+
http://mozilla.org/MPL/2.0/.
|
342
|
+
|
343
|
+
If it is not possible or desirable to put the notice in a particular file, then
|
344
|
+
You may include the notice in a location (such as a LICENSE file in a relevant
|
345
|
+
directory) where a recipient would be likely to look for such a notice.
|
346
|
+
|
347
|
+
You may add additional accurate notices of copyright ownership.
|
348
|
+
|
349
|
+
Exhibit B - “Incompatible With Secondary Licenses” Notice
|
350
|
+
|
351
|
+
This Source Code Form is “Incompatible
|
352
|
+
With Secondary Licenses”, as defined by
|
353
|
+
the Mozilla Public License, v. 2.0.
|
data/README.md
ADDED
@@ -0,0 +1,60 @@
|
|
1
|
+
# Terraform Enterprise API Client & Command Line Tool
|
2
|
+
A simple Ruby API client library and command line tool for the [Terraform Enterprise API](https://www.terraform.io/docs/enterprise/api/index.html).
|
3
|
+
|
4
|
+
|
5
|
+
|
6
|
+
## Requirements
|
7
|
+
|
8
|
+
MRI Ruby 2.0 and newer are supported. Alternative interpreters compatible with 2.0+ should work as well.
|
9
|
+
|
10
|
+
Earlier Ruby versions such as 1.8.7, 1.9.2, and 1.9.3 may work but are not supported.
|
11
|
+
|
12
|
+
This gem depends on these other gems for usage at runtime:
|
13
|
+
|
14
|
+
- [rest-client](https://github.com/rest-client/rest-client)
|
15
|
+
- [colorize](https://github.com/fazibear/colorize)
|
16
|
+
- [thor](https://github.com/erikhuda/thor)
|
17
|
+
|
18
|
+
## Usage
|
19
|
+
|
20
|
+
|
21
|
+
|
22
|
+
### Basic Example
|
23
|
+
|
24
|
+
```ruby
|
25
|
+
require 'terraform-enterprise-client'
|
26
|
+
|
27
|
+
api_key = ENV['TERRAFORM_ENTERPRISE_TOKEN']
|
28
|
+
client = TerraformEnterprise::Client.new(api_key: api_key)
|
29
|
+
|
30
|
+
# Create a new organization
|
31
|
+
org = client.organizations.create(name:'my-org',email:'maciej@skierkowski.com')
|
32
|
+
|
33
|
+
# Create a new workspace in the new organization.
|
34
|
+
# Uses the same parameters as the following docs:
|
35
|
+
# https://www.terraform.io/docs/enterprise/api/workspaces.html
|
36
|
+
client.workspaces.create(name:'my-new-workspace', organization:'my-org')
|
37
|
+
|
38
|
+
# Delete the workspace
|
39
|
+
client.workspaces.delete(name:'my-new-workspace', organization: 'my-org')
|
40
|
+
|
41
|
+
# Delete the organization now that we are done
|
42
|
+
client.organizations.delete(name:'my-org')
|
43
|
+
```
|
44
|
+
|
45
|
+
|
46
|
+
|
47
|
+
### Configuration
|
48
|
+
|
49
|
+
There are two main settings that can be modified on initialization:
|
50
|
+
|
51
|
+
- `:api_key` (required) - which specifies the API key (formerly called ATLAS_TOKEN)
|
52
|
+
- `:host` - a hostname other than the default (`app.terraform.io`) for usage with private installs
|
53
|
+
|
54
|
+
### Resources
|
55
|
+
|
56
|
+
The number of supported resources is a subset of the resources exposed via the Terraform Enterprise API. Additional resources will be added in future releases. Current supported resources include:
|
57
|
+
|
58
|
+
- `Client#workspaces`
|
59
|
+
- `Client#organizations`
|
60
|
+
- `Client#oauth_tokens`
|
@@ -0,0 +1,93 @@
|
|
1
|
+
require 'json'
|
2
|
+
require 'rest-client'
|
3
|
+
|
4
|
+
require 'terraform-enterprise/resources/organizations'
|
5
|
+
require 'terraform-enterprise/resources/oauth-tokens'
|
6
|
+
require 'terraform-enterprise/resources/workspaces'
|
7
|
+
|
8
|
+
module TerraformEnterprise
|
9
|
+
class Client
|
10
|
+
attr_accessor :base
|
11
|
+
|
12
|
+
def initialize(api_key:, host: 'https://app.terraform.io/api/v2')
|
13
|
+
@base = host
|
14
|
+
@api_key = api_key
|
15
|
+
@headers = {
|
16
|
+
'Authorization' => "Bearer #{@api_key}",
|
17
|
+
'Content-Type' => 'application/vnd.api+json'
|
18
|
+
}
|
19
|
+
end
|
20
|
+
|
21
|
+
def workspaces
|
22
|
+
TerraformEnterprise::Workspaces.new(self)
|
23
|
+
end
|
24
|
+
|
25
|
+
def organizations
|
26
|
+
TerraformEnterprise::Organizations.new(self)
|
27
|
+
end
|
28
|
+
|
29
|
+
def oauth_tokens
|
30
|
+
TerraformEnterprise::OAuthTokens.new(self)
|
31
|
+
end
|
32
|
+
|
33
|
+
def get(*path)
|
34
|
+
data = path.pop if path.last.is_a?(Hash)
|
35
|
+
request(:get, path, data)
|
36
|
+
end
|
37
|
+
|
38
|
+
def delete(*path)
|
39
|
+
data = path.pop if path.last.is_a?(Hash)
|
40
|
+
request(:delete, path,data)
|
41
|
+
end
|
42
|
+
|
43
|
+
def post(*path)
|
44
|
+
data = path.pop if path.last.is_a?(Hash)
|
45
|
+
request(:post, path, data)
|
46
|
+
end
|
47
|
+
|
48
|
+
def put(*path)
|
49
|
+
data = path.pop if path.last.is_a?(Hash)
|
50
|
+
request(:put,data,data)
|
51
|
+
end
|
52
|
+
|
53
|
+
def patch(*path)
|
54
|
+
data = path.pop if path.last.is_a?(Hash)
|
55
|
+
request(:patch,path,data)
|
56
|
+
end
|
57
|
+
|
58
|
+
def request(method, path, data={}, headers={})
|
59
|
+
request = {
|
60
|
+
method: method,
|
61
|
+
url: uri(path),
|
62
|
+
headers: @headers.merge(headers || {})
|
63
|
+
}
|
64
|
+
if data
|
65
|
+
if method==:get || method==:delete
|
66
|
+
request[:headers][:params] = data
|
67
|
+
else
|
68
|
+
request[:payload] = data.is_a?(String) ? data : data.to_json
|
69
|
+
end
|
70
|
+
end
|
71
|
+
|
72
|
+
response = begin
|
73
|
+
RestClient::Request.execute(request)
|
74
|
+
rescue RestClient::ExceptionWithResponse => ex
|
75
|
+
ex.response
|
76
|
+
end
|
77
|
+
|
78
|
+
if response.headers[:content_type] && response.headers[:content_type].include?('json')
|
79
|
+
return_data = JSON.parse(response) || {}
|
80
|
+
else
|
81
|
+
return_data = response.body
|
82
|
+
end
|
83
|
+
{'code' => response.code, 'body' => return_data}
|
84
|
+
end
|
85
|
+
|
86
|
+
private
|
87
|
+
|
88
|
+
def uri(path=[])
|
89
|
+
return path if path.is_a?(String) && path.start_with?("http")
|
90
|
+
"#{@base}/#{path.map{|p| p.to_s}.join('/')}"
|
91
|
+
end
|
92
|
+
end
|
93
|
+
end
|
@@ -0,0 +1,21 @@
|
|
1
|
+
require 'thor'
|
2
|
+
|
3
|
+
require 'terraform-enterprise/version'
|
4
|
+
require 'terraform-enterprise/commands/organizations_command'
|
5
|
+
require 'terraform-enterprise/commands/workspaces_command'
|
6
|
+
require 'terraform-enterprise/commands/oauth_tokens_command'
|
7
|
+
|
8
|
+
module TerraformEnterprise
|
9
|
+
class CommandLine < Thor
|
10
|
+
desc 'organizations <subcommand>', 'Manage organizations'
|
11
|
+
subcommand 'organizations', TerraformEnterprise::Commands::OrganizationsCommand
|
12
|
+
|
13
|
+
desc 'workspaces <subcommand>', 'Manage workspaces'
|
14
|
+
subcommand 'workspaces', TerraformEnterprise::Commands::WorkspacesCommand
|
15
|
+
|
16
|
+
desc 'oauth_tokens <subcommand>', 'Manage OAuth tokens'
|
17
|
+
subcommand 'oauth_tokens', TerraformEnterprise::Commands::OAuthTokensCommand
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
TerraformEnterprise::CommandLine.start(ARGV)
|
@@ -0,0 +1,42 @@
|
|
1
|
+
require 'yaml'
|
2
|
+
require 'colorize'
|
3
|
+
|
4
|
+
require 'terraform-enterprise-client'
|
5
|
+
|
6
|
+
module TerraformEnterprise
|
7
|
+
module Commands
|
8
|
+
class Command < Thor
|
9
|
+
class_option :color, type: :boolean, default: true
|
10
|
+
|
11
|
+
no_commands do
|
12
|
+
def render(obj)
|
13
|
+
String.disable_colorization = !options['color']
|
14
|
+
|
15
|
+
if obj['code'] && obj['body']
|
16
|
+
if obj['code'] == 200
|
17
|
+
puts "Success".green
|
18
|
+
data = obj['body']['data'] ? obj['body']['data'] : obj['body']
|
19
|
+
puts data.to_yaml
|
20
|
+
elsif
|
21
|
+
if obj['body']['errors']
|
22
|
+
obj['body']['errors'].each do |error|
|
23
|
+
puts "Error (#{error['status']}): #{error['title']}".red
|
24
|
+
end
|
25
|
+
else
|
26
|
+
end
|
27
|
+
end
|
28
|
+
else
|
29
|
+
puts obj.to_yaml
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
33
|
+
def client
|
34
|
+
settings = { }
|
35
|
+
settings[:api_key] = options[:token] || ENV['TERRAFORM_ENTERPRISE_TOKEN']
|
36
|
+
settings[:host] = options[:host] if options[:host]
|
37
|
+
TerraformEnterprise::Client.new(settings)
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
@@ -0,0 +1,17 @@
|
|
1
|
+
require 'terraform-enterprise/commands/command'
|
2
|
+
require 'terraform-enterprise-client'
|
3
|
+
|
4
|
+
module TerraformEnterprise
|
5
|
+
module Commands
|
6
|
+
class OAuthTokensCommand < TerraformEnterprise::Commands::Command
|
7
|
+
class_option :host, type: :string
|
8
|
+
class_option :token, type: :string
|
9
|
+
class_option :organization, required: true, type: :string, desc: 'Organization name'
|
10
|
+
|
11
|
+
desc 'list', 'Lists all OAuth Tokens'
|
12
|
+
def list
|
13
|
+
render client.oauth_tokens.list(options)
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
@@ -0,0 +1,30 @@
|
|
1
|
+
require 'terraform-enterprise/commands/command'
|
2
|
+
|
3
|
+
module TerraformEnterprise
|
4
|
+
module Commands
|
5
|
+
class OrganizationsCommand < TerraformEnterprise::Commands::Command
|
6
|
+
class_option :host, type: :string
|
7
|
+
class_option :token, type: :string
|
8
|
+
|
9
|
+
desc 'list', 'Lists all organizations'
|
10
|
+
def list
|
11
|
+
render client.organizations.list
|
12
|
+
end
|
13
|
+
|
14
|
+
desc 'create <name> <email>', 'Creates a new organization'
|
15
|
+
def create(name, email)
|
16
|
+
render client.organizations.create(name: name, email: email)
|
17
|
+
end
|
18
|
+
|
19
|
+
desc 'get <name>', 'Gets the organization details'
|
20
|
+
def get(name)
|
21
|
+
render client.organizations.get(name:name)
|
22
|
+
end
|
23
|
+
|
24
|
+
desc 'delete <name>', 'Deletes the organization'
|
25
|
+
def delete(name)
|
26
|
+
render client.organizations.delete(name:name)
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
@@ -0,0 +1,81 @@
|
|
1
|
+
require 'terraform-enterprise/commands/command'
|
2
|
+
|
3
|
+
module TerraformEnterprise
|
4
|
+
module Commands
|
5
|
+
class WorkspacesCommand < TerraformEnterprise::Commands::Command
|
6
|
+
class_option :host, type: :string, desc: 'Hostname of private Terraform Enterprise'
|
7
|
+
class_option :token, type: :string, desc: 'Access token'
|
8
|
+
class_option :organization, required: true, type: :string, desc: 'Organization name'
|
9
|
+
|
10
|
+
desc 'list', 'Lists all workspaces in the organization'
|
11
|
+
def list
|
12
|
+
render client.workspaces.list(options)
|
13
|
+
end
|
14
|
+
|
15
|
+
desc 'create <name>', 'Creates a new organization'
|
16
|
+
option :terraform_version, type: :string, desc: "Version of Terraform to use for this workspace."
|
17
|
+
option :working_directory, type: :string, desc: "Relative path that Terraform will execute within."
|
18
|
+
option :oauth_token, type: :string, desc: 'VCS Connection (OAuth Conection + Token) to use as identified; obtained from the oauth_tokens subcommand.'
|
19
|
+
option :branch, type: :string, desc: "Repository branch that Terraform will execute from."
|
20
|
+
option :ingress_submodules, type: :boolean, default: false, desc: "Submodules should be fetched when cloning the VCS repository."
|
21
|
+
option :repo, type: :string, desc: 'Reference to VCS repository in the format :org/:repo'
|
22
|
+
option :import_repo, type: :string, desc: ''
|
23
|
+
def create(name)
|
24
|
+
params = {
|
25
|
+
organization: options[:organization],
|
26
|
+
name: name,
|
27
|
+
'working-directory' => options[:working_directory] || '',
|
28
|
+
'vcs-repo' => {
|
29
|
+
'branch' => options[:branch] || '',
|
30
|
+
'identifier' => options[:repo] || '',
|
31
|
+
'oauth-token-id' => options[:oauth_token] || '',
|
32
|
+
'ingress-submodules' => options[:ingress_submodules]
|
33
|
+
}
|
34
|
+
}
|
35
|
+
|
36
|
+
params['migration-environment'] = options[:import_repo] if options[:import_repo]
|
37
|
+
params['terraform_version'] = options[:terraform_version] if options[:terraform_version]
|
38
|
+
|
39
|
+
render client.workspaces.create(params)
|
40
|
+
end
|
41
|
+
|
42
|
+
desc 'get <name>', 'Gets the workspace details'
|
43
|
+
def get(name)
|
44
|
+
params = {
|
45
|
+
organization: options[:organization],
|
46
|
+
workspace: name
|
47
|
+
}
|
48
|
+
render client.workspaces.get(params)
|
49
|
+
end
|
50
|
+
|
51
|
+
desc 'delete <name>', 'Deletes the workspace'
|
52
|
+
def delete(name)
|
53
|
+
params = {
|
54
|
+
organization: options[:organization],
|
55
|
+
workspace: name
|
56
|
+
}
|
57
|
+
render client.workspaces.delete(params)
|
58
|
+
end
|
59
|
+
|
60
|
+
desc 'update <name>', 'Update the workspace'
|
61
|
+
option :working_directory, type: :string, desc: "Relative path that Terraform will execute within."
|
62
|
+
option :terraform_version, type: :string, desc: "Version of Terraform to use for this workspace."
|
63
|
+
option :auto_apply, type: :boolean, desc: 'Auto-apply enabled'
|
64
|
+
def update(name)
|
65
|
+
params = options
|
66
|
+
params[:workspace] = name
|
67
|
+
render client.workspaces.update(params)
|
68
|
+
end
|
69
|
+
|
70
|
+
desc 'lock <id>', "Locks the workspace"
|
71
|
+
def lock(id)
|
72
|
+
render client.workspaces.action(action: :lock, id: id)
|
73
|
+
end
|
74
|
+
|
75
|
+
desc 'unlock <id>', 'Unlocks the workspace'
|
76
|
+
def unlock(id)
|
77
|
+
render client.workspaces.action(action: :unlock, id: id)
|
78
|
+
end
|
79
|
+
end
|
80
|
+
end
|
81
|
+
end
|
@@ -0,0 +1,26 @@
|
|
1
|
+
require "terraform-enterprise/resources_client"
|
2
|
+
|
3
|
+
module TerraformEnterprise
|
4
|
+
class Organizations < ResourcesClient
|
5
|
+
def list(params={})
|
6
|
+
@client.get(:organizations)
|
7
|
+
end
|
8
|
+
|
9
|
+
def get(params={})
|
10
|
+
@client.get(:organizations, params[:name])
|
11
|
+
end
|
12
|
+
|
13
|
+
def create(params={})
|
14
|
+
data = {
|
15
|
+
attributes: params,
|
16
|
+
type: 'organizations'
|
17
|
+
}
|
18
|
+
|
19
|
+
@client.post(:organizations, data: data)
|
20
|
+
end
|
21
|
+
|
22
|
+
def delete(params={})
|
23
|
+
@client.delete(:organizations, params[:name])
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
@@ -0,0 +1,43 @@
|
|
1
|
+
require "terraform-enterprise/resources_client"
|
2
|
+
|
3
|
+
module TerraformEnterprise
|
4
|
+
class Workspaces < ResourcesClient
|
5
|
+
def list(params={})
|
6
|
+
@client.get(:organizations, params[:organization], :workspaces)
|
7
|
+
end
|
8
|
+
|
9
|
+
def get(params={})
|
10
|
+
@client.get(:organizations, params[:organization], :workspaces, params[:workspace])
|
11
|
+
end
|
12
|
+
|
13
|
+
def create(params={})
|
14
|
+
org = params.delete(:organization)
|
15
|
+
data = {
|
16
|
+
attributes: params,
|
17
|
+
type: 'workspaces'
|
18
|
+
}
|
19
|
+
|
20
|
+
@client.post(:organizations, org, :workspaces, data: data)
|
21
|
+
end
|
22
|
+
|
23
|
+
def update(params={})
|
24
|
+
org = params.delete(:organization)
|
25
|
+
id = params.delete(:workspace)
|
26
|
+
|
27
|
+
data = {
|
28
|
+
attributes: params,
|
29
|
+
type: 'workspaces'
|
30
|
+
}
|
31
|
+
|
32
|
+
@client.patch(:organizations, org, :workspaces, id, data: data)
|
33
|
+
end
|
34
|
+
|
35
|
+
def delete(params={})
|
36
|
+
@client.delete(:organizations, params[:organization], :workspaces, params[:workspace])
|
37
|
+
end
|
38
|
+
|
39
|
+
def action(params={})
|
40
|
+
@client.post(:workspaces, params[:id], :actions, params[:action].to_sym)
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|
metadata
ADDED
@@ -0,0 +1,99 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: terraform-enterprise-client
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.2
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Maciej Skierkowski
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2018-03-23 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: rest-client
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: 2.0.2
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: 2.0.2
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: colorize
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: 0.8.1
|
34
|
+
type: :runtime
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: 0.8.1
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: thor
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: 0.20.0
|
48
|
+
type: :runtime
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: 0.20.0
|
55
|
+
description: " Ruby client that supports all of the Terraform Enterprise API methods. "
|
56
|
+
email: maciej@skierkowski.com
|
57
|
+
executables: []
|
58
|
+
extensions: []
|
59
|
+
extra_rdoc_files:
|
60
|
+
- LICENSE
|
61
|
+
- README.md
|
62
|
+
files:
|
63
|
+
- LICENSE
|
64
|
+
- README.md
|
65
|
+
- lib/terraform-enterprise-client.rb
|
66
|
+
- lib/terraform-enterprise-command-line.rb
|
67
|
+
- lib/terraform-enterprise/commands/command.rb
|
68
|
+
- lib/terraform-enterprise/commands/oauth_tokens_command.rb
|
69
|
+
- lib/terraform-enterprise/commands/organizations_command.rb
|
70
|
+
- lib/terraform-enterprise/commands/workspaces_command.rb
|
71
|
+
- lib/terraform-enterprise/resources/oauth-tokens.rb
|
72
|
+
- lib/terraform-enterprise/resources/organizations.rb
|
73
|
+
- lib/terraform-enterprise/resources/workspaces.rb
|
74
|
+
- lib/terraform-enterprise/resources_client.rb
|
75
|
+
- lib/terraform-enterprise/version.rb
|
76
|
+
homepage: http://github.com/skierkowski/terraform-enterprise-client
|
77
|
+
licenses: []
|
78
|
+
metadata: {}
|
79
|
+
post_install_message:
|
80
|
+
rdoc_options: []
|
81
|
+
require_paths:
|
82
|
+
- lib
|
83
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
84
|
+
requirements:
|
85
|
+
- - ">="
|
86
|
+
- !ruby/object:Gem::Version
|
87
|
+
version: 2.0.0
|
88
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
89
|
+
requirements:
|
90
|
+
- - ">="
|
91
|
+
- !ruby/object:Gem::Version
|
92
|
+
version: '0'
|
93
|
+
requirements: []
|
94
|
+
rubyforge_project:
|
95
|
+
rubygems_version: 2.7.3
|
96
|
+
signing_key:
|
97
|
+
specification_version: 4
|
98
|
+
summary: Ruby client for the official Terraform Enterprise API
|
99
|
+
test_files: []
|