terraform-enterprise-client 0.0.4 → 0.0.5
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +13 -5
- data/lib/terraform-enterprise-client.rb +14 -4
- data/lib/terraform-enterprise-command-line.rb +8 -0
- data/lib/terraform-enterprise/client/request.rb +10 -1
- data/lib/terraform-enterprise/commands/command.rb +2 -0
- data/lib/terraform-enterprise/commands/formatter.rb +5 -1
- data/lib/terraform-enterprise/commands/strings.rb +30 -1
- data/lib/terraform-enterprise/commands/teams_command.rb +33 -0
- data/lib/terraform-enterprise/commands/variables_command.rb +61 -0
- data/lib/terraform-enterprise/commands/workspaces_command.rb +5 -5
- data/lib/terraform-enterprise/resource_requests/teams.rb +30 -0
- data/lib/terraform-enterprise/resource_requests/variables.rb +48 -0
- data/lib/terraform-enterprise/version.rb +1 -1
- metadata +5 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: e9ea07941d8b0d4ae1c8c1046700cedc4d82c8b4
|
4
|
+
data.tar.gz: 05db114c2173ce71d68ef2784c725f42c8736ba8
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 344147995b1f01268bee781f5d90f7e797f8f73455fbe777091e06ac90b56525bbc21375b6f17e2f68a26625ff5b7d99365ce86fa4021ed5398332dd85bdf564
|
7
|
+
data.tar.gz: 09bb42afd3600006c0005e61da47a41cd6977f4f0418dbbf05d199ff8565fac0a7236261f42a18866c57e7d69a2879fd5281563c238d99858752311283d167db
|
data/README.md
CHANGED
@@ -14,6 +14,7 @@ This gem depends on these other gems for usage at runtime:
|
|
14
14
|
- [rest-client](https://github.com/rest-client/rest-client)
|
15
15
|
- [colorize](https://github.com/fazibear/colorize)
|
16
16
|
- [thor](https://github.com/erikhuda/thor)
|
17
|
+
- [terminal-table](https://github.com/tj/terminal-table)
|
17
18
|
|
18
19
|
## API Client
|
19
20
|
|
@@ -70,6 +71,7 @@ Installing the gem installs the `tfe` command line tool. Running `tfe help` prov
|
|
70
71
|
All of the resources, actions and paraeters are documented in the tool and available through the `help` subcommand.
|
71
72
|
|
72
73
|
#### Basic Usage
|
74
|
+
|
73
75
|
```shell
|
74
76
|
➭ tfe help
|
75
77
|
Commands:
|
@@ -79,11 +81,17 @@ Commands:
|
|
79
81
|
tfe workspaces <subcommand> # Manage workspaces
|
80
82
|
```
|
81
83
|
|
84
|
+
### Authentication
|
85
|
+
|
86
|
+
There are two methods for authenticating the CLI with the Terraform Enterprise API. The first is to use the `TERRAFORM_ENTERPRISE_TOKEN` environment variable. The second is to pass in the token on the command line using the `--token` option. The command line option takes precendence over the environment variable.
|
87
|
+
|
82
88
|
### Scripting
|
89
|
+
|
83
90
|
The CLI is designed to be easy to call from other scripts. A few command line options exist to control the output format to minimize the string parsing needed to extract the desired data from the output:
|
84
91
|
|
85
|
-
-
|
86
|
-
-
|
87
|
-
-
|
88
|
-
-
|
89
|
-
-
|
92
|
+
- `--no-color` (Boolean, default: false): Removes ANSI color codes from output
|
93
|
+
- `--except` (Array): Exclude particular fields from the output from being returned. This is a space-separated list of fields to be excluded from the output.
|
94
|
+
- `--only` (Array): Only return the fields selected in this space-separated list of field keys.
|
95
|
+
- `--all` (Boolean, default: false): By default most commands only return a subset of fields. Many of the APIs return additional attributes which are used by the UI and likely have little value to you. As such, they are excluded by default. This option will return all of the fields, not just the subset.
|
96
|
+
- `--value` (Boolean, default: false): The output text by default shows the key and values for each field. If this option is enabled only the value of the fields will be returned. This is particularly useful if you would like to obtain the id of a newly created resource (e.g. `tfe workspcaces create new-ws --organization my-organization --only name --value` would return only the name of the created workspace)
|
97
|
+
- `--no-table` (Boolean, default: false): For `list` subcommands format the output as a list of key/value paris instead of formatting the list in a table.
|
@@ -5,6 +5,8 @@ require 'terraform-enterprise/client/request'
|
|
5
5
|
require 'terraform-enterprise/resource_requests/organizations'
|
6
6
|
require 'terraform-enterprise/resource_requests/oauth-tokens'
|
7
7
|
require 'terraform-enterprise/resource_requests/workspaces'
|
8
|
+
require 'terraform-enterprise/resource_requests/teams'
|
9
|
+
require 'terraform-enterprise/resource_requests/variables'
|
8
10
|
|
9
11
|
module TerraformEnterprise
|
10
12
|
class Client
|
@@ -14,16 +16,24 @@ module TerraformEnterprise
|
|
14
16
|
@request = TerraformEnterprise::API::Request.new(options)
|
15
17
|
end
|
16
18
|
|
17
|
-
def
|
18
|
-
TerraformEnterprise::API::
|
19
|
+
def oauth_tokens
|
20
|
+
TerraformEnterprise::API::OAuthTokens.new(@request)
|
19
21
|
end
|
20
22
|
|
21
23
|
def organizations
|
22
24
|
TerraformEnterprise::API::Organizations.new(@request)
|
23
25
|
end
|
24
26
|
|
25
|
-
def
|
26
|
-
TerraformEnterprise::API::
|
27
|
+
def teams
|
28
|
+
TerraformEnterprise::API::Teams.new(@request)
|
29
|
+
end
|
30
|
+
|
31
|
+
def variables
|
32
|
+
TerraformEnterprise::API::Variables.new(@request)
|
33
|
+
end
|
34
|
+
|
35
|
+
def workspaces
|
36
|
+
TerraformEnterprise::API::Workspaces.new(@request)
|
27
37
|
end
|
28
38
|
end
|
29
39
|
end
|
@@ -4,6 +4,8 @@ require 'terraform-enterprise/version'
|
|
4
4
|
require 'terraform-enterprise/commands/organizations_command'
|
5
5
|
require 'terraform-enterprise/commands/workspaces_command'
|
6
6
|
require 'terraform-enterprise/commands/oauth_tokens_command'
|
7
|
+
require 'terraform-enterprise/commands/teams_command'
|
8
|
+
require 'terraform-enterprise/commands/variables_command'
|
7
9
|
|
8
10
|
module TerraformEnterprise
|
9
11
|
class CommandLine < Thor
|
@@ -15,6 +17,12 @@ module TerraformEnterprise
|
|
15
17
|
|
16
18
|
desc 'oauth_tokens <subcommand>', 'Manage OAuth tokens'
|
17
19
|
subcommand 'oauth_tokens', TerraformEnterprise::Commands::OAuthTokensCommand
|
20
|
+
|
21
|
+
desc 'teams <subcommand>', 'Manage teams'
|
22
|
+
subcommand 'teams', TerraformEnterprise::Commands::TeamsCommand
|
23
|
+
|
24
|
+
desc 'variables <subcommand>', 'Manage variables'
|
25
|
+
subcommand 'variables', TerraformEnterprise::Commands::VariablesCommand
|
18
26
|
end
|
19
27
|
end
|
20
28
|
|
@@ -5,9 +5,10 @@ module TerraformEnterprise
|
|
5
5
|
class Request
|
6
6
|
attr_accessor :base
|
7
7
|
|
8
|
-
def initialize(api_key:, host: 'https://app.terraform.io/api/v2')
|
8
|
+
def initialize(api_key:, host: 'https://app.terraform.io/api/v2', debug: false)
|
9
9
|
@base = host
|
10
10
|
@api_key = api_key
|
11
|
+
@debug = debug
|
11
12
|
@headers = {
|
12
13
|
'Authorization' => "Bearer #{@api_key}",
|
13
14
|
'Content-Type' => 'application/vnd.api+json'
|
@@ -59,6 +60,14 @@ module TerraformEnterprise
|
|
59
60
|
ex.response
|
60
61
|
end
|
61
62
|
|
63
|
+
if @debug
|
64
|
+
puts "[DEBUG] [REQUEST:METHOD] #{request[:method].to_s.upcase} #{request[:url]}"
|
65
|
+
puts "[DEBUG] [REQUEST:HEADERS] #{request[:headers]}"
|
66
|
+
puts "[DEBUG] [REQUEST:PAYLOAD] #{data}"
|
67
|
+
puts "[DEBUG] [RESPONSE:CODE] #{response.code}"
|
68
|
+
puts "[DEBUG] [RESPONSE:BODY] #{response.body}"
|
69
|
+
end
|
70
|
+
|
62
71
|
TerraformEnterprise::API::Response.new(response)
|
63
72
|
end
|
64
73
|
|
@@ -14,6 +14,7 @@ module TerraformEnterprise
|
|
14
14
|
class_option :only, type: :array, desc: 'List of fields that should be displayed'
|
15
15
|
class_option :all, type: :boolean, default: false, desc: "Return all fields, not just summary"
|
16
16
|
class_option :value, type: :boolean, default: false, desc: 'Only return the value; i.e. do not show keys'
|
17
|
+
class_option :debug, type: :boolean, default: false, desc: 'Show debug logs'
|
17
18
|
|
18
19
|
no_commands do
|
19
20
|
def render(obj, default_options={})
|
@@ -29,6 +30,7 @@ module TerraformEnterprise
|
|
29
30
|
settings = { }
|
30
31
|
settings[:api_key] = options[:token] || ENV['TERRAFORM_ENTERPRISE_TOKEN']
|
31
32
|
settings[:host] = options[:host] if options[:host]
|
33
|
+
settings[:debug] = options[:debug] if options[:debug]
|
32
34
|
TerraformEnterprise::Client.new(settings)
|
33
35
|
end
|
34
36
|
|
@@ -20,7 +20,11 @@ module TerraformEnterprise
|
|
20
20
|
end
|
21
21
|
elsif obj.has_errors?
|
22
22
|
obj.errors.each do |error|
|
23
|
-
|
23
|
+
if error['status'] && error['title']
|
24
|
+
puts "Error (#{error['status']}): #{error['title']}".red
|
25
|
+
else
|
26
|
+
puts "Error (#{obj.code}): #{error}".red
|
27
|
+
end
|
24
28
|
end
|
25
29
|
else
|
26
30
|
puts "Unknown server response (#{obj.code})".yellow
|
@@ -37,6 +37,17 @@ module TerraformEnterprise
|
|
37
37
|
},
|
38
38
|
attributes: { }
|
39
39
|
},
|
40
|
+
teams: {
|
41
|
+
commands: {
|
42
|
+
create: 'Create a new team',
|
43
|
+
delete: 'Delete the team by ID',
|
44
|
+
list: 'List teams in organization',
|
45
|
+
get: 'Get team details'
|
46
|
+
},
|
47
|
+
attributes: {
|
48
|
+
organization: 'Organization to which this Team belongs to.'
|
49
|
+
}
|
50
|
+
},
|
40
51
|
oauth_tokens: {
|
41
52
|
commands: {
|
42
53
|
list: 'List the OAuth tokens in the organization'
|
@@ -44,7 +55,25 @@ module TerraformEnterprise
|
|
44
55
|
attributes: {
|
45
56
|
organization: 'Organization to which this OAuth Token belongs to.'
|
46
57
|
}
|
47
|
-
}
|
58
|
+
},
|
59
|
+
variables: {
|
60
|
+
commands: {
|
61
|
+
create: 'Create a new variable',
|
62
|
+
delete: 'Delete the variable by ID',
|
63
|
+
get: 'Get variable details',
|
64
|
+
list: 'List variables in organization',
|
65
|
+
update: 'Update a variable by ID',
|
66
|
+
},
|
67
|
+
attributes: {
|
68
|
+
organization: 'Organization to which this Variable belongs to.',
|
69
|
+
workspace: 'Workspace to which this Variable belongs to.',
|
70
|
+
category: 'The type of cateogry, probably "terrafomr" or "environment"',
|
71
|
+
hcl: 'Variable should be parsed using HCL',
|
72
|
+
sensitive:'Variable should be marked as sensitive',
|
73
|
+
value: 'Variable value',
|
74
|
+
key: 'Variable key',
|
75
|
+
}
|
76
|
+
},
|
48
77
|
}
|
49
78
|
end
|
50
79
|
end
|
@@ -0,0 +1,33 @@
|
|
1
|
+
require 'terraform-enterprise/commands/command'
|
2
|
+
|
3
|
+
module TerraformEnterprise
|
4
|
+
module Commands
|
5
|
+
class TeamsCommand < TerraformEnterprise::Commands::Command
|
6
|
+
ATTR_STR = STRINGS[:teams][:attributes]
|
7
|
+
CMD_STR = STRINGS[:teams][:commands]
|
8
|
+
|
9
|
+
desc 'list', CMD_STR[:list]
|
10
|
+
option :table, type: :boolean, default: true, desc: STRINGS[:options][:table]
|
11
|
+
option :organization, required: true, type: :string, desc: ATTR_STR[:organization]
|
12
|
+
def list
|
13
|
+
render client.teams.list(organization: options[:organization]), except: [:permissions]
|
14
|
+
end
|
15
|
+
|
16
|
+
desc 'create <name>', CMD_STR[:create]
|
17
|
+
option :organization, required: true, type: :string, desc: ATTR_STR[:organization]
|
18
|
+
def create(name)
|
19
|
+
render client.teams.create(name: name, organization: options[:organization])
|
20
|
+
end
|
21
|
+
|
22
|
+
desc 'get <id>', CMD_STR[:get]
|
23
|
+
def get(id)
|
24
|
+
render client.teams.get(id:id), except: [:permissions]
|
25
|
+
end
|
26
|
+
|
27
|
+
desc 'delete <id>', CMD_STR[:delete]
|
28
|
+
def delete(id)
|
29
|
+
render client.teams.delete(id: id), except: [:permissions]
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
@@ -0,0 +1,61 @@
|
|
1
|
+
require 'terraform-enterprise/commands/command'
|
2
|
+
|
3
|
+
module TerraformEnterprise
|
4
|
+
module Commands
|
5
|
+
class VariablesCommand < TerraformEnterprise::Commands::Command
|
6
|
+
ATTR_STR = STRINGS[:variables][:attributes]
|
7
|
+
CMD_STR = STRINGS[:variables][:commands]
|
8
|
+
|
9
|
+
desc 'list', CMD_STR[:list]
|
10
|
+
option :table, type: :boolean, default: true, desc: STRINGS[:options][:table]
|
11
|
+
option :organization, required: true, type: :string, desc: ATTR_STR[:organization]
|
12
|
+
option :workspace, type: :string, desc: ATTR_STR[:workspace]
|
13
|
+
def list
|
14
|
+
render client.variables.list(options)
|
15
|
+
end
|
16
|
+
|
17
|
+
desc 'create <key> <value>', CMD_STR[:create]
|
18
|
+
option :organization, required: true, type: :string, desc: ATTR_STR[:organization]
|
19
|
+
option :workspace, required: true, type: :string, desc: ATTR_STR[:workspace]
|
20
|
+
option :category, default: 'terraform', type: :string, desc: ATTR_STR[:category]
|
21
|
+
option :hcl, default: false, type: :boolean, desc: ATTR_STR[:hcl]
|
22
|
+
option :sensitive, default: false, type: :boolean, desc: ATTR_STR[:sensitive]
|
23
|
+
def create(key, value)
|
24
|
+
params = {
|
25
|
+
category: options[:category],
|
26
|
+
hcl: options[:hcl],
|
27
|
+
key: key,
|
28
|
+
organization: options[:organization],
|
29
|
+
sensitive: options[:sensitive],
|
30
|
+
value: value,
|
31
|
+
workspace: options[:workspace],
|
32
|
+
}
|
33
|
+
render client.variables.create(params)
|
34
|
+
end
|
35
|
+
|
36
|
+
desc 'update <id>', CMD_STR[:update]
|
37
|
+
option :hcl, type: :boolean, desc: ATTR_STR[:hcl]
|
38
|
+
option :sensitive, type: :boolean, desc: ATTR_STR[:sensitive]
|
39
|
+
option :key, type: :string, desc: ATTR_STR[:key]
|
40
|
+
option :value, type: :string, desc: ATTR_STR[:value]
|
41
|
+
def update(id)
|
42
|
+
params = {id: id}
|
43
|
+
params[:hcl] = options[:hcl] if options.include?('hcl')
|
44
|
+
params[:key] = options[:key] if options[:key]
|
45
|
+
params[:sensitive] = options[:sensitive] if options.include?('sensitive')
|
46
|
+
params[:value] = options[:value] if options[:value]
|
47
|
+
render client.variables.update(params)
|
48
|
+
end
|
49
|
+
|
50
|
+
desc 'get <id>', CMD_STR[:get]
|
51
|
+
def get(id)
|
52
|
+
render client.variables.get(id:id)
|
53
|
+
end
|
54
|
+
|
55
|
+
desc 'delete <id>', CMD_STR[:delete]
|
56
|
+
def delete(id)
|
57
|
+
render client.variables.delete(id: id)
|
58
|
+
end
|
59
|
+
end
|
60
|
+
end
|
61
|
+
end
|
@@ -28,12 +28,12 @@ module TerraformEnterprise
|
|
28
28
|
name: name,
|
29
29
|
'working-directory' => options[:working_directory] || '',
|
30
30
|
}
|
31
|
-
if options[:
|
31
|
+
if options[:repo] && options[:oauth_token]
|
32
32
|
repo = {}
|
33
|
-
repo['branch'] = options[:branch]
|
34
|
-
repo['identifier'] = options[:repo]
|
35
|
-
repo['oauth-token-id'] = options[:oauth_token]
|
36
|
-
repo['ingress-submodules'] = options[:ingress_submodules]
|
33
|
+
repo['branch'] = options[:branch] || ''
|
34
|
+
repo['identifier'] = options[:repo]
|
35
|
+
repo['oauth-token-id'] = options[:oauth_token]
|
36
|
+
repo['ingress-submodules'] = options[:ingress_submodules] || false
|
37
37
|
params['vcs-repo'] = repo
|
38
38
|
end
|
39
39
|
|
@@ -0,0 +1,30 @@
|
|
1
|
+
require "terraform-enterprise/client/resource_request"
|
2
|
+
|
3
|
+
module TerraformEnterprise
|
4
|
+
module API
|
5
|
+
class Teams < TerraformEnterprise::API::ResourceRequest
|
6
|
+
|
7
|
+
def list(params={})
|
8
|
+
@request.get(:organizations, params[:organization], :teams)
|
9
|
+
end
|
10
|
+
|
11
|
+
def get(params={})
|
12
|
+
@request.get(:teams, params[:id])
|
13
|
+
end
|
14
|
+
|
15
|
+
def create(params={})
|
16
|
+
org = params.delete(:organization)
|
17
|
+
data = {
|
18
|
+
attributes: params,
|
19
|
+
type: 'teams'
|
20
|
+
}
|
21
|
+
|
22
|
+
@request.post(:organizations, org, :teams, data: data)
|
23
|
+
end
|
24
|
+
|
25
|
+
def delete(params={})
|
26
|
+
@request.delete(:teams, params[:id])
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
@@ -0,0 +1,48 @@
|
|
1
|
+
require "terraform-enterprise/client/resource_request"
|
2
|
+
|
3
|
+
module TerraformEnterprise
|
4
|
+
module API
|
5
|
+
class Variables < TerraformEnterprise::API::ResourceRequest
|
6
|
+
|
7
|
+
def list(params={})
|
8
|
+
filter = {}
|
9
|
+
filter[:workspace] = {name: params[:workspace]} if params[:workspace]
|
10
|
+
filter[:organization] = {name: params[:organization]} if params[:organization]
|
11
|
+
@request.get(:vars, {filter:filter})
|
12
|
+
end
|
13
|
+
|
14
|
+
def get(params={})
|
15
|
+
@request.get(:vars, params[:id])
|
16
|
+
end
|
17
|
+
|
18
|
+
def create(params={})
|
19
|
+
org = params.delete(:organization)
|
20
|
+
workspace = params.delete(:workspace)
|
21
|
+
data = {
|
22
|
+
attributes: params,
|
23
|
+
type: 'vars',
|
24
|
+
}
|
25
|
+
filter = {
|
26
|
+
organization: {name: org},
|
27
|
+
workspace: {name: workspace}
|
28
|
+
}
|
29
|
+
|
30
|
+
@request.post(:vars, {data: data, filter: filter})
|
31
|
+
end
|
32
|
+
|
33
|
+
def update(params={})
|
34
|
+
id = params.delete(:id)
|
35
|
+
data = {
|
36
|
+
attributes: params,
|
37
|
+
type: 'vars',
|
38
|
+
}
|
39
|
+
|
40
|
+
@request.patch(:vars, id, data: data)
|
41
|
+
end
|
42
|
+
|
43
|
+
def delete(params={})
|
44
|
+
@request.delete(:vars, params[:id])
|
45
|
+
end
|
46
|
+
end
|
47
|
+
end
|
48
|
+
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: terraform-enterprise-client
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.5
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Maciej Skierkowski
|
@@ -113,9 +113,13 @@ files:
|
|
113
113
|
- lib/terraform-enterprise/commands/oauth_tokens_command.rb
|
114
114
|
- lib/terraform-enterprise/commands/organizations_command.rb
|
115
115
|
- lib/terraform-enterprise/commands/strings.rb
|
116
|
+
- lib/terraform-enterprise/commands/teams_command.rb
|
117
|
+
- lib/terraform-enterprise/commands/variables_command.rb
|
116
118
|
- lib/terraform-enterprise/commands/workspaces_command.rb
|
117
119
|
- lib/terraform-enterprise/resource_requests/oauth-tokens.rb
|
118
120
|
- lib/terraform-enterprise/resource_requests/organizations.rb
|
121
|
+
- lib/terraform-enterprise/resource_requests/teams.rb
|
122
|
+
- lib/terraform-enterprise/resource_requests/variables.rb
|
119
123
|
- lib/terraform-enterprise/resource_requests/workspaces.rb
|
120
124
|
- lib/terraform-enterprise/version.rb
|
121
125
|
homepage: http://github.com/skierkowski/terraform-enterprise-client
|