rancher-management_api 0.1.1 → 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: a8e47474e013afef88f37a76c601e11a3244add2
4
- data.tar.gz: 67e0cc31a9d46ed63467af6110e66aa6ca2d15f0
3
+ metadata.gz: a24ea79731fd57cff0e36d504652a7e4568ebee6
4
+ data.tar.gz: 7d8010517a332885d784204d1e9dabe14ddd965c
5
5
  SHA512:
6
- metadata.gz: 766df1bc4efe60b8fd84940974437179929db4b98d306ffb81260248b9d0fc72159c24765ff343e0294f4df6bed8de2c7487348a79c9bebb2e12e591dcc8e4c4
7
- data.tar.gz: a4176f74b542c6571cbf558216b66da28d6ed59fc010894817e3d4d66bf1dea8666f3d39dc249e3485660a00303e82dc226314635f0544a58bd98471f21aa7de
6
+ metadata.gz: b04d51b8c2117a2a2923ae11ed22abfe2f3351749424c6673dd7bcb79088a9dd13f33e2dec2180c90f3832b2c653739c5828db448951ffc4868684e02910de6c
7
+ data.tar.gz: f27e2b3deb6587e7969101f5e105db39de9b74700efd1d2594c590c95b7a2190404492640f9e9cb8885cd4ac7964f6c94f7257f03b574424baa53799bc3c3b57
data/README.md CHANGED
@@ -3,28 +3,33 @@
3
3
  ## Usage
4
4
 
5
5
  1. Create a manager:
6
+
6
7
  a. If your Rancher has access control:
7
- ```ruby
8
- manager = Rancher::ManagementApi::Token.build_manager(
9
- host: "http://localhost:8080",
10
- username: "youruser",
11
- password: "yourpassword"
12
- )
13
- ```
8
+ ```ruby
9
+ manager = Rancher::ManagementApi::Token.build_manager(
10
+ host: "http://localhost:8080",
11
+ username: "youruser",
12
+ password: "yourpassword"
13
+ )
14
+ ```
15
+
14
16
  b. Or just create a manager:
15
- ```ruby
16
- manager = Rancher::ManagementApi::Manager.new(
17
- host: "http://localhost:8080",
18
- )
19
- ```
17
+ ```ruby
18
+ manager = Rancher::ManagementApi::Manager.new(
19
+ host: "http://localhost:8080",
20
+ )
21
+ ```
22
+
20
23
  2. Create a project (known in the UI as an Environment):
21
24
  ```ruby
22
25
  project = manager.create_project("my environment name")
23
26
  ```
27
+
24
28
  3. Create a new API key:
25
29
  ```ruby
26
30
  api_key = project.create_api_key("my api key name")
27
31
  ```
32
+
28
33
  4. Save your api_key's secret:
29
34
  ```ruby
30
35
  puts "Your new RANCHER_ACCESS_KEY=#{api_key.publicValue}"
@@ -0,0 +1,83 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ $:.unshift(File.expand_path("../../lib", __FILE__))
4
+ require 'rancher-management_api'
5
+ require 'optparse'
6
+
7
+ @options = {
8
+ uri: ENV["RANCHER_URI"],
9
+ username: ENV["RANCHER_USER"],
10
+ password: ENV["RANCHER_PASS"],
11
+ environment_name: ENV["ENVIRONMENT_NAME"],
12
+ key_name: ENV["KEY_NAME"],
13
+ output_format: ENV.fetch("OUTPUT_FORMAT", "json")
14
+ }
15
+ valid_output_formats = %w(json yml yaml)
16
+
17
+ optparse = OptionParser.new do |opts|
18
+ opts.on("-h", "--host RANCHER_URI", "URI to reach the rancher API", "Example: http://rancher.foo.com/") do |arg|
19
+ @options[:uri] = arg.chomp
20
+ end
21
+ opts.on("-u", "--user RANCHER_USER", "User to use for authentication") do |arg|
22
+ @options[:username] = arg.chomp
23
+ end
24
+ opts.on("-p", "--pass RANCHER_PASS", "Password to use for authentication") do |arg|
25
+ @options[:password] = arg.chomp
26
+ end
27
+ opts.on("-e", "--environment ENVIRONMENT_NAME", "Name of the environment to create") do |arg|
28
+ @options[:environment_name] = arg.chomp
29
+ end
30
+ opts.on("-k", "--key KEY_NAME", "Name of the api key to create") do |arg|
31
+ @options[:key_name] = arg.chomp
32
+ end
33
+ opts.on("-f", "--format OUTPUT_FORMAT", "Format of the keys", "Valid options (#{valid_output_formats.join(", ")})", "Default: json") do |arg|
34
+ @options[:output_format] = arg.chomp
35
+ end
36
+ end
37
+
38
+ optparse.parse!
39
+
40
+
41
+ errors = []
42
+ errors.push("Must specify a rancher host with -h or RANCHER_URI environment variable") unless @options[:uri]
43
+ errors.push("Must specify an environment name with -e or ENVIRONMENT_NAME environment variable") unless @options[:environment_name]
44
+ errors.push("Must specify a key name with -k or KEY_NAME environment variable") unless @options[:key_name]
45
+ errors.push("Output format must be one of (#{valid_output_formats.join(", ")})") unless valid_output_formats.include?(@options[:output_format])
46
+
47
+ # validate the options
48
+ if errors.any?
49
+ $stderr.puts "Cannot continue:"
50
+ errors.each do |msg|
51
+ $stderr.puts "\t#{msg}"
52
+ end
53
+ $stderr.puts optparse.help
54
+ exit(1)
55
+ end
56
+
57
+ # do the work
58
+ manager = if @options[:username] && @options[:password]
59
+ Rancher::ManagementApi::Token.build_manager(
60
+ host: @options[:uri],
61
+ username: @options[:username],
62
+ password: @options[:password]
63
+ )
64
+ else
65
+ Rancher::ManagementApi::Manager.new(
66
+ host: @options[:uri]
67
+ )
68
+ end
69
+ project = manager.create_project(@options[:environment_name])
70
+ api_key = project.create_api_key(@options[:key_name])
71
+
72
+ output = {
73
+ access_key: api_key.publicValue,
74
+ secret_key: api_key.secretValue
75
+ }
76
+ case @options[:output_format]
77
+ when "json"
78
+ output = output.to_json
79
+ when "yml", "yaml"
80
+ require 'yaml'
81
+ output = output.to_yaml
82
+ end
83
+ puts output
@@ -1,4 +1,5 @@
1
1
  require "ostruct"
2
+ require "json"
2
3
 
3
4
  module Rancher
4
5
  module ManagementApi
@@ -1,5 +1,5 @@
1
1
  module Rancher
2
2
  module ManagementApi
3
- VERSION = "0.1.1"
3
+ VERSION = "0.2.0"
4
4
  end
5
5
  end
@@ -15,8 +15,8 @@ Gem::Specification.new do |spec|
15
15
  spec.license = "MIT"
16
16
 
17
17
  spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
18
- spec.bindir = "exe"
19
- spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
18
+ spec.bindir = "bin"
19
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
20
20
  spec.require_paths = ["lib"]
21
21
 
22
22
  spec.add_dependency "faraday", "~> 0.9.2"
metadata CHANGED
@@ -1,15 +1,15 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rancher-management_api
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.1
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Donald Plummer
8
8
  - ''
9
9
  autorequire:
10
- bindir: exe
10
+ bindir: bin
11
11
  cert_chain: []
12
- date: 2016-07-29 00:00:00.000000000 Z
12
+ date: 2016-08-01 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: faraday
@@ -98,7 +98,10 @@ dependencies:
98
98
  description: Client for creating environments and apikeys for Rancher.
99
99
  email:
100
100
  - dplummer@avvo.com
101
- executables: []
101
+ executables:
102
+ - console
103
+ - rancher-management
104
+ - setup
102
105
  extensions: []
103
106
  extra_rdoc_files: []
104
107
  files:
@@ -110,6 +113,7 @@ files:
110
113
  - README.md
111
114
  - Rakefile
112
115
  - bin/console
116
+ - bin/rancher-management
113
117
  - bin/setup
114
118
  - lib/rancher-management_api.rb
115
119
  - lib/rancher/management_api.rb