ibm-cloud-sdk 0.1.9 → 0.1.10

Sign up to get free protection for your applications and to get access to all the features.
Files changed (65) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +6 -1
  3. data/ibm-cloud-sdk.gemspec +1 -1
  4. data/lib/ibm/cloud/sdk.rb +2 -1
  5. data/lib/ibm/cloud/sdk/iam.rb +5 -0
  6. data/lib/ibm/cloud/sdk/resource_controller.rb +4 -0
  7. data/lib/ibm/cloud/sdk/tags.rb +28 -0
  8. data/lib/ibm/cloud/sdk/tags/http.rb +5 -0
  9. data/lib/ibm/cloud/sdk/tags/http/tag_collection.rb +99 -0
  10. data/lib/ibm/cloud/sdk/version.rb +1 -1
  11. data/lib/ibm/cloud/sdk/vpc.rb +8 -7
  12. data/lib/ibm/cloud/sdk/vpc/floatingips.rb +2 -2
  13. data/lib/ibm/cloud/sdk/vpc/flowlogcollectors.rb +2 -2
  14. data/lib/ibm/cloud/sdk/vpc/http.rb +7 -0
  15. data/lib/ibm/cloud/sdk/vpc/http/vpc_collection.rb +82 -0
  16. data/lib/ibm/cloud/sdk/vpc/http/vpc_http.rb +29 -0
  17. data/lib/ibm/cloud/sdk/vpc/http/vpc_instance.rb +30 -0
  18. data/lib/ibm/cloud/sdk/vpc/ike_policies.rb +2 -2
  19. data/lib/ibm/cloud/sdk/vpc/images.rb +2 -2
  20. data/lib/ibm/cloud/sdk/vpc/instance/actions.rb +1 -1
  21. data/lib/ibm/cloud/sdk/vpc/instance/floating_ips.rb +2 -2
  22. data/lib/ibm/cloud/sdk/vpc/instance/network_interfaces.rb +2 -2
  23. data/lib/ibm/cloud/sdk/vpc/instance/volume_attachments.rb +2 -2
  24. data/lib/ibm/cloud/sdk/vpc/instance_profiles.rb +3 -3
  25. data/lib/ibm/cloud/sdk/vpc/instances.rb +2 -2
  26. data/lib/ibm/cloud/sdk/vpc/ipsec_policies.rb +2 -2
  27. data/lib/ibm/cloud/sdk/vpc/keys.rb +2 -24
  28. data/lib/ibm/cloud/sdk/vpc/load_balancer.rb +1 -1
  29. data/lib/ibm/cloud/sdk/vpc/load_balancer/listeners.rb +2 -2
  30. data/lib/ibm/cloud/sdk/vpc/load_balancer/members.rb +2 -2
  31. data/lib/ibm/cloud/sdk/vpc/load_balancer/policies.rb +2 -2
  32. data/lib/ibm/cloud/sdk/vpc/load_balancer/pools.rb +2 -2
  33. data/lib/ibm/cloud/sdk/vpc/load_balancer/rules.rb +2 -2
  34. data/lib/ibm/cloud/sdk/vpc/load_balancers.rb +1 -1
  35. data/lib/ibm/cloud/sdk/vpc/network_acls.rb +4 -4
  36. data/lib/ibm/cloud/sdk/vpc/operating_systems.rb +2 -2
  37. data/lib/ibm/cloud/sdk/vpc/public_gateways.rb +2 -2
  38. data/lib/ibm/cloud/sdk/vpc/regions.rb +4 -4
  39. data/lib/ibm/cloud/sdk/vpc/security_groups.rb +6 -6
  40. data/lib/ibm/cloud/sdk/vpc/subnets.rb +2 -2
  41. data/lib/ibm/cloud/sdk/vpc/volume_profiles.rb +2 -2
  42. data/lib/ibm/cloud/sdk/vpc/volumes.rb +2 -2
  43. data/lib/ibm/cloud/sdk/vpc/vpcs.rb +6 -6
  44. data/lib/ibm/cloud/sdk/vpc/vpn_gateway/connections.rb +2 -2
  45. data/lib/ibm/cloud/sdk/vpc/vpn_gateway/local_cidrs.rb +2 -2
  46. data/lib/ibm/cloud/sdk/vpc/vpn_gateway/peer_cidrs.rb +2 -2
  47. data/lib/ibm/cloud/sdk/vpc/vpn_gateways.rb +2 -2
  48. data/lib/ibm/cloud/sdk_http.rb +16 -0
  49. data/lib/ibm/cloud/sdk_http/base_collection.rb +121 -0
  50. data/lib/ibm/cloud/sdk_http/base_http_mixin.rb +63 -0
  51. data/lib/ibm/cloud/sdk_http/base_instance.rb +55 -0
  52. data/lib/ibm/cloud/sdk_http/connection.rb +32 -0
  53. data/lib/ibm/cloud/sdk_http/exceptions.rb +31 -0
  54. data/lib/ibm/cloud/{sdk/vpc/base_mixins → sdk_http}/has_child.rb +3 -7
  55. data/lib/ibm/cloud/sdk_http/iam_token.rb +53 -0
  56. data/lib/ibm/cloud/sdk_http/sdk_response.rb +132 -0
  57. data/lib/ibm/cloud_sdk.rb +39 -0
  58. metadata +21 -12
  59. data/lib/ibm/cloud/sdk/vpc/base_collection.rb +0 -107
  60. data/lib/ibm/cloud/sdk/vpc/base_instance.rb +0 -23
  61. data/lib/ibm/cloud/sdk/vpc/base_vpc.rb +0 -61
  62. data/lib/ibm/cloud/sdk/vpc/cloud_sdk.rb +0 -33
  63. data/lib/ibm/cloud/sdk/vpc/exceptions.rb +0 -33
  64. data/lib/ibm/cloud/sdk/vpc/helpers/connection.rb +0 -96
  65. data/lib/ibm/cloud/sdk/vpc/helpers/response.rb +0 -134
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: dc39c6125bcaf6730a73477c76e7e40d2eb131cf6ca34466537d65f615ed8e6a
4
- data.tar.gz: ac29b18c76bff0ed290878e12007f1bf639654ed239ce7c27e99431acde25a17
3
+ metadata.gz: 3846f53417aa653151063dfd91b59ea43b1ba3a9d2d53fdb085c8dc7f28bb2ea
4
+ data.tar.gz: 903b21299da1b4d57953b4af2a98d27bc99e34298781b7936deae237641d34c6
5
5
  SHA512:
