terraform-enterprise-client 0.0.3 → 0.0.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +5 -5
- data/README.md +32 -3
- data/lib/terraform-enterprise-client.rb +9 -73
- data/lib/terraform-enterprise/client/request.rb +73 -0
- data/lib/terraform-enterprise/client/resource.rb +19 -0
- data/lib/terraform-enterprise/client/resource_request.rb +10 -0
- data/lib/terraform-enterprise/client/response.rb +37 -0
- data/lib/terraform-enterprise/commands/command.rb +22 -20
- data/lib/terraform-enterprise/commands/formatter.rb +86 -0
- data/lib/terraform-enterprise/commands/oauth_tokens_command.rb +3 -4
- data/lib/terraform-enterprise/commands/organizations_command.rb +7 -7
- data/lib/terraform-enterprise/commands/strings.rb +50 -0
- data/lib/terraform-enterprise/commands/workspaces_command.rb +41 -35
- data/lib/terraform-enterprise/resource_requests/oauth-tokens.rb +11 -0
- data/lib/terraform-enterprise/resource_requests/organizations.rb +28 -0
- data/lib/terraform-enterprise/resource_requests/workspaces.rb +45 -0
- data/lib/terraform-enterprise/version.rb +1 -1
- metadata +53 -8
- data/lib/terraform-enterprise/resources/oauth-tokens.rb +0 -9
- data/lib/terraform-enterprise/resources/organizations.rb +0 -26
- data/lib/terraform-enterprise/resources/workspaces.rb +0 -43
- data/lib/terraform-enterprise/resources_client.rb +0 -8
    
        checksums.yaml
    CHANGED
    
    | @@ -1,7 +1,7 @@ | |
| 1 1 | 
             
            ---
         | 
| 2 | 
            -
             | 
| 3 | 
            -
              metadata.gz:  | 
| 4 | 
            -
              data.tar.gz:  | 
| 2 | 
            +
            SHA1:
         | 
| 3 | 
            +
              metadata.gz: 006ecb0aac424adcf47e1318668b6bcbf0e9c44f
         | 
| 4 | 
            +
              data.tar.gz: fb7e5b66c2143088e6768f63518a4488c2525877
         | 
| 5 5 | 
             
            SHA512:
         | 
| 6 | 
            -
              metadata.gz:  | 
| 7 | 
            -
              data.tar.gz:  | 
| 6 | 
            +
              metadata.gz: 19e5964e0c33f4df21285d0ae17f0dd544c18a7f9e15beb2352ec62de422c9ff8b255618bf3f61c97579c62ffa3ff1d22c6be286e488e76a5d08df2b2bf7954e
         | 
| 7 | 
            +
              data.tar.gz: 7f51d4076fa08f805492b05f4fdf8c1b512acc5e49d9067c708ee60bf26a95573664b737d3f90cf33ba746c1336c3891dc10691061adecebfc229170853394a2
         | 
    
        data/README.md
    CHANGED
    
    | @@ -15,11 +15,13 @@ This gem depends on these other gems for usage at runtime: | |
