cube_cli 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +12 -0
- data/.rspec +3 -0
- data/.travis.yml +7 -0
- data/Gemfile +4 -0
- data/Gemfile.lock +39 -0
- data/README.md +35 -0
- data/Rakefile +6 -0
- data/bin/console +14 -0
- data/bin/cube_cli +4 -0
- data/bin/setup +8 -0
- data/cube_cli.gemspec +36 -0
- data/lib/cube_cli.rb +92 -0
- data/lib/cube_cli/cli.rb +31 -0
- data/lib/cube_cli/version.rb +3 -0
- metadata +132 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 267afbce3233be60c12764986558252ca8585707e0aef7ecd8fec018809d81ef
|
4
|
+
data.tar.gz: c228fb2e38f23e43fa1f827ab58bd001eb7859d94b8ba9865b9945470e458eb3
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: e08fb3371e97c0b3bd1e09c44d34bbc2d64b2ee1bce78b46b27f52cfd4590545cf38c6202d08375b150901bc6fc60ab304f70fe93b74778d958ae10e3df3e01a
|
7
|
+
data.tar.gz: a28bbaac9156dd8fa77913dcf428598a1d672054bd6fa98e4b2858a00d45bdc0a67ea7834b719c01e059bd172a713d8dc463e444c7609fb3a71c12a1e8d95202
|
data/.gitignore
ADDED
data/.rspec
ADDED
data/.travis.yml
ADDED
data/Gemfile
ADDED
data/Gemfile.lock
ADDED
@@ -0,0 +1,39 @@
|
|
1
|
+
PATH
|
2
|
+
remote: .
|
3
|
+
specs:
|
4
|
+
cube_cli (0.1.0)
|
5
|
+
thor (~> 1.0.1)
|
6
|
+
yaml (~> 0.1.0)
|
7
|
+
|
8
|
+
GEM
|
9
|
+
remote: https://rubygems.org/
|
10
|
+
specs:
|
11
|
+
diff-lcs (1.4.4)
|
12
|
+
rake (10.5.0)
|
13
|
+
rspec (3.9.0)
|
14
|
+
rspec-core (~> 3.9.0)
|
15
|
+
rspec-expectations (~> 3.9.0)
|
16
|
+
rspec-mocks (~> 3.9.0)
|
17
|
+
rspec-core (3.9.2)
|
18
|
+
rspec-support (~> 3.9.3)
|
19
|
+
rspec-expectations (3.9.2)
|
20
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
21
|
+
rspec-support (~> 3.9.0)
|
22
|
+
rspec-mocks (3.9.1)
|
23
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
24
|
+
rspec-support (~> 3.9.0)
|
25
|
+
rspec-support (3.9.3)
|
26
|
+
thor (1.0.1)
|
27
|
+
yaml (0.1.0)
|
28
|
+
|
29
|
+
PLATFORMS
|
30
|
+
ruby
|
31
|
+
|
32
|
+
DEPENDENCIES
|
33
|
+
bundler (~> 2.0)
|
34
|
+
cube_cli!
|
35
|
+
rake (~> 10.0)
|
36
|
+
rspec (~> 3.0)
|
37
|
+
|
38
|
+
BUNDLED WITH
|
39
|
+
2.0.2
|
data/README.md
ADDED
@@ -0,0 +1,35 @@
|
|
1
|
+
# CubeCli
|
2
|
+
|
3
|
+
Welcome to your new gem! In this directory, you'll find the files you need to be able to package up your Ruby library into a gem. Put your Ruby code in the file `lib/cube_cli`. To experiment with that code, run `bin/console` for an interactive prompt.
|
4
|
+
|
5
|
+
TODO: Delete this and the text above, and describe your gem
|
6
|
+
|
7
|
+
## Installation
|
8
|
+
|
9
|
+
Add this line to your application's Gemfile:
|
10
|
+
|
11
|
+
```ruby
|
12
|
+
gem 'cube_cli'
|
13
|
+
```
|
14
|
+
|
15
|
+
And then execute:
|
16
|
+
|
17
|
+
$ bundle
|
18
|
+
|
19
|
+
Or install it yourself as:
|
20
|
+
|
21
|
+
$ gem install cube_cli
|
22
|
+
|
23
|
+
## Usage
|
24
|
+
|
25
|
+
TODO: Write usage instructions here
|
26
|
+
|
27
|
+
## Development
|
28
|
+
|
29
|
+
After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
|
30
|
+
|
31
|
+
To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
|
32
|
+
|
33
|
+
## Contributing
|
34
|
+
|
35
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/cube_cli.
|
data/Rakefile
ADDED
data/bin/console
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require "bundler/setup"
|
4
|
+
require "cube_cli"
|
5
|
+
|
6
|
+
# You can add fixtures and/or initialization code here to make experimenting
|
7
|
+
# with your gem easier. You can also use a different console, if you like.
|
8
|
+
|
9
|
+
# (If you use this, don't forget to add pry to your Gemfile!)
|
10
|
+
# require "pry"
|
11
|
+
# Pry.start
|
12
|
+
|
13
|
+
require "irb"
|
14
|
+
IRB.start(__FILE__)
|
data/bin/cube_cli
ADDED
data/bin/setup
ADDED
data/cube_cli.gemspec
ADDED
@@ -0,0 +1,36 @@
|
|
1
|
+
lib = File.expand_path("lib", __dir__)
|
2
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
3
|
+
require "cube_cli/version"
|
4
|
+
|
5
|
+
Gem::Specification.new do |spec|
|
6
|
+
spec.name = "cube_cli"
|
7
|
+
spec.version = CubeCli::VERSION
|
8
|
+
spec.authors = ["Hging"]
|
9
|
+
spec.email = ["hging3@gmail.com"]
|
10
|
+
|
11
|
+
spec.summary = %q{This is a Ucloud Cube Cli}
|
12
|
+
spec.description = %q{This is a Ucloud Cube Cli}
|
13
|
+
spec.homepage = "https://github.com/hging/cube_cli"
|
14
|
+
|
15
|
+
# spec.metadata["allowed_push_host"] = "TODO: Set to 'http://mygemserver.com'"
|
16
|
+
|
17
|
+
spec.metadata["homepage_uri"] = spec.homepage
|
18
|
+
spec.metadata["source_code_uri"] = "https://github.com/hging/cube_cli"
|
19
|
+
spec.metadata["changelog_uri"] = "https://github.com/hging/cube_cli"
|
20
|
+
|
21
|
+
# Specify which files should be added to the gem when it is released.
|
22
|
+
# The `git ls-files -z` loads the files in the RubyGem that have been added into git.
|
23
|
+
spec.files = Dir.chdir(File.expand_path('..', __FILE__)) do
|
24
|
+
`git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
|
25
|
+
end
|
26
|
+
|
27
|
+
spec.bindir = "bin"
|
28
|
+
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
29
|
+
spec.require_paths = ["lib"]
|
30
|
+
|
31
|
+
spec.add_runtime_dependency "thor", "~> 1.0.1"
|
32
|
+
spec.add_runtime_dependency "yaml", "~> 0.1.0"
|
33
|
+
spec.add_development_dependency "bundler", "~> 2.0"
|
34
|
+
spec.add_development_dependency "rake", "~> 10.0"
|
35
|
+
spec.add_development_dependency "rspec", "~> 3.0"
|
36
|
+
end
|
data/lib/cube_cli.rb
ADDED
@@ -0,0 +1,92 @@
|
|
1
|
+
require "cube_cli/version"
|
2
|
+
require 'digest'
|
3
|
+
require 'digest/sha1'
|
4
|
+
require 'json'
|
5
|
+
require 'base64'
|
6
|
+
require 'net/http'
|
7
|
+
require 'net/https'
|
8
|
+
require 'yaml'
|
9
|
+
|
10
|
+
module CubeCli
|
11
|
+
class Error < StandardError; end
|
12
|
+
# Your code goes here...
|
13
|
+
def self.update(region, cube_id, image, pod_name)
|
14
|
+
@region = region
|
15
|
+
@cube_id = cube_id
|
16
|
+
@image = image
|
17
|
+
new_pod = old_pod
|
18
|
+
new_pod["spec"]["containers"] = old_pod["spec"]["containers"].map do |container|
|
19
|
+
container["image"] = image if container["name"] == pod_name
|
20
|
+
container
|
21
|
+
end
|
22
|
+
|
23
|
+
dict = {
|
24
|
+
"Action" => 'RenewCubePod',
|
25
|
+
"CubeId" => @cube_id,
|
26
|
+
"Region" => @region,
|
27
|
+
"ProjectId" => ENV['UCLOUD_PROJECT_ID'],
|
28
|
+
"PublicKey" => ENV['UCLOUD_PUBLIC_KEY'],
|
29
|
+
"Pod" => Base64.encode64(new_pod.to_yaml).split("\n").join
|
30
|
+
}
|
31
|
+
dict["Signature"] = signature(dict)
|
32
|
+
send_request(dict)
|
33
|
+
# 'Update' + image
|
34
|
+
end
|
35
|
+
|
36
|
+
def self.get(region, cube_id)
|
37
|
+
@region = region
|
38
|
+
@cube_id = cube_id
|
39
|
+
old_pod
|
40
|
+
end
|
41
|
+
|
42
|
+
|
43
|
+
def self.signature(dict)
|
44
|
+
a = Hash[ dict.sort_by { |key, val| key } ]
|
45
|
+
string = ""
|
46
|
+
a.each do |key, value|
|
47
|
+
string << key.to_s + value.to_s
|
48
|
+
end
|
49
|
+
Digest::SHA1.hexdigest(string + ENV['UCLOUD_PRIVATE_KEY'])
|
50
|
+
end
|
51
|
+
|
52
|
+
def self.old_pod
|
53
|
+
dict = {
|
54
|
+
"Action" => 'GetCubePod',
|
55
|
+
"CubeId" => @cube_id,
|
56
|
+
"Region" => @region,
|
57
|
+
"ProjectId" => ENV['UCLOUD_PROJECT_ID'],
|
58
|
+
"PublicKey" => ENV['UCLOUD_PUBLIC_KEY']
|
59
|
+
}
|
60
|
+
dict["Signature"] = signature(dict)
|
61
|
+
response = send_request(dict)
|
62
|
+
pod = Base64.decode64 response["Pod"]
|
63
|
+
YAML.load(pod)
|
64
|
+
end
|
65
|
+
|
66
|
+
|
67
|
+
def self.send_request(dict)
|
68
|
+
uri = URI('https://api.ucloud.cn/')
|
69
|
+
|
70
|
+
# Create client
|
71
|
+
http = Net::HTTP.new(uri.host, uri.port)
|
72
|
+
http.use_ssl = true
|
73
|
+
http.verify_mode = OpenSSL::SSL::VERIFY_PEER
|
74
|
+
body = JSON.dump(dict)
|
75
|
+
|
76
|
+
# Create Request
|
77
|
+
req = Net::HTTP::Post.new(uri)
|
78
|
+
# Add headers
|
79
|
+
req.add_field "Content-Type", "application/json; charset=utf-8"
|
80
|
+
# Set body
|
81
|
+
req.body = body
|
82
|
+
|
83
|
+
# Fetch Request
|
84
|
+
res = http.request(req)
|
85
|
+
# puts "Response HTTP Status Code: #{res.code}"
|
86
|
+
# puts "Response HTTP Response Body: #{res.body}"
|
87
|
+
return JSON.parse(res.body)
|
88
|
+
rescue StandardError => e
|
89
|
+
puts "HTTP Request failed (#{e.message})"
|
90
|
+
end
|
91
|
+
|
92
|
+
end
|
data/lib/cube_cli/cli.rb
ADDED
@@ -0,0 +1,31 @@
|
|
1
|
+
require "thor"
|
2
|
+
require "cube_cli"
|
3
|
+
module CubeCli
|
4
|
+
|
5
|
+
class CLI < Thor
|
6
|
+
desc "CubeCli", "CubeCli update"
|
7
|
+
method_option :image, :type => :string, :aliases => "-i"
|
8
|
+
method_option :cube_id, :type => :string, :aliases => "-c"
|
9
|
+
method_option :region, :type => :string, :aliases => "-r"
|
10
|
+
method_option :pod_name, :type => :string, :aliases => "-p"
|
11
|
+
|
12
|
+
def update
|
13
|
+
image = options[:image]
|
14
|
+
cube_id = options[:cube_id]
|
15
|
+
region = options[:region] || 'cn-bj2'
|
16
|
+
pod_name = options[:pod_name]
|
17
|
+
puts CubeCli.update(region, cube_id, image, pod_name)
|
18
|
+
end
|
19
|
+
|
20
|
+
desc "CubeCli", "CubeCli get"
|
21
|
+
method_option :cube_id, :type => :string, :aliases => "-c"
|
22
|
+
method_option :region, :type => :string, :aliases => "-r"
|
23
|
+
|
24
|
+
def get
|
25
|
+
cube_id = options[:cube_id]
|
26
|
+
region = options[:region] || 'cn-bj2'
|
27
|
+
puts CubeCli.get(region, cube_id)
|
28
|
+
end
|
29
|
+
|
30
|
+
end
|
31
|
+
end
|
metadata
ADDED
@@ -0,0 +1,132 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: cube_cli
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Hging
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2020-07-23 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: thor
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: 1.0.1
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: 1.0.1
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: yaml
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: 0.1.0
|
34
|
+
type: :runtime
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: 0.1.0
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: bundler
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '2.0'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '2.0'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: rake
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - "~>"
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '10.0'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - "~>"
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '10.0'
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: rspec
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - "~>"
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '3.0'
|
76
|
+
type: :development
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - "~>"
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '3.0'
|
83
|
+
description: This is a Ucloud Cube Cli
|
84
|
+
email:
|
85
|
+
- hging3@gmail.com
|
86
|
+
executables:
|
87
|
+
- console
|
88
|
+
- cube_cli
|
89
|
+
- setup
|
90
|
+
extensions: []
|
91
|
+
extra_rdoc_files: []
|
92
|
+
files:
|
93
|
+
- ".gitignore"
|
94
|
+
- ".rspec"
|
95
|
+
- ".travis.yml"
|
96
|
+
- Gemfile
|
97
|
+
- Gemfile.lock
|
98
|
+
- README.md
|
99
|
+
- Rakefile
|
100
|
+
- bin/console
|
101
|
+
- bin/cube_cli
|
102
|
+
- bin/setup
|
103
|
+
- cube_cli.gemspec
|
104
|
+
- lib/cube_cli.rb
|
105
|
+
- lib/cube_cli/cli.rb
|
106
|
+
- lib/cube_cli/version.rb
|
107
|
+
homepage: https://github.com/hging/cube_cli
|
108
|
+
licenses: []
|
109
|
+
metadata:
|
110
|
+
homepage_uri: https://github.com/hging/cube_cli
|
111
|
+
source_code_uri: https://github.com/hging/cube_cli
|
112
|
+
changelog_uri: https://github.com/hging/cube_cli
|
113
|
+
post_install_message:
|
114
|
+
rdoc_options: []
|
115
|
+
require_paths:
|
116
|
+
- lib
|
117
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
118
|
+
requirements:
|
119
|
+
- - ">="
|
120
|
+
- !ruby/object:Gem::Version
|
121
|
+
version: '0'
|
122
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
123
|
+
requirements:
|
124
|
+
- - ">="
|
125
|
+
- !ruby/object:Gem::Version
|
126
|
+
version: '0'
|
127
|
+
requirements: []
|
128
|
+
rubygems_version: 3.0.6
|
129
|
+
signing_key:
|
130
|
+
specification_version: 4
|
131
|
+
summary: This is a Ucloud Cube Cli
|
132
|
+
test_files: []
|