6
- metadata.gz: 845d945f1e0722745858a2256decc3fd73628fd172ba88a8e49a51a7edbf06418965cc609566288e31c2965ff88f2eff33f7691628bd33ef26da0309827c5058
7
- data.tar.gz: ee6c2c63c3472db99d9d773d77e045180594958b0ee4627b964f64365e1ea6a07c7a3159706ef326d9b87702a97218d7648c057737b14e4afc02bf4f40ae6c5f
6
+ metadata.gz: 9a1284cd63ae075ed1786f5045cb3951e328fb5edfcc95e1d981dd63c72a6ec85ff116102e07fe1317333dcc77305dad3287f312e184a31eb44bc3889303c521
7
+ data.tar.gz: 507dde2d35874cdee345b14c785d941b0b2a40014251ad8262f684f8f0966b050f57bb03e407332c006204344061c4963f4759895ab040d1ed24e5af73acc65d
@@ -1,8 +1,13 @@
1
1
  # Changelog
2
2
  All notable changes to the gem ibm-cloud-sdk-ruby will be documented here.
3
3
 
4
+ ## v0.1.10 - 2020-10-08
5
+ - Change VPC http provider to HTTParty
6
+ - Add Tags API and clean up VPC
7
+ - Log ResourceController and IAM calls
8
+
4
9
  ## v0.1.9 - 2020-10-02
5
- - Fix PowerVS Volume attach/detach calls
10
+ - Fix PowerVS Volume Attach/Detach calls
6
11
 
7
12
  ## v0.1.8 - 2020-10-01