| 15 15 | 
             
            - [colorize](https://github.com/fazibear/colorize)
         | 
| 16 16 | 
             
            - [thor](https://github.com/erikhuda/thor)
         | 
| 17 17 |  | 
| 18 | 
            -
            ##  | 
| 18 | 
            +
            ## API Client
         | 
| 19 19 |  | 
| 20 | 
            +
            ### Usage
         | 
| 20 21 |  | 
| 21 22 |  | 
| 22 | 
            -
             | 
| 23 | 
            +
             | 
| 24 | 
            +
            #### Basic Example
         | 
| 23 25 |  | 
| 24 26 | 
             
            ```ruby
         | 
| 25 27 | 
             
            require 'terraform-enterprise-client'
         | 
| @@ -57,4 +59,31 @@ The number of supported resources is a subset of the resources exposed via the T | |
| 57 59 |  | 
| 58 60 | 
             
            - `Client#workspaces`
         | 
| 59 61 | 
             
            - `Client#organizations`
         | 
| 60 | 
            -
            - `Client#oauth_tokens`
         | 
| 62 | 
            +
            - `Client#oauth_tokens`
         | 
| 63 | 
            +
             | 
| 64 | 
            +
            ## Command Line Tool
         | 
| 65 | 
            +
             | 
| 66 | 
            +
            Installing the gem installs the `tfe` command line tool. Running `tfe help` provides the help information and list of available subcomands.
         | 
| 67 | 
            +
             | 
| 68 | 
            +
            ### Usage
         | 
| 69 | 
            +
             | 
| 70 | 
            +
            All of the resources, actions and paraeters are documented in the tool and available through the `help` subcommand.
         | 
| 71 | 
            +
             | 
| 72 | 
            +
            #### Basic Usage
         | 
| 73 | 
            +
            ```shell
         | 
| 74 | 
            +
            ➭ tfe help
         | 
| 75 | 
            +
            Commands:
         | 
| 76 | 
            +
              tfe help [COMMAND]              # Describe available commands or one specific command
         | 
| 77 | 
            +
              tfe oauth_tokens <subcommand>   # Manage OAuth tokens
         | 
| 78 | 
            +
              tfe organizations <subcommand>  # Manage organizations
         | 
| 79 | 
            +
              tfe workspaces <subcommand>     # Manage workspaces
         | 
| 80 | 
            +
            ```
         | 
| 81 | 
            +
             | 
| 82 | 
            +
            ### Scripting
         | 
| 83 | 
            +
            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 | 
            +
             | 
| 85 | 
            +
            - `no-color` (Boolean, default: false): Removes ANSI color codes from output
         | 
| 86 | 
            +
            - `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.
         | 
| 87 | 
            +
            - `only` (Array): Only return the fields selected in this space-separated list of field keys.
         | 
| 88 | 
            +
            - `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.
         | 
| 89 | 
            +
            - `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)
         | 
| @@ -1,93 +1,29 @@ | |
| 1 1 | 
             
            require 'json'
         | 
| 2 2 | 
             
            require 'rest-client'
         | 
| 3 3 |  | 
| 4 | 
            -
            require 'terraform-enterprise/ | 
| 5 | 
            -
            require 'terraform-enterprise/ | 
| 6 | 
            -
            require 'terraform-enterprise/ | 
| 4 | 
            +
            require 'terraform-enterprise/client/request'
         | 
| 5 | 
            +
            require 'terraform-enterprise/resource_requests/organizations'
         | 
| 6 | 
            +
            require 'terraform-enterprise/resource_requests/oauth-tokens'
         | 
| 7 | 
            +
            require 'terraform-enterprise/resource_requests/workspaces'
         | 
| 7 8 |  | 
| 8 9 | 
             
            module TerraformEnterprise
         | 
| 9 10 | 
             
              class Client
         | 
| 10 11 | 
             
                attr_accessor :base
         | 
| 11 12 |  | 
| 12 | 
            -
                def initialize( | 
| 13 | 
            -
                  @ | 
| 14 | 
            -
                  @api_key = api_key
         | 
| 15 | 
            -
                  @headers = {
         | 
| 16 | 
            -
                    'Authorization' => "Bearer #{@api_key}",
         | 
| 17 | 
            -
                    'Content-Type' => 'application/vnd.api+json'
         | 
| 18 | 
            -
                  }
         | 
| 13 | 
            +
                def initialize(options={})
         | 
| 14 | 
            +
                  @request = TerraformEnterprise::API::Request.new(options)
         | 
| 19 15 | 
             
                end
         | 
| 20 16 |  | 
| 21 17 | 
             
                def workspaces
         | 
| 22 | 
            -
                  TerraformEnterprise::Workspaces.new( | 
| 18 | 
            +
                  TerraformEnterprise::API::Workspaces.new(@request)
         | 
| 23 19 | 
             
                end
         | 
| 24 20 |  | 
| 25 21 | 
             
                def organizations
         | 
| 26 | 
            -
                  TerraformEnterprise::Organizations.new( | 
| 22 | 
            +
                  TerraformEnterprise::API::Organizations.new(@request)
         | 
| 27 23 | 
             
                end
         | 
| 28 24 |  | 
| 29 25 | 
             
                def oauth_tokens
         | 
| 30 | 
            -
                  TerraformEnterprise::OAuthTokens.new( | 
| 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('/')}"
         | 
| 26 | 
            +
                  TerraformEnterprise::API::OAuthTokens.new(@request)
         | 
| 91 27 | 
             
                end
         | 
| 92 28 | 
             
              end
         | 
| 93 29 | 
             
            end
         | 
| @@ -0,0 +1,73 @@ | |
| 1 | 
            +
            require 'terraform-enterprise/client/response'
         | 
| 2 | 
            +
             | 
| 3 | 
            +
            module TerraformEnterprise
         | 
| 4 | 
            +
              module API
         | 
| 5 | 
            +
                class Request
         | 
| 6 | 
            +
                  attr_accessor :base
         | 
| 7 | 
            +
             | 
| 8 | 
            +
                  def initialize(api_key:, host: 'https://app.terraform.io/api/v2')
         | 
| 9 | 
            +
                    @base    = host
         | 
| 10 | 
            +
                    @api_key = api_key
         | 
| 11 | 
            +
                    @headers = {
         | 
| 12 | 
            +
                      'Authorization' => "Bearer #{@api_key}",
         | 
| 13 | 
            +
                      'Content-Type' => 'application/vnd.api+json'
         | 
| 14 | 
            +
                    }
         | 
| 15 | 
            +
                  end
         | 
| 16 | 
            +
             | 
| 17 | 
            +
                  def get(*path)
         | 
| 18 | 
            +
                    data = path.pop if path.last.is_a?(Hash)
         | 
| 19 | 
            +
                    request(:get, path, data)
         | 
| 20 | 
            +
                  end
         | 
| 21 | 
            +
             | 
| 22 | 
            +
                  def delete(*path)
         | 
| 23 | 
            +
                    data = path.pop if path.last.is_a?(Hash)
         | 
| 24 | 
            +
                    request(:delete, path,data)
         | 
| 25 | 
            +
                  end
         | 
| 26 | 
            +
             | 
| 27 | 
            +
                  def post(*path)
         | 
| 28 | 
            +
                    data = path.pop if path.last.is_a?(Hash)
         | 
| 29 | 
            +
                    request(:post, path, data)
         | 
| 30 | 
            +
                  end
         | 
| 31 | 
            +
             | 
| 32 | 
            +
                  def put(*path)
         | 
| 33 | 
            +
                    data = path.pop if path.last.is_a?(Hash)
         | 
| 34 | 
            +
                    request(:put,data,data)
         | 
| 35 | 
            +
                  end
         | 
| 36 | 
            +
             | 
| 37 | 
            +
                  def patch(*path)
         | 
| 38 | 
            +
                    data = path.pop if path.last.is_a?(Hash)
         | 
| 39 | 
            +
                    request(:patch,path,data)
         | 
| 40 | 
            +
                  end
         | 
| 41 | 
            +
             | 
| 42 | 
            +
                  def request(method, path, data={}, headers={})
         | 
| 43 | 
            +
                    request = {
         | 
| 44 | 
            +
                      method:  method,
         | 
| 45 | 
            +
                      url:     uri(path),
         | 
| 46 | 
            +
                      headers: @headers.merge(headers || {})
         | 
| 47 | 
            +
                    }
         | 
| 48 | 
            +
                    if data
         | 
| 49 | 
            +
                      if method==:get || method==:delete
         | 
| 50 | 
            +
                        request[:headers][:params] = data
         | 
| 51 | 
            +
                      else
         | 
| 52 | 
            +
                        request[:payload] = data.is_a?(String) ? data : data.to_json
         | 
| 53 | 
            +
                      end
         | 
| 54 | 
            +
                    end
         | 
| 55 | 
            +
             | 
| 56 | 
            +
                    response = begin
         | 
| 57 | 
            +
                      RestClient::Request.execute(request)
         | 
| 58 | 
            +
                    rescue RestClient::ExceptionWithResponse => ex
         | 
| 59 | 
            +
                      ex.response
         | 
| 60 | 
            +
                    end
         | 
| 61 | 
            +
             | 
| 62 | 
            +
                    TerraformEnterprise::API::Response.new(response)
         | 
| 63 | 
            +
                  end
         | 
| 64 | 
            +
             | 
| 65 | 
            +
                  private
         | 
| 66 | 
            +
             | 
| 67 | 
            +
                  def uri(path=[])
         | 
| 68 | 
            +
                    return path if path.is_a?(String) && path.start_with?("http")
         | 
| 69 | 
            +
                    "#{@base}/#{path.map{|p| p.to_s}.join('/')}"
         | 
| 70 | 
            +
                  end
         | 
| 71 | 
            +
                end
         | 
| 72 | 
            +
              end
         | 
| 73 | 
            +
            end
         | 
| @@ -0,0 +1,19 @@ | |
| 1 | 
            +
            module TerraformEnterprise
         | 
| 2 | 
            +
              module API
         | 
| 3 | 
            +
                class Resource
         | 
| 4 | 
            +
                  attr_accessor :type, :attributes, :id, :relationships, :links, :errors, :success
         | 
| 5 | 
            +
                  def initialize(data)
         | 
| 6 | 
            +
                    @id               = data['id']
         | 
| 7 | 
            +
                    @type             = data['type']
         | 
| 8 | 
            +
                    @attributes       = data['attributes'] || {}
         | 
| 9 | 
            +
                    @relationships    = data['relationships'] || {}
         | 
| 10 | 
            +
                    @links            = data['links'] || []
         | 
| 11 | 
            +
                    @errors           = data['errors'] || []
         | 
| 12 | 
            +
                  end
         | 
| 13 | 
            +
             | 
| 14 | 
            +
                  def has_errors?
         | 
| 15 | 
            +
                    !@errors.empty?
         | 
| 16 | 
            +
                  end
         | 
| 17 | 
            +
                end
         | 
| 18 | 
            +
              end
         | 
| 19 | 
            +
            end
         | 
| @@ -0,0 +1,37 @@ | |
| 1 | 
            +
            require 'terraform-enterprise/client/resource'
         | 
| 2 | 
            +
             | 
| 3 | 
            +
            module TerraformEnterprise
         | 
| 4 | 
            +
              module API
         | 
| 5 | 
            +
                class Response
         | 
| 6 | 
            +
                  attr_reader :code, :body, :data, :resource, :resources, :errors
         | 
| 7 | 
            +
                  def initialize(rest_client_response)
         | 
| 8 | 
            +
                    @code = rest_client_response.code
         | 
| 9 | 
            +
                    @body = parse(rest_client_response.body)
         | 
| 10 | 
            +
                    @data = (@body.is_a?(Hash) && @body['data']) ? @body['data'] : @body
         | 
| 11 | 
            +
                    if @data.is_a?(Hash)
         | 
| 12 | 
            +
                      @resource = TerraformEnterprise::API::Resource.new(@data) 
         | 
| 13 | 
            +
                    end
         | 
| 14 | 
            +
                    if @data.is_a?(Array) && @data.all?{|a| a.is_a?(Hash)}
         | 
| 15 | 
            +
                      @resources = @data.map do |item|
         | 
| 16 | 
            +
                        TerraformEnterprise::API::Resource.new(item)
         | 
| 17 | 
            +
                      end
         | 
| 18 | 
            +
                    end
         | 
| 19 | 
            +
                    if has_errors?
         | 
| 20 | 
            +
                      @errors = @body['errors']
         | 
| 21 | 
            +
                    end
         | 
| 22 | 
            +
                  end
         | 
| 23 | 
            +
             | 
| 24 | 
            +
                  def has_errors?
         | 
| 25 | 
            +
                    @body.is_a?(Hash) && @body['errors'] && @body['errors'].is_a?(Array)
         | 
| 26 | 
            +
                  end
         | 
| 27 | 
            +
             | 
| 28 | 
            +
                  private
         | 
| 29 | 
            +
             | 
| 30 | 
            +
                  def parse(str)
         | 
| 31 | 
            +
                    JSON.parse(str)
         | 
| 32 | 
            +
                  rescue JSON::ParserError
         | 
| 33 | 
            +
                    str
         | 
| 34 | 
            +
                  end
         | 
| 35 | 
            +
                end
         | 
| 36 | 
            +
              end
         | 
| 37 | 
            +
            end
         | 
| @@ -1,33 +1,28 @@ | |
| 1 | 
            -
            require ' | 
| 2 | 
            -
            require 'colorize'
         | 
| 1 | 
            +
            require 'json'
         | 
| 3 2 |  | 
| 4 3 | 
             
            require 'terraform-enterprise-client'
         | 
| 4 | 
            +
            require 'terraform-enterprise/commands/formatter'
         | 
| 5 | 
            +
            require 'terraform-enterprise/commands/strings'
         | 
| 5 6 |  | 
| 6 7 | 
             
            module TerraformEnterprise
         | 
| 7 8 | 
             
              module Commands
         | 
| 8 9 | 
             
                class Command < Thor
         | 
| 9 | 
            -
                  class_option : | 
| 10 | 
            +
                  class_option :host, type: :string, desc: 'Set host address for private Terraform Enterprise'
         | 
| 11 | 
            +
                  class_option :token, type: :string, desc: 'Set the auth token, defaults to TERRAFORM_ENTERPRISE_TOKEN environment variable'
         | 
| 12 | 
            +
                  class_option :color, type: :boolean, default: true, desc: 'If disabled the ANSI color codes will not be used'
         | 
| 13 | 
            +
                  class_option :except, type: :array, desc: 'List of fields that should not be displayed'
         | 
| 14 | 
            +
                  class_option :only, type: :array, desc: 'List of fields that should be displayed'
         | 
| 15 | 
            +
                  class_option :all, type: :boolean, default: false, desc: "Return all fields, not just summary"
         | 
| 16 | 
            +
                  class_option :value, type: :boolean, default: false, desc: 'Only return the value; i.e. do not show keys'
         | 
| 10 17 |  | 
| 11 18 | 
             
                  no_commands do
         | 
| 12 | 
            -
                    def render(obj)
         | 
| 13 | 
            -
                       | 
| 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
         | 
| 19 | 
            +
                    def render(obj, default_options={})
         | 
| 20 | 
            +
                      calculated_options = if(options[:all])
         | 
| 21 | 
            +
                        symbolize_keys(options.to_h)
         | 
| 28 22 | 
             
                      else
         | 
| 29 | 
            -
                         | 
| 23 | 
            +
                        symbolize_keys(default_options).merge(symbolize_keys(options.to_h))
         | 
| 30 24 | 
             
                      end
         | 
| 25 | 
            +
                      TerraformEnterprise::Commands::Formatter.render obj, calculated_options
         | 
| 31 26 | 
             
                    end
         | 
| 32 27 |  | 
| 33 28 | 
             
                    def client
         | 
| @@ -36,6 +31,13 @@ module TerraformEnterprise | |
| 36 31 | 
             
                      settings[:host]    = options[:host] if options[:host]
         | 
| 37 32 | 
             
                      TerraformEnterprise::Client.new(settings)
         | 
| 38 33 | 
             
                    end
         | 
| 34 | 
            +
             | 
| 35 | 
            +
                    private
         | 
| 36 | 
            +
             | 
| 37 | 
            +
                    def symbolize_keys(hash)
         | 
| 38 | 
            +
                      JSON.parse(JSON[hash], symbolize_names: true)
         | 
| 39 | 
            +
                    end
         | 
| 40 | 
            +
             | 
| 39 41 | 
             
                  end
         | 
| 40 42 | 
             
                end
         | 
| 41 43 | 
             
              end
         | 
| @@ -0,0 +1,86 @@ | |
| 1 | 
            +
            require 'yaml'
         | 
| 2 | 
            +
            require 'colorize'
         | 
| 3 | 
            +
            require 'terminal-table'
         | 
| 4 | 
            +
             | 
| 5 | 
            +
            require 'terraform-enterprise-client'
         | 
| 6 | 
            +
             | 
| 7 | 
            +
            module TerraformEnterprise
         | 
| 8 | 
            +
              module Commands
         | 
| 9 | 
            +
                module Formatter
         | 
| 10 | 
            +
                  def self.render(obj, options={})
         | 
| 11 | 
            +
                    String.disable_colorization = !options[:color]
         | 
| 12 | 
            +
                    if obj.is_a?(TerraformEnterprise::API::Response)
         | 
| 13 | 
            +
                      if obj.code >= 200 && obj.code < 300
         | 
| 14 | 
            +
                        if obj.resources
         | 
| 15 | 
            +
                          puts render_resource_table(obj.resources, options)
         | 
| 16 | 
            +
                        elsif obj.resource
         | 
| 17 | 
            +
                          puts render_resource(obj.resource, options) 
         | 
| 18 | 
            +
                        else
         | 
| 19 | 
            +
                          puts "Success (#{obj.code})".green
         | 
| 20 | 
            +
                        end
         | 
| 21 | 
            +
                      elsif obj.has_errors?
         | 
| 22 | 
            +
                        obj.errors.each do |error|
         | 
| 23 | 
            +
                          puts "Error (#{error['status']}): #{error['title']}".red
         | 
| 24 | 
            +
                        end
         | 
| 25 | 
            +
                      else
         | 
| 26 | 
            +
                        puts "Unknown server response (#{obj.code})".yellow
         | 
| 27 | 
            +
                        puts obj.body
         | 
| 28 | 
            +
                      end
         | 
| 29 | 
            +
                    else
         | 
| 30 | 
            +
                      puts "Unknown content".yellow
         | 
| 31 | 
            +
                      puts obj
         | 
| 32 | 
            +
                    end
         | 
| 33 | 
            +
                  end
         | 
| 34 | 
            +
             | 
| 35 | 
            +
                  private
         | 
| 36 | 
            +
             | 
| 37 | 
            +
                  def self.parse_resource(resource, options)
         | 
| 38 | 
            +
                    parsed_resource = flatten_dotted_hash(resource.attributes)
         | 
| 39 | 
            +
                    parsed_resource = {'id' => resource.id}.merge(parsed_resource) if resource.id
         | 
| 40 | 
            +
                    (options[:except] || []).each do |excluded|
         | 
| 41 | 
            +
                      parsed_resource.delete_if {|key,value| key.to_s.start_with?(excluded.to_s) }
         | 
| 42 | 
            +
                    end
         | 
| 43 | 
            +
                    if options[:only] && options[:only].length > 0
         | 
| 44 | 
            +
                      parsed_resource.select! do |key, value|
         | 
| 45 | 
            +
                        options[:only].any?{ |included| key.to_s.start_with?(included.to_s) }
         | 
| 46 | 
            +
                      end
         | 
| 47 | 
            +
                    end
         | 
| 48 | 
            +
                    parsed_resource
         | 
| 49 | 
            +
                  end
         | 
| 50 | 
            +
             | 
| 51 | 
            +
                  def self.render_resource(resource, options)
         | 
| 52 | 
            +
                    parsed_resource = parse_resource(resource, options)
         | 
| 53 | 
            +
                    parsed_resource.keys.map do |key|
         | 
| 54 | 
            +
                      value = parsed_resource[key]
         | 
| 55 | 
            +
                      options[:value] ? value : "#{key.bold}: #{value}"
         | 
| 56 | 
            +
                    end.join("\n")
         | 
| 57 | 
            +
                  end
         | 
| 58 | 
            +
             | 
| 59 | 
            +
                  def self.render_resource_table(resources, options)
         | 
| 60 | 
            +
                    if options[:table] && !options[:value]
         | 
| 61 | 
            +
                      parsed_resources = resources.map{|resource| parse_resource(resource,options)}
         | 
| 62 | 
            +
                      keys = parsed_resources.map{|resource| resource.keys }.flatten.uniq
         | 
| 63 | 
            +
                      rows = parsed_resources.map do |resource|
         | 
| 64 | 
            +
                        keys.map{|key| resource[key]}
         | 
| 65 | 
            +
                      end
         | 
| 66 | 
            +
                      table = Terminal::Table.new headings: keys, rows: rows
         | 
| 67 | 
            +
                      table
         | 
| 68 | 
            +
                    else
         | 
| 69 | 
            +
                      out = resources.map{|resource| render_resource(resource, options)}.join("\n#{'-' * 10}\n")
         | 
| 70 | 
            +
                    end
         | 
| 71 | 
            +
                  end
         | 
| 72 | 
            +
             | 
| 73 | 
            +
                  def self.flatten_hash(h,f=[],g={})
         | 
| 74 | 
            +
                    return g.update({ f=>h }) unless h.is_a?(Hash) || h.is_a?(Array)
         | 
| 75 | 
            +
                    h.each { |k,r| flatten_hash(r,f+[k],g) } if h.is_a?(Hash)
         | 
| 76 | 
            +
                    h.each_with_index { |r, k| flatten_hash(r,f+[k],g) } if h.is_a?(Array)
         | 
| 77 | 
            +
                    g
         | 
| 78 | 
            +
                  end
         | 
| 79 | 
            +
             | 
| 80 | 
            +
                  def self.flatten_dotted_hash(source)
         | 
| 81 | 
            +
                    flat = flatten_hash(source)
         | 
| 82 | 
            +
                    flat.keys.each_with_object({}) { |key, h| h[key.join('.')] = flat[key] }  
         | 
| 83 | 
            +
                  end
         | 
| 84 | 
            +
                end
         | 
| 85 | 
            +
              end
         | 
| 86 | 
            +
            end
         | 
| @@ -4,11 +4,10 @@ require 'terraform-enterprise-client' | |
| 4 4 | 
             
            module TerraformEnterprise
         | 
| 5 5 | 
             
              module Commands
         | 
| 6 6 | 
             
                class OAuthTokensCommand < TerraformEnterprise::Commands::Command
         | 
| 7 | 
            -
                  class_option : | 
| 8 | 
            -
                  class_option :token, type: :string
         | 
| 9 | 
            -
                  class_option :organization, required: true, type: :string, desc: 'Organization name'
         | 
| 7 | 
            +
                  class_option :organization, required: true, type: :string, desc: STRINGS[:oauth_tokens][:attributes][:organization]
         | 
| 10 8 |  | 
| 11 | 
            -
                  desc 'list',  | 
| 9 | 
            +
                  desc 'list', STRINGS[:oauth_tokens][:commands][:list]
         | 
| 10 | 
            +
                  option :table, type: :boolean, default: true, desc: STRINGS[:options][:table]
         | 
| 12 11 | 
             
                  def list
         | 
| 13 12 | 
             
                    render client.oauth_tokens.list(options)
         | 
| 14 13 | 
             
                  end
         | 
| @@ -3,25 +3,25 @@ require 'terraform-enterprise/commands/command' | |
| 3 3 | 
             
            module TerraformEnterprise
         | 
| 4 4 | 
             
              module Commands
         | 
| 5 5 | 
             
                class OrganizationsCommand < TerraformEnterprise::Commands::Command
         | 
| 6 | 
            -
                   | 
| 7 | 
            -
                  class_option :token, type: :string
         | 
| 6 | 
            +
                  CMD_STR = STRINGS[:organizations][:commands]
         | 
| 8 7 |  | 
| 9 | 
            -
                  desc 'list',  | 
| 8 | 
            +
                  desc 'list', CMD_STR[:list]
         | 
| 9 | 
            +
                  option :table, type: :boolean, default: true, desc: STRINGS[:options][:table]
         | 
| 10 10 | 
             
                  def list
         | 
| 11 | 
            -
                    render client.organizations.list
         | 
| 11 | 
            +
                    render client.organizations.list, only: [:id, :name, 'created-at', :email]
         | 
| 12 12 | 
             
                  end
         | 
| 13 13 |  | 
| 14 | 
            -
                  desc 'create <name> <email>',  | 
| 14 | 
            +
                  desc 'create <name> <email>', CMD_STR[:create]
         | 
| 15 15 | 
             
                  def create(name, email)
         | 
| 16 16 | 
             
                    render client.organizations.create(name: name, email: email)
         | 
| 17 17 | 
             
                  end
         | 
| 18 18 |  | 
| 19 | 
            -
                  desc 'get <name>',  | 
| 19 | 
            +
                  desc 'get <name>', CMD_STR[:get]
         | 
| 20 20 | 
             
                  def get(name)
         | 
| 21 21 | 
             
                    render client.organizations.get(name:name)
         | 
| 22 22 | 
             
                  end
         | 
| 23 23 |  | 
| 24 | 
            -
                  desc 'delete <name>',  | 
| 24 | 
            +
                  desc 'delete <name>', CMD_STR[:delete]
         | 
| 25 25 | 
             
                  def delete(name)
         | 
| 26 26 | 
             
                    render client.organizations.delete(name:name)
         | 
| 27 27 | 
             
                  end
         | 
| @@ -0,0 +1,50 @@ | |
| 1 | 
            +
             | 
| 2 | 
            +
             | 
| 3 | 
            +
            module TerraformEnterprise
         | 
| 4 | 
            +
              module Commands
         | 
| 5 | 
            +
                STRINGS = {
         | 
| 6 | 
            +
                  options: {
         | 
| 7 | 
            +
                    table: 'Format list output as a table'
         | 
| 8 | 
            +
                  },
         | 
| 9 | 
            +
                  workspaces: {
         | 
| 10 | 
            +
                    attributes: {
         | 
| 11 | 
            +
                      terraform_version: 'Version of Terraform to use for this workspace.',
         | 
| 12 | 
            +
                      working_directory: 'Relative path that Terraform will execute within.',
         | 
| 13 | 
            +
                      oauth_token: 'VCS Connection (OAuth Conection + Token) to use as identified; obtained from the oauth_tokens subcommand.',
         | 
| 14 | 
            +
                      branch: 'Repository branch that Terraform will execute from.',
         | 
| 15 | 
            +
                      ingress_submodules: 'Submodules should be fetched when cloning the VCS repository.',
         | 
| 16 | 
            +
                      repo: 'Reference to VCS repository in the format :org/:repo.',
         | 
| 17 | 
            +
                      import_legacy: 'Specifies the legacy Environment to use as the source of the migration/',
         | 
| 18 | 
            +
                      organization: 'Organization to which this workspaces belongs to.',
         | 
| 19 | 
            +
                      auto_apply: 'Auto-apply enabled',
         | 
| 20 | 
            +
                    },
         | 
| 21 | 
            +
                    commands: {
         | 
| 22 | 
            +
                      create: 'Create a new workspace',
         | 
| 23 | 
            +
                      list: 'List worksapces in the organization',
         | 
| 24 | 
            +
                      get: 'Get workspace details by name',
         | 
| 25 | 
            +
                      delete: 'Delete the workspace',
         | 
| 26 | 
            +
                      update: 'Update the workspace',
         | 
| 27 | 
            +
                      lock: 'Lock the workspace by workspace ID',
         | 
| 28 | 
            +
                      unlock: 'Unlock the workspace by workspace ID'
         | 
| 29 | 
            +
                    }
         | 
| 30 | 
            +
                  },
         | 
| 31 | 
            +
                  organizations: {
         | 
| 32 | 
            +
                    commands: {
         | 
| 33 | 
            +
                      create: 'Create a new organization',
         | 
| 34 | 
            +
                      list: 'List all the organizations',
         | 
| 35 | 
            +
                      get: 'Get organization details by name',
         | 
| 36 | 
            +
                      delete: 'Delete the organization',
         | 
| 37 | 
            +
                    },
         | 
| 38 | 
            +
                    attributes: { }
         | 
| 39 | 
            +
                  },
         | 
| 40 | 
            +
                  oauth_tokens: {
         | 
| 41 | 
            +
                    commands: {
         | 
| 42 | 
            +
                      list: 'List the OAuth tokens in the organization'
         | 
| 43 | 
            +
                    },
         | 
| 44 | 
            +
                    attributes: {
         | 
| 45 | 
            +
                      organization: 'Organization to which this OAuth Token belongs to.'
         | 
| 46 | 
            +
                    }
         | 
| 47 | 
            +
                  }
         | 
| 48 | 
            +
                }
         | 
| 49 | 
            +
              end
         | 
| 50 | 
            +
            end
         | 
| @@ -3,78 +3,84 @@ require 'terraform-enterprise/commands/command' | |
| 3 3 | 
             
            module TerraformEnterprise
         | 
| 4 4 | 
             
              module Commands
         | 
| 5 5 | 
             
                class WorkspacesCommand < TerraformEnterprise::Commands::Command
         | 
| 6 | 
            -
                   | 
| 7 | 
            -
                   | 
| 8 | 
            -
                  class_option :organization, required: true, type: :string, desc: 'Organization name'
         | 
| 6 | 
            +
                  ATTR_STR = STRINGS[:workspaces][:attributes]
         | 
| 7 | 
            +
                  CMD_STR = STRINGS[:workspaces][:commands]
         | 
| 9 8 |  | 
| 10 | 
            -
                  desc 'list',  | 
| 9 | 
            +
                  desc 'list', CMD_STR[:list]
         | 
| 10 | 
            +
                  option :organization, required: true, type: :string, desc: ATTR_STR[:organization]
         | 
| 11 | 
            +
                  option :table, type: :boolean, default: true, desc: STRINGS[:options][:table]
         | 
| 11 12 | 
             
                  def list
         | 
| 12 | 
            -
                    render client.workspaces.list(options)
         | 
| 13 | 
            +
                    render client.workspaces.list(options), except:[:permissions, :actions, :environment, 'created-at']
         | 
| 13 14 | 
             
                  end
         | 
| 14 15 |  | 
| 15 | 
            -
                  desc 'create <name>',  | 
| 16 | 
            -
                  option :terraform_version, type: :string, desc:  | 
| 17 | 
            -
                  option :working_directory, type: :string, desc:  | 
| 18 | 
            -
                  option :oauth_token, type: :string, desc:  | 
| 19 | 
            -
                  option :branch, type: :string, desc:  | 
| 20 | 
            -
                  option :ingress_submodules, type: :boolean,  | 
| 21 | 
            -
                  option :repo, type: :string, desc:  | 
| 22 | 
            -
                  option : | 
| 16 | 
            +
                  desc 'create <name>', CMD_STR[:create]
         | 
| 17 | 
            +
                  option :terraform_version, type: :string, desc: ATTR_STR[:terraform_version]
         | 
| 18 | 
            +
                  option :working_directory, type: :string, desc: ATTR_STR[:working_directory]
         | 
| 19 | 
            +
                  option :oauth_token, type: :string, desc: ATTR_STR[:oauth_token]
         | 
| 20 | 
            +
                  option :branch, type: :string, desc: ATTR_STR[:branch]
         | 
| 21 | 
            +
                  option :ingress_submodules, type: :boolean, desc: ATTR_STR[:ingress_submodules]
         | 
| 22 | 
            +
                  option :repo, type: :string, desc: ATTR_STR[:repos]
         | 
| 23 | 
            +
                  option :import_legacy_environment, type: :string, desc: ATTR_STR[:import_legacy]
         | 
| 24 | 
            +
                  option :organization, required: true, type: :string, desc: ATTR_STR[:organization]
         | 
| 23 25 | 
             
                  def create(name)
         | 
| 24 26 | 
             
                    params = {
         | 
| 25 27 | 
             
                      organization: options[:organization],
         | 
| 26 28 | 
             
                      name: name,
         | 
| 27 29 | 
             
                      '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 30 | 
             
                    }
         | 
| 31 | 
            +
                    if options[:branch] || options[:repo] || options[:oauth_token] || options[:ingress_submodules]
         | 
| 32 | 
            +
                      repo = {}
         | 
| 33 | 
            +
                      repo['branch']             = options[:branch] if options[:branch]
         | 
| 34 | 
            +
                      repo['identifier']         = options[:repo] if options[:repo]
         | 
| 35 | 
            +
                      repo['oauth-token-id']     = options[:oauth_token] if options[:oauth_token]
         | 
| 36 | 
            +
                      repo['ingress-submodules'] = options[:ingress_submodules] if options[:ingress_submodules]
         | 
| 37 | 
            +
                      params['vcs-repo'] = repo
         | 
| 38 | 
            +
                    end
         | 
| 35 39 |  | 
| 36 | 
            -
                    params['migration-environment'] = options[: | 
| 40 | 
            +
                    params['migration-environment'] = options[:import_legacy_environment] if options[:import_legacy_environment]
         | 
| 37 41 | 
             
                    params['terraform_version']     = options[:terraform_version] if options[:terraform_version]
         | 
| 38 | 
            -
                    
         | 
| 39 | 
            -
                    render client.workspaces.create(params)
         | 
| 42 | 
            +
                    render client.workspaces.create(params), except:[:permissions, :actions, :environment]
         | 
| 40 43 | 
             
                  end
         | 
| 41 44 |  | 
| 42 | 
            -
                  desc 'get <name>',  | 
| 45 | 
            +
                  desc 'get <name>', CMD_STR[:get]
         | 
| 46 | 
            +
                  option :organization, required: true, type: :string, desc: ATTR_STR[:organization]
         | 
| 43 47 | 
             
                  def get(name)
         | 
| 44 48 | 
             
                    params = {
         | 
| 45 49 | 
             
                      organization: options[:organization],
         | 
| 46 50 | 
             
                      workspace: name
         | 
| 47 51 | 
             
                    }
         | 
| 48 | 
            -
                    render client.workspaces.get(params)
         | 
| 52 | 
            +
                    render client.workspaces.get(params), except:[:permissions, :actions, :environment]
         | 
| 49 53 | 
             
                  end
         | 
| 50 54 |  | 
| 51 | 
            -
                  desc 'delete <name>',  | 
| 55 | 
            +
                  desc 'delete <name>', CMD_STR[:delete]
         | 
| 56 | 
            +
                  option :organization, required: true, type: :string, desc: ATTR_STR[:organization]
         | 
| 52 57 | 
             
                  def delete(name)
         | 
| 53 58 | 
             
                    params = {
         | 
| 54 59 | 
             
                      organization: options[:organization],
         | 
| 55 60 | 
             
                      workspace: name
         | 
| 56 61 | 
             
                    }
         | 
| 57 | 
            -
                    render client.workspaces.delete(params)
         | 
| 62 | 
            +
                    render client.workspaces.delete(params), except:[:permissions, :actions, :environment]
         | 
| 58 63 | 
             
                  end
         | 
| 59 64 |  | 
| 60 | 
            -
                  desc 'update <name>',  | 
| 61 | 
            -
                  option :working_directory, type: :string, desc:  | 
| 62 | 
            -
                  option :terraform_version, type: :string, desc:  | 
| 63 | 
            -
                  option :auto_apply, type: :boolean, desc:  | 
| 65 | 
            +
                  desc 'update <name>', CMD_STR[:update]
         | 
| 66 | 
            +
                  option :working_directory, type: :string, desc: ATTR_STR[:working_directory]
         | 
| 67 | 
            +
                  option :terraform_version, type: :string, desc: ATTR_STR[:terraform_version]
         | 
| 68 | 
            +
                  option :auto_apply, type: :boolean, desc: ATTR_STR[:auto_apply]
         | 
| 69 | 
            +
                  option :organization, required: true, type: :string, desc: ATTR_STR[:organization]
         | 
| 64 70 | 
             
                  def update(name)
         | 
| 65 71 | 
             
                    params = options
         | 
| 66 72 | 
             
                    params[:workspace] = name
         | 
| 67 | 
            -
                    render client.workspaces.update(params)
         | 
| 73 | 
            +
                    render client.workspaces.update(params), except:[:permissions, :actions, :environment]
         | 
| 68 74 | 
             
                  end
         | 
| 69 75 |  | 
| 70 | 
            -
                  desc 'lock <id>',  | 
| 76 | 
            +
                  desc 'lock <id>', CMD_STR[:lock]
         | 
| 71 77 | 
             
                  def lock(id)
         | 
| 72 | 
            -
                    render client.workspaces.action(action: :lock, id: id)
         | 
| 78 | 
            +
                    render client.workspaces.action(action: :lock, id: id), except:[:permissions, :actions, :environment]
         | 
| 73 79 | 
             
                  end
         | 
| 74 80 |  | 
| 75 | 
            -
                  desc 'unlock <id>',  | 
| 81 | 
            +
                  desc 'unlock <id>', CMD_STR[:unlock]
         | 
| 76 82 | 
             
                  def unlock(id)
         | 
| 77 | 
            -
                    render client.workspaces.action(action: :unlock, id: id)
         | 
| 83 | 
            +
                    render client.workspaces.action(action: :unlock, id: id), except:[:permissions, :actions, :environment]
         | 
| 78 84 | 
             
                  end
         | 
| 79 85 | 
             
                end
         | 
| 80 86 | 
             
              end
         | 
| @@ -0,0 +1,11 @@ | |
| 1 | 
            +
            require "terraform-enterprise/client/resource_request"
         | 
| 2 | 
            +
             | 
| 3 | 
            +
            module TerraformEnterprise  
         | 
| 4 | 
            +
              module API
         | 
| 5 | 
            +
                class OAuthTokens < TerraformEnterprise::API::ResourceRequest
         | 
| 6 | 
            +
                  def list(params={})
         | 
| 7 | 
            +
                    @request.get(:organizations, params[:organization], 'oauth-tokens')
         | 
| 8 | 
            +
                  end
         | 
| 9 | 
            +
                end
         | 
| 10 | 
            +
              end
         | 
| 11 | 
            +
            end
         | 
| @@ -0,0 +1,28 @@ | |
| 1 | 
            +
            require "terraform-enterprise/client/resource_request"
         | 
| 2 | 
            +
             | 
| 3 | 
            +
            module TerraformEnterprise  
         | 
| 4 | 
            +
              module API
         | 
| 5 | 
            +
                class Organizations < TerraformEnterprise::API::ResourceRequest
         | 
| 6 | 
            +
                  def list(params={})
         | 
| 7 | 
            +
                    @request.get(:organizations)
         | 
| 8 | 
            +
                  end
         | 
| 9 | 
            +
             | 
| 10 | 
            +
                  def get(params={})
         | 
| 11 | 
            +
                    @request.get(:organizations, params[:name])
         | 
| 12 | 
            +
                  end
         | 
| 13 | 
            +
             | 
| 14 | 
            +
                  def create(params={})
         | 
| 15 | 
            +
                    data = {
         | 
| 16 | 
            +
                      attributes: params,
         | 
| 17 | 
            +
                      type: 'organizations'
         | 
| 18 | 
            +
                    }
         | 
| 19 | 
            +
             | 
| 20 | 
            +
                    @request.post(:organizations, data: data)
         | 
| 21 | 
            +
                  end
         | 
| 22 | 
            +
             | 
| 23 | 
            +
                  def delete(params={})
         | 
| 24 | 
            +
                    @request.delete(:organizations, params[:name])
         | 
| 25 | 
            +
                  end
         | 
| 26 | 
            +
                end
         | 
| 27 | 
            +
              end
         | 
| 28 | 
            +
            end
         | 
| @@ -0,0 +1,45 @@ | |
| 1 | 
            +
            require "terraform-enterprise/client/resource_request"
         | 
| 2 | 
            +
             | 
| 3 | 
            +
            module TerraformEnterprise  
         | 
| 4 | 
            +
              module API
         | 
| 5 | 
            +
                class Workspaces < TerraformEnterprise::API::ResourceRequest
         | 
| 6 | 
            +
                  def list(params={})
         | 
| 7 | 
            +
                    @request.get(:organizations, params[:organization], :workspaces)
         | 
| 8 | 
            +
                  end
         | 
| 9 | 
            +
             | 
| 10 | 
            +
                  def get(params={})
         | 
| 11 | 
            +
                    @request.get(:organizations, params[:organization], :workspaces, params[:workspace])
         | 
| 12 | 
            +
                  end
         | 
| 13 | 
            +
             | 
| 14 | 
            +
                  def create(params={})
         | 
| 15 | 
            +
                    org = params.delete(:organization)
         | 
| 16 | 
            +
                    data = {
         | 
| 17 | 
            +
                      attributes: params,
         | 
| 18 | 
            +
                      type: 'workspaces'
         | 
| 19 | 
            +
                    }
         | 
| 20 | 
            +
             | 
| 21 | 
            +
                    @request.post(:organizations, org, :workspaces, data: data)
         | 
| 22 | 
            +
                  end
         | 
| 23 | 
            +
             | 
| 24 | 
            +
                  def update(params={})
         | 
| 25 | 
            +
                    org = params.delete(:organization)
         | 
| 26 | 
            +
                    id  = params.delete(:workspace)
         | 
| 27 | 
            +
             | 
| 28 | 
            +
                    data = {
         | 
| 29 | 
            +
                      attributes: params,
         | 
| 30 | 
            +
                      type: 'workspaces'
         | 
| 31 | 
            +
                    }
         | 
| 32 | 
            +
             | 
| 33 | 
            +
                    @request.patch(:organizations, org, :workspaces, id, data: data)
         | 
| 34 | 
            +
                  end
         | 
| 35 | 
            +
             | 
| 36 | 
            +
                  def delete(params={})
         | 
| 37 | 
            +
                    @request.delete(:organizations, params[:organization], :workspaces, params[:workspace])
         | 
| 38 | 
            +
                  end
         | 
| 39 | 
            +
             | 
| 40 | 
            +
                  def action(params={})
         | 
| 41 | 
            +
                    @request.post(:workspaces, params[:id], :actions, params[:action].to_sym)
         | 
| 42 | 
            +
                  end
         | 
| 43 | 
            +
                end
         | 
| 44 | 
            +
              end
         | 
| 45 | 
            +
            end
         | 
    
        metadata
    CHANGED
    
    | @@ -1,20 +1,23 @@ | |
| 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.4
         | 
| 5 5 | 
             
            platform: ruby
         | 
| 6 6 | 
             
            authors:
         | 
| 7 7 | 
             
            - Maciej Skierkowski
         | 
| 8 8 | 
             
            autorequire: 
         | 
| 9 9 | 
             
            bindir: bin
         | 
| 10 10 | 
             
            cert_chain: []
         | 
| 11 | 
            -
            date: 2018-03- | 
| 11 | 
            +
            date: 2018-03-26 00:00:00.000000000 Z
         | 
| 12 12 | 
             
            dependencies:
         | 
| 13 13 | 
             
            - !ruby/object:Gem::Dependency
         | 
| 14 14 | 
             
              name: rest-client
         | 
| 15 15 | 
             
              requirement: !ruby/object:Gem::Requirement
         | 
| 16 16 | 
             
                requirements:
         | 
| 17 17 | 
             
                - - "~>"
         | 
| 18 | 
            +
                  - !ruby/object:Gem::Version
         | 
| 19 | 
            +
                    version: '2.0'
         | 
| 20 | 
            +
                - - ">="
         | 
| 18 21 | 
             
                  - !ruby/object:Gem::Version
         | 
| 19 22 | 
             
                    version: 2.0.2
         | 
| 20 23 | 
             
              type: :runtime
         | 
| @@ -22,6 +25,9 @@ dependencies: | |
| 22 25 | 
             
              version_requirements: !ruby/object:Gem::Requirement
         | 
| 23 26 | 
             
                requirements:
         | 
| 24 27 | 
             
                - - "~>"
         | 
| 28 | 
            +
                  - !ruby/object:Gem::Version
         | 
| 29 | 
            +
                    version: '2.0'
         | 
| 30 | 
            +
                - - ">="
         | 
| 25 31 | 
             
                  - !ruby/object:Gem::Version
         | 
| 26 32 | 
             
                    version: 2.0.2
         | 
| 27 33 | 
             
            - !ruby/object:Gem::Dependency
         | 
| @@ -29,6 +35,9 @@ dependencies: | |
| 29 35 | 
             
              requirement: !ruby/object:Gem::Requirement
         | 
| 30 36 | 
             
                requirements:
         | 
| 31 37 | 
             
                - - "~>"
         | 
| 38 | 
            +
                  - !ruby/object:Gem::Version
         | 
| 39 | 
            +
                    version: '0.8'
         | 
| 40 | 
            +
                - - ">="
         | 
| 32 41 | 
             
                  - !ruby/object:Gem::Version
         | 
| 33 42 | 
             
                    version: 0.8.1
         | 
| 34 43 | 
             
              type: :runtime
         | 
| @@ -36,6 +45,9 @@ dependencies: | |
| 36 45 | 
             
              version_requirements: !ruby/object:Gem::Requirement
         | 
| 37 46 | 
             
                requirements:
         | 
| 38 47 | 
             
                - - "~>"
         | 
| 48 | 
            +
                  - !ruby/object:Gem::Version
         | 
| 49 | 
            +
                    version: '0.8'
         | 
| 50 | 
            +
                - - ">="
         | 
| 39 51 | 
             
                  - !ruby/object:Gem::Version
         | 
| 40 52 | 
             
                    version: 0.8.1
         | 
| 41 53 | 
             
            - !ruby/object:Gem::Dependency
         | 
| @@ -43,6 +55,9 @@ dependencies: | |
| 43 55 | 
             
              requirement: !ruby/object:Gem::Requirement
         | 
| 44 56 | 
             
                requirements:
         | 
| 45 57 | 
             
                - - "~>"
         | 
| 58 | 
            +
                  - !ruby/object:Gem::Version
         | 
| 59 | 
            +
                    version: '0.20'
         | 
| 60 | 
            +
                - - ">="
         | 
| 46 61 | 
             
                  - !ruby/object:Gem::Version
         | 
| 47 62 | 
             
                    version: 0.20.0
         | 
| 48 63 | 
             
              type: :runtime
         | 
| @@ -50,8 +65,31 @@ dependencies: | |
| 50 65 | 
             
              version_requirements: !ruby/object:Gem::Requirement
         | 
| 51 66 | 
             
                requirements:
         | 
| 52 67 | 
             
                - - "~>"
         | 
| 68 | 
            +
                  - !ruby/object:Gem::Version
         | 
| 69 | 
            +
                    version: '0.20'
         | 
| 70 | 
            +
                - - ">="
         | 
| 53 71 | 
             
                  - !ruby/object:Gem::Version
         | 
| 54 72 | 
             
                    version: 0.20.0
         | 
| 73 | 
            +
            - !ruby/object:Gem::Dependency
         | 
| 74 | 
            +
              name: terminal-table
         | 
| 75 | 
            +
              requirement: !ruby/object:Gem::Requirement
         | 
| 76 | 
            +
                requirements:
         | 
| 77 | 
            +
                - - "~>"
         | 
| 78 | 
            +
                  - !ruby/object:Gem::Version
         | 
| 79 | 
            +
                    version: '1.8'
         | 
| 80 | 
            +
                - - ">="
         | 
| 81 | 
            +
                  - !ruby/object:Gem::Version
         | 
| 82 | 
            +
                    version: 1.8.0
         | 
| 83 | 
            +
              type: :runtime
         | 
| 84 | 
            +
              prerelease: false
         | 
| 85 | 
            +
              version_requirements: !ruby/object:Gem::Requirement
         | 
| 86 | 
            +
                requirements:
         | 
| 87 | 
            +
                - - "~>"
         | 
| 88 | 
            +
                  - !ruby/object:Gem::Version
         | 
| 89 | 
            +
                    version: '1.8'
         | 
| 90 | 
            +
                - - ">="
         | 
| 91 | 
            +
                  - !ruby/object:Gem::Version
         | 
| 92 | 
            +
                    version: 1.8.0
         | 
| 55 93 | 
             
            description: " Ruby client that supports all of the Terraform Enterprise API methods. "
         | 
| 56 94 | 
             
            email: maciej@skierkowski.com
         | 
| 57 95 | 
             
            executables:
         | 
| @@ -66,17 +104,23 @@ files: | |
| 66 104 | 
             
            - bin/tfe
         | 
| 67 105 | 
             
            - lib/terraform-enterprise-client.rb
         | 
| 68 106 | 
             
            - lib/terraform-enterprise-command-line.rb
         | 
| 107 | 
            +
            - lib/terraform-enterprise/client/request.rb
         | 
| 108 | 
            +
            - lib/terraform-enterprise/client/resource.rb
         | 
| 109 | 
            +
            - lib/terraform-enterprise/client/resource_request.rb
         | 
| 110 | 
            +
            - lib/terraform-enterprise/client/response.rb
         | 
| 69 111 | 
             
            - lib/terraform-enterprise/commands/command.rb
         | 
| 112 | 
            +
            - lib/terraform-enterprise/commands/formatter.rb
         | 
| 70 113 | 
             
            - lib/terraform-enterprise/commands/oauth_tokens_command.rb
         | 
| 71 114 | 
             
            - lib/terraform-enterprise/commands/organizations_command.rb
         | 
| 115 | 
            +
            - lib/terraform-enterprise/commands/strings.rb
         | 
| 72 116 | 
             
            - lib/terraform-enterprise/commands/workspaces_command.rb
         | 
| 73 | 
            -
            - lib/terraform-enterprise/ | 
| 74 | 
            -
            - lib/terraform-enterprise/ | 
| 75 | 
            -
            - lib/terraform-enterprise/ | 
| 76 | 
            -
            - lib/terraform-enterprise/resources_client.rb
         | 
| 117 | 
            +
            - lib/terraform-enterprise/resource_requests/oauth-tokens.rb
         | 
| 118 | 
            +
            - lib/terraform-enterprise/resource_requests/organizations.rb
         | 
| 119 | 
            +
            - lib/terraform-enterprise/resource_requests/workspaces.rb
         | 
| 77 120 | 
             
            - lib/terraform-enterprise/version.rb
         | 
| 78 121 | 
             
            homepage: http://github.com/skierkowski/terraform-enterprise-client
         | 
| 79 | 
            -
            licenses: | 
| 122 | 
            +
            licenses:
         | 
| 123 | 
            +
            - MPL-2.0
         | 
| 80 124 | 
             
            metadata: {}
         | 
| 81 125 | 
             
            post_install_message: 
         | 
| 82 126 | 
             
            rdoc_options: []
         | 
| @@ -94,8 +138,9 @@ required_rubygems_version: !ruby/object:Gem::Requirement | |
| 94 138 | 
             
                  version: '0'
         | 
| 95 139 | 
             
            requirements: []
         | 
| 96 140 | 
             
            rubyforge_project: 
         | 
| 97 | 
            -
            rubygems_version: 2. | 
| 141 | 
            +
            rubygems_version: 2.5.1
         | 
| 98 142 | 
             
            signing_key: 
         | 
| 99 143 | 
             
            specification_version: 4
         | 
| 100 144 | 
             
            summary: Ruby client for the official Terraform Enterprise API
         | 
| 101 145 | 
             
            test_files: []
         | 
| 146 | 
            +
            has_rdoc: 
         | 
| @@ -1,26 +0,0 @@ | |
| 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
         | 
| @@ -1,43 +0,0 @@ | |
| 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
         |