vcoworkflows 0.1.4 → 0.2.0
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 +4 -4
- data/CHANGELOG.md +8 -0
- data/Guardfile +9 -9
- data/Rakefile +1 -1
- data/lib/vcoworkflows.rb +1 -0
- data/lib/vcoworkflows/cli/execute.rb +6 -7
- data/lib/vcoworkflows/cli/query.rb +6 -7
- data/lib/vcoworkflows/config.rb +93 -0
- data/lib/vcoworkflows/constants.rb +10 -0
- data/lib/vcoworkflows/vcosession.rb +29 -7
- data/lib/vcoworkflows/version.rb +1 -1
- data/lib/vcoworkflows/workflow.rb +48 -20
- data/spec/vcoworkflows/config_spec.rb +58 -0
- data/spec/vcoworkflows/vcosession_spec.rb +27 -6
- data/spec/vcoworkflows/workflow_spec.rb +36 -9
- metadata +6 -4
- data/lib/vcoworkflows/cli/auth.rb +0 -41
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 4aecbf8d560cb33986bb7724cb185dd4c674f979
|
4
|
+
data.tar.gz: afa37f3f01dc4e31e70121a5acb764192d0ea1f0
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 2be9992176d0cde2177ade9b116047cb3cc2ee922d795efcfb9035c627ddc00dfac1aa68ac71859d896e7beb796af76bd1d7db7d252f21c271d6d00a7250b0e8
|
7
|
+
data.tar.gz: e298f6c3070df696fad7e3132798a55ad85522ad5890b99038fff2800ef03689c812175bc62cf3e8f5f3956e04697d607dbec5c4873f3b5ebb506861241a9334
|
data/CHANGELOG.md
CHANGED
@@ -1,6 +1,14 @@
|
|
1
1
|
vcoworkflows CHANGELOG
|
2
2
|
================
|
3
3
|
|
4
|
+
## 0.2.0
|
5
|
+
|
6
|
+
- Removes `VcoWorkflows::Cli::Auth`
|
7
|
+
- Slightly breaks the behavior of `VcoWorkflows::VcoSession` from v0.1.x; all parameters for `VcoWorkflows::VcoSession.new()` are optional now, and if none are given, an attempt to load configuration from the default configuration file (currently `${HOME}/.vcoworkflows/config.json`) will be made.
|
8
|
+
- Added `config` and `config_file` options to `VcoWorkflows::Workflow.new`. If only name is specified, attempt to grab configuration from `${HOME}/.vcoworkflows/config.json`
|
9
|
+
|
10
|
+
## 0.1.4
|
11
|
+
|
4
12
|
## 0.1.3
|
5
13
|
|
6
14
|
### Third Time's the Charm
|
data/Guardfile
CHANGED
@@ -9,6 +9,15 @@ notification :growl, sticky:true
|
|
9
9
|
# * zeus: 'zeus rspec' (requires the server to be started separately)
|
10
10
|
# * 'just' rspec: 'rspec'
|
11
11
|
|
12
|
+
guard :rubocop do
|
13
|
+
watch(%r{.+\.rb$})
|
14
|
+
watch(%r{bin/.+\.rb$})
|
15
|
+
watch(%r{lib/vcoworkflows/.+\.rb$})
|
16
|
+
watch(%r{spec/.+\.rb$})
|
17
|
+
watch(%r{spec/vcoworkflows/.+_spec\.rb$})
|
18
|
+
watch(%r{(?:.+/)?\.rubocop\.yml$}) { |m| File.direname(m[0]) }
|
19
|
+
end
|
20
|
+
|
12
21
|
guard :rspec, cmd: "bundle exec rspec" do
|
13
22
|
require "guard/rspec/dsl"
|
14
23
|
dsl = Guard::RSpec::Dsl.new(self)
|
@@ -26,15 +35,6 @@ guard :rspec, cmd: "bundle exec rspec" do
|
|
26
35
|
dsl.watch_spec_files_for(ruby.lib_files)
|
27
36
|
end
|
28
37
|
|
29
|
-
guard :rubocop do
|
30
|
-
watch(%r{.+\.rb$})
|
31
|
-
watch(%r{bin/.+\.rb$})
|
32
|
-
watch(%r{lib/vcoworkflows/.+\.rb$})
|
33
|
-
watch(%r{spec/.+\.rb$})
|
34
|
-
watch(%r{spec/vcoworkflows/.+_spec\.rb$})
|
35
|
-
watch(%r{(?:.+/)?\.rubocop\.yml$}) { |m| File.direname(m[0]) }
|
36
|
-
end
|
37
|
-
|
38
38
|
guard 'yard' do
|
39
39
|
watch(%r{bin/.+\.rb})
|
40
40
|
watch(%r{lib/.+\.rb})
|
data/Rakefile
CHANGED
data/lib/vcoworkflows.rb
CHANGED
@@ -2,6 +2,7 @@ require 'thor'
|
|
2
2
|
|
3
3
|
require File.dirname(__FILE__) + '/vcoworkflows/version'
|
4
4
|
require File.dirname(__FILE__) + '/vcoworkflows/constants'
|
5
|
+
require File.dirname(__FILE__) + '/vcoworkflows/config'
|
5
6
|
require File.dirname(__FILE__) + '/vcoworkflows/vcosession'
|
6
7
|
require File.dirname(__FILE__) + '/vcoworkflows/workflowservice'
|
7
8
|
require File.dirname(__FILE__) + '/vcoworkflows/workflow'
|
@@ -1,5 +1,4 @@
|
|
1
1
|
require 'vcoworkflows'
|
2
|
-
require_relative 'auth'
|
3
2
|
require 'thor/group'
|
4
3
|
|
5
4
|
# rubocop:disable MethodLength, LineLength
|
@@ -31,7 +30,10 @@ module VcoWorkflows
|
|
31
30
|
|
32
31
|
# rubocop:disable CyclomaticComplexity, PerceivedComplexity
|
33
32
|
def execute
|
34
|
-
|
33
|
+
config = VcoWorkflows::Config.new(url: options[:server],
|
34
|
+
username: options[:username],
|
35
|
+
password: options[:password],
|
36
|
+
verify_ssl: options[:verify_ssl])
|
35
37
|
|
36
38
|
# Parse out the parameters
|
37
39
|
parameters = {}
|
@@ -60,11 +62,8 @@ module VcoWorkflows
|
|
60
62
|
# Get the workflow
|
61
63
|
puts "Retrieving workflow '#{workflow}' ..."
|
62
64
|
wf = VcoWorkflows::Workflow.new(workflow,
|
63
|
-
|
64
|
-
|
65
|
-
password: auth.password,
|
66
|
-
verify_ssl: options[:verify_ssl],
|
67
|
-
id: options[:id])
|
65
|
+
id: options[:id],
|
66
|
+
config: config)
|
68
67
|
|
69
68
|
# List out mandatory parameters
|
70
69
|
puts "Required parameters:\n #{wf.required_parameters.keys.join(', ')}"
|
@@ -1,5 +1,4 @@
|
|
1
1
|
require 'vcoworkflows'
|
2
|
-
require_relative 'auth'
|
3
2
|
require 'thor/group'
|
4
3
|
|
5
4
|
# rubocop:disable MethodLength, LineLength
|
@@ -35,7 +34,10 @@ module VcoWorkflows
|
|
35
34
|
# Process the subcommand
|
36
35
|
# rubocop:disable CyclomaticComplexity, PerceivedComplexity
|
37
36
|
def query
|
38
|
-
|
37
|
+
config = VcoWorkflows::Config.new(url: options[:server],
|
38
|
+
username: options[:username],
|
39
|
+
password: options[:password],
|
40
|
+
verify_ssl: options[:verify_ssl])
|
39
41
|
|
40
42
|
if options[:dry_run]
|
41
43
|
puts "\nQuerying against vCO REST endpoint:\n #{options[:server]}"
|
@@ -47,11 +49,8 @@ module VcoWorkflows
|
|
47
49
|
# Get the workflow
|
48
50
|
puts "\nRetrieving workflow '#{workflow}' ..."
|
49
51
|
wf = VcoWorkflows::Workflow.new(workflow,
|
50
|
-
|
51
|
-
|
52
|
-
password: auth.password,
|
53
|
-
verify_ssl: options[:verify_ssl],
|
54
|
-
id: options[:id])
|
52
|
+
id: options[:id],
|
53
|
+
config: config)
|
55
54
|
|
56
55
|
puts ''
|
57
56
|
if options[:execution_id]
|
@@ -0,0 +1,93 @@
|
|
1
|
+
require 'vcoworkflows/constants'
|
2
|
+
require 'uri'
|
3
|
+
|
4
|
+
# VcoWorkflows
|
5
|
+
module VcoWorkflows
|
6
|
+
# Class Config
|
7
|
+
class Config
|
8
|
+
# URL for the vCenter Orchestrator REST API
|
9
|
+
attr_reader :url
|
10
|
+
|
11
|
+
# User name to authenticate to vCenter Orchestrator
|
12
|
+
attr_accessor :username
|
13
|
+
|
14
|
+
# Password to authenticate to vCenter Orchestrator
|
15
|
+
attr_accessor :password
|
16
|
+
|
17
|
+
# Whether or not to do SSL/TLS Certificate verification
|
18
|
+
attr_accessor :verify_ssl
|
19
|
+
|
20
|
+
# rubocop:disable LineLength, MethodLength, CyclomaticComplexity, PerceivedComplexity
|
21
|
+
|
22
|
+
# Constructor
|
23
|
+
# @param [String] config_file Path to config file to load
|
24
|
+
# @param [String] url URL for vCO server
|
25
|
+
# @param [String] username Username for vCO server
|
26
|
+
# @param [String] password Password for vCO server
|
27
|
+
# @param [Boolean] verify_ssl Verify SSL Certificates?
|
28
|
+
# @return [VcoWorkflows::Config]
|
29
|
+
def initialize(config_file: nil, url: nil, username: nil, password: nil, verify_ssl: true)
|
30
|
+
# If we're given a URL and no config_file, then build the configuration
|
31
|
+
# from the values we're given (or can scrape from the environment).
|
32
|
+
# Otherwise, load the given config file or the default config file if no
|
33
|
+
# config file was given.
|
34
|
+
if url && config_file.nil?
|
35
|
+
self.url = url
|
36
|
+
@username = username.nil? ? ENV['VCO_USER'] : username
|
37
|
+
@password = password.nil? ? ENV['VCO_PASSWD'] : password
|
38
|
+
@verify_ssl = verify_ssl
|
39
|
+
else
|
40
|
+
# First, check if an explicit config file was given
|
41
|
+
config_file = DEFAULT_CONFIG_FILE if config_file.nil?
|
42
|
+
load_config(config_file)
|
43
|
+
end
|
44
|
+
|
45
|
+
# Fail if we don't have both a username and a password.
|
46
|
+
fail(IOError, ERR[:url_unset]) if @url.nil?
|
47
|
+
fail(IOError, ERR[:username_unset]) if @username.nil?
|
48
|
+
fail(IOError, ERR[:password_unset]) if @password.nil?
|
49
|
+
end
|
50
|
+
# rubocop:enable LineLength, MethodLength, CyclomaticComplexity, PerceivedComplexity
|
51
|
+
|
52
|
+
# rubocop:disable LineLength
|
53
|
+
|
54
|
+
# Set the URL for the vCO server, force the path component.
|
55
|
+
# @param [String] vco_url
|
56
|
+
def url=(vco_url)
|
57
|
+
url = URI.parse(vco_url)
|
58
|
+
url.path = '/vco/api'
|
59
|
+
@url = url.to_s
|
60
|
+
end
|
61
|
+
# rubocop:enable LineLength
|
62
|
+
|
63
|
+
# load config file
|
64
|
+
# @param [String] config_file Path for the configuration file to load
|
65
|
+
def load_config(config_file)
|
66
|
+
config_data = JSON.parse(File.read(config_file))
|
67
|
+
return if config_data.nil?
|
68
|
+
self.url = config_data['url']
|
69
|
+
@username = config_data['username']
|
70
|
+
@password = config_data['password']
|
71
|
+
@verify_ssl = config_data['verify_ssl']
|
72
|
+
end
|
73
|
+
|
74
|
+
# Return a String representation of this object
|
75
|
+
# @return [String]
|
76
|
+
def to_s
|
77
|
+
puts "url: #{@url}"
|
78
|
+
puts "username: #{@username}"
|
79
|
+
puts "password: #{@password}"
|
80
|
+
puts "verify_ssl: #{@verify_ssl}"
|
81
|
+
end
|
82
|
+
|
83
|
+
# Return a JSON document for this object
|
84
|
+
def to_json
|
85
|
+
config = {}
|
86
|
+
config['url'] = @url
|
87
|
+
config['username'] = @username
|
88
|
+
config['password'] = @password
|
89
|
+
config['verify_ssl'] = @verify_ssl
|
90
|
+
puts JSON.pretty_generate(config)
|
91
|
+
end
|
92
|
+
end
|
93
|
+
end
|
@@ -2,6 +2,15 @@
|
|
2
2
|
module VcoWorkflows
|
3
3
|
# rubocop:disable LineLength
|
4
4
|
|
5
|
+
#
|
6
|
+
class Config
|
7
|
+
# Where we nominally expect configuration files to be
|
8
|
+
DEFAULT_CONFIG_DIR = File.join((ENV['HOME'] || ENV['HOMEDRIVE']), '.vcoworkflows')
|
9
|
+
|
10
|
+
# Default configuration file
|
11
|
+
DEFAULT_CONFIG_FILE = File.join(DEFAULT_CONFIG_DIR, 'config.json')
|
12
|
+
end
|
13
|
+
|
5
14
|
# Options description messages
|
6
15
|
|
7
16
|
# Version
|
@@ -76,6 +85,7 @@ module VcoWorkflows
|
|
76
85
|
no_workflow_service_defined: 'vcoworkflows: Attempted to execute a workflow with a nil workflow service!',
|
77
86
|
param_verify_failed: 'vcoworkflows: Attempt to verify required parameter failed!',
|
78
87
|
no_such_parameter: 'Attempted to set a parameter that does not exist!',
|
88
|
+
url_unset: 'No URL was configured, nothing to connect to!',
|
79
89
|
username_unset: 'No username was specified, either by $VCO_USER or --username',
|
80
90
|
password_unset: 'No password was specified, either by $VCO_PASSWD or --password'
|
81
91
|
}
|
@@ -1,4 +1,5 @@
|
|
1
|
-
|
1
|
+
require 'vcoworkflows/constants'
|
2
|
+
require 'vcoworkflows/config'
|
2
3
|
require 'rest_client'
|
3
4
|
|
4
5
|
# VcoWorkflows
|
@@ -9,20 +10,41 @@ module VcoWorkflows
|
|
9
10
|
# Accessor for rest-client object, primarily for testing purposes
|
10
11
|
attr_reader :rest_resource
|
11
12
|
|
13
|
+
# rubocop:disable MethodLength, LineLength
|
14
|
+
|
12
15
|
# Initialize the session
|
13
16
|
#
|
17
|
+
# When specifying a config, do not provide other parameters. Likewise,
|
18
|
+
# if providing uri, user, and password, a config object is not necessary.
|
19
|
+
#
|
20
|
+
# @param [VcoWorkflows::Config] config Configuration object for the connection
|
14
21
|
# @param [String] uri URI for the vCenter Orchestrator API endpoint
|
15
22
|
# @param [String] user User name for vCO
|
16
23
|
# @param [String] password Password for vCO
|
17
24
|
# @param [Boolean] verify_ssl Whether or not to verify SSL certificates
|
18
|
-
def initialize(uri, user: nil, password: nil, verify_ssl: true)
|
19
|
-
|
25
|
+
def initialize(config: nil, uri: nil, user: nil, password: nil, verify_ssl: true)
|
26
|
+
# If a configuration object was provided, use it.
|
27
|
+
# If we got a URL and no config, build a new config with the URL and any
|
28
|
+
# other options that passed in.
|
29
|
+
# Otherwise, load the default config file if possible...
|
30
|
+
if config
|
31
|
+
config = config
|
32
|
+
elsif uri && config.nil?
|
33
|
+
config = VcoWorkflows::Config.new(url: uri,
|
34
|
+
username: user,
|
35
|
+
password: password,
|
36
|
+
verify_ssl: verify_ssl)
|
37
|
+
elsif uri.nil? && config.nil?
|
38
|
+
config = VcoWorkflows::Config.new
|
39
|
+
end
|
40
|
+
|
20
41
|
RestClient.proxy = ENV['http_proxy'] # Set a proxy if present
|
21
|
-
@rest_resource = RestClient::Resource.new(
|
22
|
-
user:
|
23
|
-
password:
|
24
|
-
verify_ssl: verify_ssl)
|
42
|
+
@rest_resource = RestClient::Resource.new(config.url,
|
43
|
+
user: config.username,
|
44
|
+
password: config.password,
|
45
|
+
verify_ssl: config.verify_ssl)
|
25
46
|
end
|
47
|
+
# rubocop:enable MethodLength, LineLength
|
26
48
|
|
27
49
|
# Perform a REST GET operation against the specified endpoint
|
28
50
|
#
|
data/lib/vcoworkflows/version.rb
CHANGED
@@ -29,27 +29,24 @@ module VcoWorkflows
|
|
29
29
|
# @return [String] workflow description
|
30
30
|
attr_reader :description
|
31
31
|
|
32
|
-
# Workflow Input Parameters
|
33
|
-
# @return [Hash<VcoWorkflows::WorkflowParameter>]
|
34
|
-
# WorkflowParameter objects, keyed by name
|
32
|
+
# Workflow Input Parameters: Hash of WorkflowParameters, keyed by name
|
33
|
+
# @return [Hash<VcoWorkflows::WorkflowParameter>]
|
35
34
|
attr_reader :input_parameters
|
36
35
|
|
37
|
-
# Workflow Output Parameters
|
38
|
-
# @return [Hash<VcoWorkflows::WorkflowParameter>]
|
39
|
-
# WorkflowParameter objects, keyed by name
|
36
|
+
# Workflow Output Parameters: Hash of WorkflowParameters, keyed by name
|
37
|
+
# @return [Hash<VcoWorkflows::WorkflowParameter>]
|
40
38
|
attr_reader :output_parameters
|
41
39
|
|
42
|
-
# Workflow Service
|
43
|
-
# @return [VcoWorkflows::WorkflowService]
|
44
|
-
# currently being used to interface with vCO
|
40
|
+
# Workflow Service in use by this Workflow
|
41
|
+
# @return [VcoWorkflows::WorkflowService]
|
45
42
|
attr_accessor :service
|
46
43
|
|
47
44
|
# Workflow execution ID
|
48
|
-
# @return [String]
|
45
|
+
# @return [String]
|
49
46
|
attr_reader :execution_id
|
50
47
|
|
51
48
|
# Workflow source JSON
|
52
|
-
# @return [String]
|
49
|
+
# @return [String]
|
53
50
|
attr_reader :source_json
|
54
51
|
|
55
52
|
# rubocop:enable LineLength
|
@@ -60,10 +57,20 @@ module VcoWorkflows
|
|
60
57
|
#
|
61
58
|
# When passed `url`, `username` and `password` the necessary session and
|
62
59
|
# service objects will be created behind the scenes. Alternatively you can
|
63
|
-
# pass in a
|
64
|
-
# constructed them yourself.
|
60
|
+
# pass in a Config or a WorkflowService object if you have
|
61
|
+
# constructed them yourself. You may also pass in the path to a
|
62
|
+
# configuration file (`config_file`).
|
63
|
+
#
|
65
64
|
# @param [String] name Name of the requested workflow
|
66
|
-
# @param [Hash] options Hash of options
|
65
|
+
# @param [Hash] options Hash of options:
|
66
|
+
# - id: (String) GUID for the Workflow
|
67
|
+
# - url: (String) vCO REST API URL
|
68
|
+
# - username: (String) User to authenticate as
|
69
|
+
# - password: (String) Password for username
|
70
|
+
# - verify_ssl: (Boolean) Perform TLS/SSL certificate validation
|
71
|
+
# - service: (VcoWorkflows::WorkflowService) WorkflowService to use for communicating to vCO
|
72
|
+
# - config: (VcoWorkflows::Config) Configuration object to use for this workflow's session
|
73
|
+
# - config_file: (String) Path to load configuration file from for this workflow's session
|
67
74
|
# @return [VcoWorkflows::Workflow]
|
68
75
|
def initialize(name = nil, options = {})
|
69
76
|
@options = {
|
@@ -72,9 +79,12 @@ module VcoWorkflows
|
|
72
79
|
username: nil,
|
73
80
|
password: nil,
|
74
81
|
verify_ssl: true,
|
75
|
-
service: nil
|
82
|
+
service: nil,
|
83
|
+
config: nil,
|
84
|
+
config_file: nil
|
76
85
|
}.merge(options)
|
77
86
|
|
87
|
+
config = nil
|
78
88
|
@service = nil
|
79
89
|
@execution_id = nil
|
80
90
|
|
@@ -84,11 +94,29 @@ module VcoWorkflows
|
|
84
94
|
|
85
95
|
if options[:service]
|
86
96
|
@service = options[:service]
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
97
|
+
else
|
98
|
+
# If we were given a configuration object, use it
|
99
|
+
# If we were given a config file path, use it
|
100
|
+
# If we have a url, username and password, use them
|
101
|
+
# If all we have is a URL, try anyway, maybe we'll get username and
|
102
|
+
# password from ENV values (hey, it might work...)
|
103
|
+
if @options[:config]
|
104
|
+
config = @options[:config]
|
105
|
+
elsif @options[:config_file]
|
106
|
+
config = VcoWorkflows::Config.new(config_file: @options[:config_file])
|
107
|
+
elsif @options[:url] && @options[:username] && @options[:password]
|
108
|
+
config = VcoWorkflows::Config.new(url: @options[:url],
|
109
|
+
username: @options[:username],
|
110
|
+
password: @options[:password],
|
111
|
+
verify_ssl: @options[:verify_ssl])
|
112
|
+
elsif @options[:url]
|
113
|
+
config = VcoWorkflows::Config.new(url: @options[:url],
|
114
|
+
verify_ssl: @options[:verify_ssl])
|
115
|
+
end
|
116
|
+
|
117
|
+
# If we got a config object above, great. If it's still nil, VcoSession
|
118
|
+
# will accept that and try to load the default config file.
|
119
|
+
session = VcoWorkflows::VcoSession.new(config: config)
|
92
120
|
@service = VcoWorkflows::WorkflowService.new(session)
|
93
121
|
end
|
94
122
|
|
@@ -0,0 +1,58 @@
|
|
1
|
+
require_relative '../spec_helper.rb'
|
2
|
+
require 'vcoworkflows'
|
3
|
+
|
4
|
+
# rubocop:disable LineLength
|
5
|
+
|
6
|
+
describe VcoWorkflows::Config, 'Config' do
|
7
|
+
before(:each) do
|
8
|
+
@url = 'https://vcoserver.example.com:8281/vco/api'
|
9
|
+
@username = 'johndoe'
|
10
|
+
@password = 's3cr3t'
|
11
|
+
|
12
|
+
@config_file = '/tmp/vcoconfig.json'
|
13
|
+
@config_data = {
|
14
|
+
url: @url,
|
15
|
+
username: @username,
|
16
|
+
password: @password
|
17
|
+
}.to_json
|
18
|
+
|
19
|
+
allow(File).to receive(:read).and_call_original
|
20
|
+
allow(File).to receive(:read).with(@config_file).and_return(@config_data)
|
21
|
+
end
|
22
|
+
|
23
|
+
it 'should configure the URL from parameters' do
|
24
|
+
config = VcoWorkflows::Config.new(url: @url, username: @username, password: @password)
|
25
|
+
|
26
|
+
expect(config.url).to eql(@url)
|
27
|
+
end
|
28
|
+
|
29
|
+
it 'should configure the username from parameters' do
|
30
|
+
config = VcoWorkflows::Config.new(url: @url, username: @username, password: @password)
|
31
|
+
|
32
|
+
expect(config.username).to eql(@username)
|
33
|
+
end
|
34
|
+
|
35
|
+
it 'should configure the password from parameters' do
|
36
|
+
config = VcoWorkflows::Config.new(url: @url, username: @username, password: @password)
|
37
|
+
|
38
|
+
expect(config.password).to eql(@password)
|
39
|
+
end
|
40
|
+
|
41
|
+
it 'should configure the URL from a configuration file' do
|
42
|
+
config = VcoWorkflows::Config.new(config_file: @config_file)
|
43
|
+
|
44
|
+
expect(config.url).to eql(@url)
|
45
|
+
end
|
46
|
+
|
47
|
+
it 'should configure the username from a configuration file' do
|
48
|
+
config = VcoWorkflows::Config.new(config_file: @config_file)
|
49
|
+
|
50
|
+
expect(config.username).to eql(@username)
|
51
|
+
end
|
52
|
+
|
53
|
+
it 'should configure the password from a configuration file' do
|
54
|
+
config = VcoWorkflows::Config.new(config_file: @config_file)
|
55
|
+
|
56
|
+
expect(config.password).to eql(@password)
|
57
|
+
end
|
58
|
+
end
|
@@ -8,23 +8,44 @@ describe VcoWorkflows::VcoSession, 'VcoSession' do
|
|
8
8
|
@uri = 'https://vcoserver.example.com:8281'
|
9
9
|
@username = 'johndoe'
|
10
10
|
@password = 's3cr3t'
|
11
|
+
|
12
|
+
@config = VcoWorkflows::Config.new(url: @uri, username: @username, password: @password)
|
13
|
+
end
|
14
|
+
|
15
|
+
it 'should set the URL from parameters' do
|
16
|
+
vs = VcoWorkflows::VcoSession.new(uri: @uri, user: @username, password: @password)
|
17
|
+
api_url = '/vco/api'
|
18
|
+
|
19
|
+
expect(vs.rest_resource.url).to eql(@uri << api_url)
|
20
|
+
end
|
21
|
+
|
22
|
+
it 'should set the username from parameters' do
|
23
|
+
vs = VcoWorkflows::VcoSession.new(uri: @uri, user: @username, password: @password)
|
24
|
+
|
25
|
+
expect(vs.rest_resource.user).to eql(@username)
|
26
|
+
end
|
27
|
+
|
28
|
+
it 'should set the password from parameters' do
|
29
|
+
vs = VcoWorkflows::VcoSession.new(uri: @uri, user: @username, password: @password)
|
30
|
+
|
31
|
+
expect(vs.rest_resource.password).to eql(@password)
|
11
32
|
end
|
12
33
|
|
13
|
-
it 'should set the URL' do
|
14
|
-
vs = VcoWorkflows::VcoSession.new(
|
34
|
+
it 'should set the URL from configuration' do
|
35
|
+
vs = VcoWorkflows::VcoSession.new(config: @config)
|
15
36
|
api_url = '/vco/api'
|
16
37
|
|
17
38
|
expect(vs.rest_resource.url).to eql(@uri << api_url)
|
18
39
|
end
|
19
40
|
|
20
|
-
it 'should set the username' do
|
21
|
-
vs = VcoWorkflows::VcoSession.new(
|
41
|
+
it 'should set the username from configuration' do
|
42
|
+
vs = VcoWorkflows::VcoSession.new(config: @config)
|
22
43
|
|
23
44
|
expect(vs.rest_resource.user).to eql(@username)
|
24
45
|
end
|
25
46
|
|
26
|
-
it 'should set the password' do
|
27
|
-
vs = VcoWorkflows::VcoSession.new(
|
47
|
+
it 'should set the password from configuration' do
|
48
|
+
vs = VcoWorkflows::VcoSession.new(config: @config)
|
28
49
|
|
29
50
|
expect(vs.rest_resource.password).to eql(@password)
|
30
51
|
end
|
@@ -30,9 +30,42 @@ describe VcoWorkflows::Workflow, 'Workflow' do
|
|
30
30
|
|
31
31
|
# Mock the WorkflowService
|
32
32
|
@service = double('service')
|
33
|
-
allow(@service).to receive(:get_workflow_for_id)
|
34
|
-
allow(@service).to receive(:get_workflow_for_name)
|
35
|
-
allow(@service).to receive(:get_presentation)
|
33
|
+
allow(@service).to receive(:get_workflow_for_id).and_return(@workflow_json)
|
34
|
+
allow(@service).to receive(:get_workflow_for_name).and_return(@workflow_json)
|
35
|
+
allow(@service).to receive(:get_presentation).and_return(@presentation_json)
|
36
|
+
|
37
|
+
# Config object, file, data for constructor testing
|
38
|
+
@config_file = '/tmp/vcoconfig.json'
|
39
|
+
@config_data = {
|
40
|
+
url: @url,
|
41
|
+
username: @username,
|
42
|
+
password: @password
|
43
|
+
}.to_json
|
44
|
+
@config = VcoWorkflows::Config.new(url: 'https://vcoserver.example.com:8281/vco/api',
|
45
|
+
username: 'johndoe',
|
46
|
+
password: 's3cre3t')
|
47
|
+
allow(VcoWorkflows::VcoSession).to receive(:new).and_return(true)
|
48
|
+
allow(VcoWorkflows::WorkflowService).to receive(:new).and_return(@service)
|
49
|
+
allow(File).to receive(:read).and_call_original
|
50
|
+
allow(File).to receive(:read).with(@config_file).and_return(@config_data)
|
51
|
+
end
|
52
|
+
|
53
|
+
it 'should not explode when created with service' do
|
54
|
+
wf = VcoWorkflows::Workflow.new(@workflow_name, service: @service)
|
55
|
+
|
56
|
+
expect(wf).to_not eq(nil)
|
57
|
+
end
|
58
|
+
|
59
|
+
it 'should not explode when created with config' do
|
60
|
+
wf = VcoWorkflows::Workflow.new(@workflow_name, config: @config)
|
61
|
+
|
62
|
+
expect(wf).to_not eq(nil)
|
63
|
+
end
|
64
|
+
|
65
|
+
it 'should not explode when created with config_file' do
|
66
|
+
wf = VcoWorkflows::Workflow.new(@workflow_name)
|
67
|
+
|
68
|
+
expect(wf).to_not eq(nil)
|
36
69
|
end
|
37
70
|
|
38
71
|
it 'should parse a single string parameter' do
|
@@ -79,12 +112,6 @@ describe VcoWorkflows::Workflow, 'Workflow' do
|
|
79
112
|
expect(wfparams['arrayparam'].value).to eql(%w(a b c))
|
80
113
|
end
|
81
114
|
|
82
|
-
it 'should not explode' do
|
83
|
-
wf = VcoWorkflows::Workflow.new(@workflow_name, service: @service)
|
84
|
-
|
85
|
-
expect(wf).to_not eq(nil)
|
86
|
-
end
|
87
|
-
|
88
115
|
it 'should have input and output parameters' do
|
89
116
|
input_param_count = 13
|
90
117
|
output_param_count = 3
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: vcoworkflows
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Gregory Ruiz-ade
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-04
|
11
|
+
date: 2015-06-04 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -226,9 +226,9 @@ files:
|
|
226
226
|
- bin/vcoworkflows
|
227
227
|
- example.rb
|
228
228
|
- lib/vcoworkflows.rb
|
229
|
-
- lib/vcoworkflows/cli/auth.rb
|
230
229
|
- lib/vcoworkflows/cli/execute.rb
|
231
230
|
- lib/vcoworkflows/cli/query.rb
|
231
|
+
- lib/vcoworkflows/config.rb
|
232
232
|
- lib/vcoworkflows/constants.rb
|
233
233
|
- lib/vcoworkflows/runner.rb
|
234
234
|
- lib/vcoworkflows/vcosession.rb
|
@@ -240,6 +240,7 @@ files:
|
|
240
240
|
- lib/vcoworkflows/workflowservice.rb
|
241
241
|
- lib/vcoworkflows/workflowtoken.rb
|
242
242
|
- spec/spec_helper.rb
|
243
|
+
- spec/vcoworkflows/config_spec.rb
|
243
244
|
- spec/vcoworkflows/vcosession_spec.rb
|
244
245
|
- spec/vcoworkflows/workflow_spec.rb
|
245
246
|
- spec/vcoworkflows/workflowexecutionlog_spec.rb
|
@@ -268,12 +269,13 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
268
269
|
version: '0'
|
269
270
|
requirements: []
|
270
271
|
rubyforge_project:
|
271
|
-
rubygems_version: 2.
|
272
|
+
rubygems_version: 2.2.2
|
272
273
|
signing_key:
|
273
274
|
specification_version: 4
|
274
275
|
summary: vCO Workflows REST API Wrapper
|
275
276
|
test_files:
|
276
277
|
- spec/spec_helper.rb
|
278
|
+
- spec/vcoworkflows/config_spec.rb
|
277
279
|
- spec/vcoworkflows/vcosession_spec.rb
|
278
280
|
- spec/vcoworkflows/workflow_spec.rb
|
279
281
|
- spec/vcoworkflows/workflowexecutionlog_spec.rb
|
@@ -1,41 +0,0 @@
|
|
1
|
-
require 'vcoworkflows/constants'
|
2
|
-
|
3
|
-
# VcoWorkflows
|
4
|
-
module VcoWorkflows
|
5
|
-
# Cli
|
6
|
-
module Cli
|
7
|
-
# Auth is a very small helper class to allow pulling authentication
|
8
|
-
# credentials from the environment when using one of the executable
|
9
|
-
# commands.
|
10
|
-
#
|
11
|
-
# If credentials aren't passed in as options to the command, we'll
|
12
|
-
# also check the environment for $VCO_USER and $VCO_PASSWD and use
|
13
|
-
# those. Otherwise, command line options will override environment
|
14
|
-
# values.
|
15
|
-
class Auth
|
16
|
-
# username
|
17
|
-
# @return [String]
|
18
|
-
attr_reader :username
|
19
|
-
|
20
|
-
# password
|
21
|
-
# @return [String]
|
22
|
-
attr_reader :password
|
23
|
-
|
24
|
-
# Initialize the Auth object. If the paramaters are nil, look
|
25
|
-
# for values in the environment instead.
|
26
|
-
# @param [String] username vCenter Orchestrator user name
|
27
|
-
# @param [String] password vCenter Orchestrator password
|
28
|
-
# @return [VcoWorkflows::Cli::Auth]
|
29
|
-
def initialize(username: nil, password: nil)
|
30
|
-
# Set username and password from parameters, if provided, or
|
31
|
-
# environment variables $VCO_USER and $VCO_PASSWD, if not.
|
32
|
-
@username = username.nil? ? ENV['VCO_USER'] : username
|
33
|
-
@password = password.nil? ? ENV['VCO_PASSWD'] : password
|
34
|
-
|
35
|
-
# Fail if we don't have both a username and a password.
|
36
|
-
fail(IOError, ERR[:username_unset]) if @username.nil?
|
37
|
-
fail(IOError, ERR[:password_unset]) if @password.nil?
|
38
|
-
end
|
39
|
-
end
|
40
|
-
end
|
41
|
-
end
|