8
13
  - Add second level instances
@@ -24,5 +24,5 @@ Gem::Specification.new do |spec|
24
24
  spec.require_paths = ["lib"]
25
25
 
26
26
  spec.add_dependency "rest-client"
27
- spec.add_dependency "http"
27
+ spec.add_dependency "httparty"
28
28
  end
@@ -2,12 +2,13 @@
2
2
  require "json"
3
3
  require "rest-client"
4
4
 
5
+ require 'ibm/cloud_sdk'
6
+
5
7
  require "ibm/cloud/sdk/base_service"
6
8
  require "ibm/cloud/sdk/iam"
7
9
  require "ibm/cloud/sdk/power_iaas"
8
10
  require "ibm/cloud/sdk/resource_controller"
9
11
  require "ibm/cloud/sdk/version"
10
- require "ibm/cloud/sdk/vpc/cloud_sdk"
11
12
  require "ibm/cloud/sdk/logging"
12
13
 
13
14
  module IBM
@@ -1,13 +1,18 @@
1
+ require_relative 'logging'
2
+
1
3
  module IBM
2
4
  module Cloud
3
5
  module SDK
4
6
  class IAM < BaseService
7
+ include Logging
8
+
5
9
  def endpoint
6
10
  "https://iam.cloud.ibm.com".freeze
7
11
  end
8
12
 
9
13
  def initialize(api_key)
10
14
  @api_key = api_key
15
+ RestClient.log = logger
11
16
  end
12
17
 
13
18
  def get_identity_token
@@ -1,7 +1,10 @@
1
+ require_relative 'logging'
2
+
1
3
  module IBM
2
4
  module Cloud
3
5
  module SDK
4
6
  class ResourceController < BaseService
7
+ include Logging
5
8
  require "ibm/cloud/sdk/resource_controller/resource"
6
9
  def endpoint
7
10
  "https://resource-controller.cloud.ibm.com/v2"
@@ -9,6 +12,7 @@ module IBM
9
12
 
10
13
  def initialize(token)
11
14
  @token = token
15
+ RestClient.log = logger
12
16
  end
13
17
 
14
18
  def get_resource(guid)
