train-alicloud 0.0.2

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.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 70ab43053ff407de562c98318dd1e0926951729dcc3b021d661436f569ae5e7f
4
+ data.tar.gz: fc23966ae524f096879dc0dfe256a994d569c820b5328102f8896d47ae02a840
5
+ SHA512:
6
+ metadata.gz: cf6670f8a94e0d406757a86ba52501423eb2337d13634ca018d61e8dc2b1046248dab67f012f32c64e28f7c559f310c024487e0d4661dd114d48234e94787f2e
7
+ data.tar.gz: 972218f9739808b247533091b3a037bfa4d4dabc005bd1afa9dd00684ba9b9328498724eaadb7315760f6b4f42c4418967ffce07068418333f699d895091b386
data/LICENSE ADDED
@@ -0,0 +1,13 @@
1
+ Copyright (c) 2020 Chef Software Inc.
2
+
3
+ Licensed under the Apache License, Version 2.0 (the "License");
4
+ you may not use this file except in compliance with the License.
5
+ You may obtain a copy of the License at
6
+
7
+ http://www.apache.org/licenses/LICENSE-2.0
8
+
9
+ Unless required by applicable law or agreed to in writing, software
10
+ distributed under the License is distributed on an "AS IS" BASIS,
11
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
+ See the License for the specific language governing permissions and
13
+ limitations under the License.
@@ -0,0 +1,21 @@
1
+ # This file is known as the "entry point."
2
+ # This is the file Train will try to load if it
3
+ # thinks your plugin is needed.
4
+
5
+ # The *only* thing this file should do is setup the
6
+ # load path, then load plugin files.
7
+
8
+ # Next two lines simply add the path of the gem to the load path.
9
+ # This is not needed when being loaded as a gem; but when doing
10
+ # plugin development, you may need it. Either way, it's harmless.
11
+ libdir = File.dirname(__FILE__)
12
+ $LOAD_PATH.unshift(libdir) unless $LOAD_PATH.include?(libdir)
13
+
14
+ # It's traditonal to keep your gem version in a separate file, so CI can find it easier.
15
+ require_relative "train-alicloud/version"
16
+
17
+ # A train plugin has three components: Transport, Connection, and Platform.
18
+ # Transport acts as the glue.
19
+ require_relative "train-alicloud/transport"
20
+ require_relative "train-alicloud/platform"
21
+ require_relative "train-alicloud/connection"
@@ -0,0 +1,87 @@
1
+ # Connection definition file for an example Train plugin.
2
+
3
+ # Most of the work of a Train plugin happens in this file.
4
+ # Connections derive from Train::Plugins::Transport::BaseConnection,
5
+ # and provide a variety of services. Later generations of the plugin
6
+ # API will likely separate out these responsibilities, but for now,
7
+ # some of the responsibilities include:
8
+ # * authentication to the target
9
+ # * platform / release /family detection
10
+ # * caching
11
+ # * API execution
12
+ # * marshalling to / from JSON
13
+ # You don't have to worry about most of this.
14
+
15
+ # Push platform detection out to a mixin, as it tends
16
+ # to develop at a different cadence than the rest
17
+ require_relative "platform"
18
+ require "train"
19
+ require "train/plugins"
20
+
21
+ require "aliyunsdkcore"
22
+
23
+ module TrainPlugins
24
+ module AliCloud
25
+ # You must inherit from BaseConnection.
26
+ class Connection < Train::Plugins::Transport::BaseConnection
27
+ # We've placed platform detection in a separate module; pull it in here.
28
+ include TrainPlugins::AliCloud::Platform
29
+
30
+ def initialize(options)
31
+ # 'options' here is a hash, Symbol-keyed,
32
+ # of what Train.target_config decided to do with the URI that it was
33
+ # passed by `inspec -t` (or however the application gathered target information)
34
+ # Some plugins might use this moment to capture credentials from the URI,
35
+ # and the configure an underlying SDK accordingly.
36
+ # You might also take a moment to manipulate the options.
37
+ # Have a look at the Local, SSH, and AWS transports for ideas about what
38
+ # you can do with the options.
39
+
40
+ # Override for any cli options
41
+ # alicloud://region
42
+ options[:region] = options[:host] || options[:region]
43
+
44
+ # Now let the BaseConnection have a chance to configure itself.
45
+ super(options)
46
+
47
+ # Force enable caching.
48
+ enable_cache :api_call
49
+
50
+ # Why are we doing this?
51
+ ENV["ALICLOUD_REGION"] = @options[:region] if @options[:region]
52
+ end
53
+
54
+ def alicloud_client(api:, api_version:)
55
+ region = @options[:region]
56
+
57
+ endpoint ||= if api == "sts"
58
+ "https://#{api}.aliyuncs.com"
59
+ else
60
+ "https://#{api}.#{region}.aliyuncs.com"
61
+ end
62
+
63
+ RPCClient.new(
64
+ access_key_id: @options[:access_key_id],
65
+ access_key_secret: @options[:secret_access_key],
66
+ endpoint: endpoint,
67
+ api_version: api_version
68
+ )
69
+ end
70
+
71
+ def alicloud_resource(klass, args)
72
+ klass.new(args)
73
+ end
74
+
75
+ # TODO: determine exactly what this is used for
76
+ def uri
77
+ "alicloud://#{@options[:region]}"
78
+ end
79
+
80
+ def unique_identifier
81
+ # use alicloud account id
82
+ caller_identity = alicloud_client(api: "sts", api_version: "2015-04-01").request(action: "GetCallerIdentity")
83
+ caller_identity["AccountId"]
84
+ end
85
+ end
86
+ end
87
+ end
@@ -0,0 +1,39 @@
1
+ require_relative "version"
2
+
3
+ # Platform definition file. This is a good place to separate out any
4
+ # logic regarding the identification of the OS or API at the far end
5
+ # of the connection.
6
+
7
+ # Abbreviate the namespace here, if you like.
8
+ module TrainPlugins::AliCloud
9
+ # Since we're mixing in the platform detection facility into Connection,
10
+ # this has to come in as a Module.
11
+ module Platform
12
+ # The method `platform` is called when platform detection is
13
+ # about to be performed. Train core defines a sophisticated
14
+ # system for platform detection, but for most plugins, you'll
15
+ # only ever run on the special platform for which you are targeting.
16
+ def platform
17
+ # If you are declaring a new platform, you will need to tell
18
+ # Train a bit about it.
19
+ # If you were defining a cloud API, you should say you are a member
20
+ # of the cloud family.
21
+
22
+ # This plugin defines a new platform.
23
+ Train::Platforms.name("alicloud").in_family("cloud")
24
+
25
+ # When you know you will only ever run on your dedicated platform
26
+ # force_platform! lets you bypass platform detection.
27
+ # The options to this are not currently documented completely.
28
+
29
+ # Use release to report a version number. You might use the version
30
+ # of the plugin, or a version of an important underlying SDK, or a
31
+ # version of a remote API.
32
+ alicloud_version = Gem.loaded_specs["aliyunsdkcore"].version
33
+ alicloud_version = "aliyunsdkcore: v#{alicloud_version}"
34
+ plugin_version = "train-alicloud: v#{TrainPlugins::AliCloud::VERSION}"
35
+
36
+ force_platform!("alicloud", release: "#{plugin_version}, #{alicloud_version}")
37
+ end
38
+ end
39
+ end
@@ -0,0 +1,40 @@
1
+
2
+ require "train"
3
+ require "train/plugins"
4
+ require "aliyunsdkcore"
5
+
6
+ # Train Plugins v1 are usually declared under the TrainPlugins namespace.
7
+ # Each plugin has three components: Transport, Connection, and Platform.
8
+ # We'll only define the Transport here, but we'll refer to the others.
9
+ require_relative "connection"
10
+
11
+ module TrainPlugins
12
+ module AliCloud
13
+ class Transport < Train.plugin(1)
14
+ name "alicloud"
15
+
16
+ # Pass ENV vars in using a block to `option`. This causes `
17
+ # option to lazy-evaluate the block to provide a default value.`
18
+ # Otherwise, we would read the ENV var (and set the default)
19
+ # once at compile time, which would make testing difficult.
20
+ # TODO: convert to thor-style defaults
21
+ option(:region, required: true) { ENV["ALICLOUD_REGION"] }
22
+ option(:access_key_id, required: true) { ENV["ALICLOUD_ACCESS_KEY"] }
23
+ option(:secret_access_key, required: true) { ENV["ALICLOUD_SECRET_KEY"] }
24
+
25
+ # The only thing you MUST do in a transport is a define a
26
+ # connection() method that returns a instance that is a
27
+ # subclass of BaseConnection.
28
+
29
+ # The options passed to this are undocumented and rarely used.
30
+ def connection(_instance_opts = nil)
31
+ # Typical practice is to cache the connection as an instance variable.
32
+ # Do what makes sense for your platform.
33
+ # @options here is the parsed options that the calling
34
+ # app handed to us at process invocation. See the Connection class
35
+ # for more details.
36
+ @connection ||= TrainPlugins::AliCloud::Connection.new(@options)
37
+ end
38
+ end
39
+ end
40
+ end
@@ -0,0 +1,10 @@
1
+ # This file exists simply to record the version number of the plugin.
2
+ # It is kept in a separate file, so that your gemspec can load it and
3
+ # learn the current version without loading the whole plugin. Also,
4
+ # many CI servers can update this file when "version bumping".
5
+
6
+ module TrainPlugins
7
+ module AliCloud
8
+ VERSION = "0.0.2".freeze
9
+ end
10
+ end
metadata ADDED
@@ -0,0 +1,78 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: train-alicloud
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.2
5
+ platform: ruby
6
+ authors:
7
+ - Chef InSpec Team
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2020-11-09 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: aliyunsdkcore
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: 0.0.16
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: 0.0.16
27
+ - !ruby/object:Gem::Dependency
28
+ name: aliyun-sdk
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '0.8'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '0.8'
41
+ description: Allows applications using Train to speak to AliCloud; handles authentication,
42
+ cacheing, and SDK dependency management.
43
+ email:
44
+ - inspec@chef.io
45
+ executables: []
46
+ extensions: []
47
+ extra_rdoc_files: []
48
+ files:
49
+ - LICENSE
50
+ - lib/train-alicloud.rb
51
+ - lib/train-alicloud/connection.rb
52
+ - lib/train-alicloud/platform.rb
53
+ - lib/train-alicloud/transport.rb
54
+ - lib/train-alicloud/version.rb
55
+ homepage: https://github.com/chef-customers/train-alicloud
56
+ licenses:
57
+ - Apache-2.0
58
+ metadata: {}
59
+ post_install_message:
60
+ rdoc_options: []
61
+ require_paths:
62
+ - lib
63
+ required_ruby_version: !ruby/object:Gem::Requirement
64
+ requirements:
65
+ - - ">="
66
+ - !ruby/object:Gem::Version
67
+ version: '0'
68
+ required_rubygems_version: !ruby/object:Gem::Requirement
69
+ requirements:
70
+ - - ">="
71
+ - !ruby/object:Gem::Version
72
+ version: '0'
73
+ requirements: []
74
+ rubygems_version: 3.1.2
75
+ signing_key:
76
+ specification_version: 4
77
+ summary: AliCloud API Transport for Train
78
+ test_files: []