@@ -0,0 +1,28 @@
1
+ # typed: true
2
+ # frozen_string_literal: true
3
+
4
+ require 'ibm/cloud/sdk_http'
5
+ require_relative 'tags/http'
6
+
7
+ module IBM
8
+ module Cloud
9
+ module SDK
10
+ # A collection interface into the Tags API.
11
+ class Tags < TAG::TagCollection
12
+ def initialize(connection, token, logger: nil) # rubocop:disable Lint/MissingSuper
13
+ @token = token
14
+ @connection = connection
15
+
16
+ @logger = logger || Logger.new($stdout, level: :warn)
17
+ @array_key = 'items'
18
+ end
19
+
20
+ attr_reader :logger, :token, :connection
21
+
22
+ def endpoint
23
+ 'https://tags.global-search-tagging.cloud.ibm.com/v3/tags'
24
+ end
25
+ end
26
+ end
27
+ end
28
+ end
@@ -0,0 +1,5 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'ibm/cloud/sdk_http'
4
+
5
+ require_relative 'http/tag_collection'
@@ -0,0 +1,99 @@
1
+ # typed: true
2
+ # frozen_string_literal: true
3
+
4
+ require_relative '../http'
5
+
6
+ module IBM
7
+ module Cloud
8
+ module SDK
9
+ module TAG
10
+ # The Base Collection for the Tags API.
11
+ class TagCollection < SDKHTTP::BaseCollection
12
+ # rubocop:disable Metrics/AbcSize, Metrics/CyclomaticComplexity, Metrics/PerceivedComplexity, Layout/LineLength
13
+
14
+ # Set params on the next request.
15
+ # @param account_id [String>] The ID of the billing account to list the tags for. If it is not set, then it is taken from the authorization token. This parameter is required if tag_type is set to service.
16
+ # @param tag_type [String] The type of the tag you want to list. Supported values are user and service.
17
+ # @param full_data [Boolean] If set to true, this query returns the provider, ghost, ims or ghost,ims, where the tag exists and the number of attached resources.
18
+ # @param providers [String] Select a provider. Supported values are ghost and ims.
19
+ # @param attached_to [String] If you want to return only the list of tags attached to a specified resource, pass the ID of the resource on this parameter. For GhoST onboarded resources, the resource ID is the CRN; for IMS resources, it is the IMS ID. When using this parameter, you must specify the appropriate provider (ims or ghost).
20
+ # @param offset [Integer] The offset is the index of the item from which you want to start returning data from.
21
+ # @param limit [Integer] The number of tags to return (1 <> 1000). Default: 100
22
+ # @param timeout [Integer] The search timeout bounds the search request to be executed within the specified time value. It returns the hits accumulated until time runs out (0 <> 60000).
23
+ # @param order_by_name [String] Order the output by tag name (asc,desc).
24
+ # @param attached_only [Boolean] Filter on attached tags. If true, it returns only tags that are attached to one or more resources.
25
+ def params(
26
+ account_id: nil,
27
+ tag_type: nil,
28
+ full_data: false,
29
+ providers: nil,
30
+ attached_to: nil,
31
+ offset: 0,
32
+ limit: 100,
33
+ timeout: nil,
34
+ order_by_name: 'asc',
35
+ attached_only: false
36
+ )
37
+ @params ||= {}
38
+ @params[:account_id] = account_id if account_id
39
+ @params[:tag_type] = tag_type if tag_type && %w[user service].include?(tag_type)
40
+ @params[:full_data] = full_data if full_data.instance_of?(TrueClass)
41
+ @params[:providers] = providers if providers && %w[ghost ims].include?(providers)
42
+ @params[:attached_to] = attached_to if attached_to
43
+ @params[:offset] = offset if offset.positive?
44
+ @params[:limit] = limit if limit && (1..1000).include?(limit) && limit != 100
45
+ @params[:timeout] = timeout if timeout
46
+ @params[:order_by_name] = order_by_name if order_by_name && %w[desc].include?(order_by_name)
47
+ @params[:attached_only] = attached_only if attached_only.instance_of?(TrueClass)
48
+ self
49
+ end
50
+ # rubocop:enable Metrics/AbcSize, Metrics/CyclomaticComplexity, Metrics/PerceivedComplexity, Layout/LineLength
51
+
52
+ def reset_params
53
+ @params = {}
54
+ end
55
+
56
+ # Return the total count as retrieved from the API.
57
+ # @return [Integer] value in total_count
58
+ def total_count
59
+ fetch.json.[](:total_count)
60
+ end
61
+
62
+ # Get all tags attached to a CRN.
63
+ # @param crn [String] The CRN for the instance.
64
+ def attached_to(crn)
65
+ return [] if crn.to_s.empty?
66
+
67
+ params(attached_to: crn).all
68
+ end
69
+
70
+ private
71
+
72
+ # Create a generator that removes the need for pagination.
73
+ # @param url [String] Full URL to send to server.
74
+ # @return [Enumerator] Object to page through results.
75
+ # @yield [BaseInstance] An instance of the instance class.
76
+ # @yield [Hash] When no BaseInstance set.
77
+ def each_resource(url, offset = 0, &block)
78
+ return enum_for(:each_resource, url) unless block_given?
79
+ return unless url
80
+
81
+ response = params(offset: offset).get(path: url).json
82
+
83
+ resources = response.fetch(@array_key.to_sym)
84
+ current_count = response.fetch(:offset) + response.fetch(:limit)
85
+
86
+ resources&.each { |value| yield value } # rubocop:disable Style/ExplicitBlockArgument
87
+
88
+ if resources.empty?
89
+ reset_params
90
+ return
91
+ end
92
+
93
+ each_resource(url, current_count, &block)
94
+ end
95
+ end
96
+ end
97
+ end
98
+ end
99
+ end
@@ -1,7 +1,7 @@
1
1
  module IBM
2
2
  module Cloud
3
3
  module SDK
4
- VERSION = "0.1.9"
4
+ VERSION = "0.1.10"
5
5
  end
6
6
  end
7
7
  end
@@ -1,10 +1,8 @@
1
1
  # typed: true
2
2
  # frozen_string_literal: true
3
3
 
4
- require_relative 'vpc/base_vpc'
5
- require_relative 'vpc/base_collection'
6
- require_relative 'vpc/base_instance'
7
- require_relative 'vpc/exceptions'
4
+ require 'ibm/cloud/sdk_http'
5
+ require_relative 'vpc/http'
8
6
 
9
7
  require_relative 'vpc/floatingips'
10
8
  require_relative 'vpc/flowlogcollectors'
@@ -30,20 +28,23 @@ module IBM
30
28
  module Cloud
31
29
  module SDK
32
30
  # Container that encapsulates the VPC API.
33
- class Vpc < BaseVPC
31
+ class Vpc
32
+ include VPC::VpcHTTP
33
+
34
34
  # Create an API Client object for the VPC IaaS service
35
35
  #
36
36
  # @param region [String] the IBM Power Cloud instance region
37
37
  # @param connection [IBM::Cloud::SDK::VPC::Connection] A connection object.
38
38
  # @param logger [Logger] An instance of an instanciated logger.
39
- def initialize(region, connection, logger: nil)
39
+ def initialize(region, connection, token, logger: nil)
40
40
  @region = region
41
+ @token = token
41
42
  @connection = connection
42
43
 
43
44
  @logger = logger || Logger.new($stdout, level: :warn)
44
45
  end
45
46
 
46
- attr_reader :connection, :logger
47
+ attr_reader :logger, :token, :connection
47
48
  attr_accessor :region
48
49
 
49
50
  # The Region API endpoint.
@@ -6,14 +6,14 @@ module IBM
6
6
  module SDK
7
7
  module VPC
8
8
  # Class that deals with groups of floating IPs.
9
- class FloatingIPs < BaseCollection
9
+ class FloatingIPs < VPCCollection
10
10
  def initialize(parent)
11
11
  super(parent, 'floating_ips', child_class: FloatingIP)
12
12
  end
13
13
  end
14
14
 
15
15
  # Class that deals with a single floating IP.
16
- class FloatingIP < BaseInstance; end
16
+ class FloatingIP < VPCInstance; end
17
17
  end
18
18
  end
19
19
  end
@@ -6,14 +6,14 @@ module IBM
6
6
  module SDK
7
7
  module VPC
8
8
  # A list of subnets
9
- class FlowLogCollectors < BaseCollection
9
+ class FlowLogCollectors < VPCCollection
10
10
  def initialize(parent)
11
11
  super(parent, 'flow_log_collectors', child_class: FlowLogCollectors)
12
12
  end
13
13
  end
14
14
 
15
15
  # A single subnet
16
- class FlowLogCollector < BaseInstance; end
16
+ class FlowLogCollector < VPCInstance; end
17
17
  end
18
18
  end
19
19
  end
@@ -0,0 +1,7 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'ibm/cloud/sdk_http'
4
+ require_relative 'http/vpc_http'
5
+
6
+ require_relative 'http/vpc_collection'
7
+ require_relative 'http/vpc_instance'
@@ -0,0 +1,82 @@
1
+ # typed: true
2
+ # frozen_string_literal: true
3
+
4
+ require_relative '../http'
5
+ require_relative 'vpc_http'
6
+
7
+ module IBM
8
+ module Cloud
9
+ module SDK
10
+ module VPC
11
+ # Container that encapsulates the VPC API.
12
+ # This class is used as a base for collection APIs.
13
+ # @param parent [Object] The parent instance in the API chain.
14
+ # @param endpoint [string] A path from the parent to the desired endpoint. In most cases is should be 1 word.
15
+ # @param array_key [string] The key that the API response holds the endpoint data. When nil the endpoint will be used.
16
+ # @param child_class [Object] The Object to be used when instanciating the single instance for this class.
17
+ class VPCCollection < SDKHTTP::BaseCollection
18
+ include VpcHTTP
19
+
20
+ # A chainable method to set query filters on the collection.
21
+ # @example vpc.images.params(limit: 1).all
22
+ #
23
+ # @param start [String] A server-supplied token determining what resource to start the page on.
24
+ # @param limit [Integer] The number of resources to return on a page allowed values are between 1 and 100
25
+ # @param resource_group [String] Filters the collection to resources within one of the resource groups identified in a comma-separated list of resource group identifiers
26
+ # @return [BaseCollection] This class with the param instance variable set.
27
+ def params(start: nil, limit: nil, resource_group: nil)
28
+ @params[:start] = start if start
29
+ @params[:limit] = limit if limit
30
+ @params[:resource_group] = resource_group if resource_group
31
+ self
32
+ end
33
+
34
+ # Determine if the collection has a total_count key in its response.
35
+ # @return [Boolean]
36
+ def has_count?
37
+ fetch.json&.key?(:total_count)
38
+ end
39
+
40
+ # Get the total count if it exists in the response. Returns nil otherwise.
41
+ # @return [Integer] The total count reuturned by the server.
42
+ def count
43
+ fetch.json&.[](:total_count)
44
+ end
45
+
46
+ private
47
+
48
+ # Return a wrapped instance if set.
49
+ # @param value [Hash] The hash returned from server.
50
+ def hash_instance(value)
51
+ return @instance.new(self, data: value, id_key: @instance_id) if @instance
52
+
53
+ value
54
+ end
55
+
56
+ # Create a generator that removes the need for pagination.
57
+ # @param url [String] Full URL to send to server.
58
+ # @return [Enumerator] Object to page through results.
59
+ # @yield [BaseInstance] An instance of the instance class.
60
+ # @yield [Hash] When no VPCInstance set.
61
+ def each_resource(url, &block)
62
+ return enum_for(:each_resource, url) unless block_given?
63
+ return unless url
64
+
65
+ response = get(path: url).json
66
+ resources = response.fetch(@array_key.to_sym)
67
+
68
+ resources&.each { |value| yield hash_instance(value) }
69
+ # VPC has a next key that holds the next URL.
70
+ return unless response.key?(:next)
71
+
72
+ # The :next data structure is a hash with a href member.
73
+ next_url = response.dig(:next, :href)
74
+ return unless next_url
75
+
76
+ each_resource(next_url, &block)
77
+ end
78
+ end
79
+ end
80
+ end
81
+ end
82
+ end
@@ -0,0 +1,29 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative '../http'
4
+
5
+ module IBM
6
+ module Cloud
7
+ module SDK
8
+ # Module holds basic HTTP functionality.
9
+ module VPC
10
+ # Generic methods for accessing VPC.
11
+ module VpcHTTP
12
+ include SDKHTTP::BaseHTTPMixin
13
+
14
+ def metadata(query = nil, payload = nil)
15
+ @params ||= {}
16
+ @params.merge!(query) if query
17
+
18
+ payload ||= {}
19
+ {
20
+ query: { version: '2020-08-01', generation: 2 }.merge(@params),
21
+ body: payload,
22
+ headers: { "Authorization": @token.authorization_header }
23
+ }
24
+ end
25
+ end
26
+ end
27
+ end
28
+ end
29
+ end
@@ -0,0 +1,30 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'ibm/cloud/sdk/tags'
4
+
5
+ require_relative 'vpc_http'
6
+
7
+ module IBM
8
+ module Cloud
9
+ module SDK
10
+ module VPC
11
+ # Container that encapsulates the VPC API.
12
+ class VPCInstance < SDKHTTP::BaseInstance
13
+ include VpcHTTP
14
+
15
+ # Get the CRN for the resource.
16
+ # @return [String]
17
+ def crn
18
+ self[:crn]
19
+ end
20
+
21
+ # Get the tags associated with this resource.
22
+ # @return [Enumerator] An enumerator with the results.
23
+ def tags
24
+ IBM::Cloud::SDK::Tags.new(@connection, @token, logger: @logger).attached_to(crn)
25
+ end
26
+ end
27
+ end
28
+ end
29
+ end
30
+ end