kpm-cnr 0.2.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 88ca7014fb28d3e43362e57a908c79d1507e436e
4
+ data.tar.gz: 28639de99b70c236fa4827bef5231813049890dc
5
+ SHA512:
6
+ metadata.gz: ee641ccfa42fbd51820cb670bed40ee357678dcd79437e1bd2d130d2022f65ed188595256c5fdac7aadea0b7704764d01c4830e1222cc13a8f752e481649ce92
7
+ data.tar.gz: d85e722c23d419c95ca39d0b059494b65f5ca2b1121d07da9da9a5a09dc9fe1c418bd22dfd5f4e748626ea9e48e351576c0d93121969578d892f176889e594cc
data/Changelog ADDED
@@ -0,0 +1,4 @@
1
+ - 0.0.2
2
+ * Gem build
3
+
4
+ -- Antoine Legrand <ant.legrand@gmail.com> 27/07/2016
data/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2016 Antoine Legrand
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,59 @@
1
+ Varager ruby wrapper
2
+ =======================
3
+ # Installation
4
+ ```bash
5
+ gem install varager
6
+ ```
7
+
8
+ # Configuration
9
+ ```ruby
10
+ # Server endpoint
11
+ Varager.site = "http://localhost:3000"
12
+
13
+ # Creds
14
+ Varager.user = "ant@gmail.com"
15
+ Varager.password = "totolala"
16
+
17
+ # Loggers
18
+ Varager.logger = Logger.new(STDOUT)
19
+ OpenAPI.logger = Varager.logger
20
+ ```
21
+
22
+ # Usage
23
+ Auth is done once on the first call
24
+
25
+ ## Environments
26
+ ### List
27
+ ```ruby
28
+ # Get all envs
29
+ envs = Varager.list_envs
30
+ #=> #<Varager::Model::Envs>>
31
+ first_env = envs.environments[0]
32
+ #=> #<Varager::Model::Env>>
33
+ ```
34
+ ### Get
35
+ ```ruby
36
+ # 1. From http_client
37
+ env = Varager.get_env(params: {id: env_id})
38
+ #=> #<Varager::Model::Env>>
39
+ ```
40
+ ### Delete
41
+ ```ruby
42
+ # 1. From http_client
43
+ env = Varager.get_env(params: {id: env_id})
44
+ #=> #<Varager::Model::Env>>
45
+
46
+ # 2. From model
47
+ env.delete!
48
+ ```
49
+
50
+ ## Add variables to an environment
51
+ ```ruby
52
+ # 1. From http_client
53
+ env = Varager.add_vars(params: {id: env_id}, body: {config: {var1: value, var2: value2}}.to_json)
54
+ #=> #<Varager::Model::Env>>
55
+
56
+ # 2. From model
57
+ env.add_var(key, value)
58
+ env.add_vars({key1: value, key2: value2})
59
+ ```
data/Rakefile ADDED
@@ -0,0 +1,3 @@
1
+ require 'bundler'
2
+ Bundler::GemHelper.install_tasks
3
+ Dir.glob('tasks/*.rake').each { |r| import r }
data/lib/kpm.rb ADDED
@@ -0,0 +1,24 @@
1
+ require 'hashie'
2
+ require 'virtus'
3
+ require 'openapi'
4
+ require 'kpm/auth_token'
5
+ require 'kpm/models'
6
+ require 'kpm/handlers'
7
+ require 'kpm/routes'
8
+ require 'kpm/client'
9
+
10
+ # LAST
11
+
12
+ ## MOVE TO APP ""
13
+ require 'logger'
14
+
15
+ Kpm.application_secret = "sk_test_2qITuuqhz7iuUExfIGHhBR"
16
+ Kpm.site = "http://localhost:5000"
17
+ Kpm.user = 'admin@email.com'
18
+ Kpm.password = 'adminkpm'
19
+ Kpm.logger = Logger.new(STDOUT)
20
+ Kpm.logger.level = 1
21
+ OpenAPI.logger = Kpm.logger
22
+ OpenAPI.cache = false
23
+
24
+ Kpm::Routes.generate(Kpm)
@@ -0,0 +1,17 @@
1
+ module Kpm
2
+ class AuthToken < OpenAPI::AuthToken
3
+
4
+ def initialize
5
+ super ({"expires_in" => 3600,
6
+ "header" => "Authorization",
7
+ "header_format" => "%s"})
8
+ end
9
+
10
+ def new_auth_token()
11
+ # auth_response = Kpm.auth(body: {user: {email: Kpm.user, password: Kpm.password}}.to_json)
12
+ # auth_response.authentication_token
13
+ update({"token" => "no-token-required-yet"})
14
+ end
15
+
16
+ end
17
+ end
data/lib/kpm/client.rb ADDED
@@ -0,0 +1,43 @@
1
+ require 'json'
2
+ require 'net/https'
3
+ require 'time'
4
+ require 'base64'
5
+
6
+ #require File.join(File.dirname(__FILE__), '../../response')
7
+ module Kpm
8
+ module ClassMethods
9
+ include OpenAPI::ClassMethods
10
+ attr_accessor :user, :password
11
+
12
+ def build_path(path, params=nil)
13
+ uri = URI("/api/v1/#{path}")
14
+ if params != nil
15
+ uri.query = URI.encode_www_form(params)
16
+ end
17
+ return uri
18
+ end
19
+
20
+ def auth_token
21
+ @auth_token ||= Kpm::AuthToken.new
22
+ end
23
+ end
24
+
25
+ class << self
26
+ include ClassMethods
27
+ end
28
+
29
+ class Client
30
+ include ClassMethods
31
+
32
+ def initialize(options={})
33
+ @user = options[:user] || Kpm.user
34
+ @password = options[:password] || Kpm.password
35
+ @logger = options[:logger] || Kpm.logger
36
+ @site = options[:site] || Kpm.site
37
+ @request_timeout = options[:request_timeout] || Kpm.request_timeout || 5
38
+ @max_retry = options[:max_retry] || Kpm.max_retry || 2
39
+ Kpm::Routes.generate(self)
40
+ # init handlers
41
+ end
42
+ end
43
+ end
@@ -0,0 +1,8 @@
1
+ $:.unshift(File.dirname(__FILE__))
2
+
3
+ module Kpm
4
+ module Handlers
5
+ autoload :Model, "handlers/json"
6
+ autoload :Array, "handlers/json"
7
+ end
8
+ end
@@ -0,0 +1,58 @@
1
+ module Kpm
2
+ module Handlers
3
+ class Model < OpenAPI::Handler
4
+ class << self
5
+ def method_missing(method_symbol, *arguments) #:nodoc:
6
+ method_name = method_symbol.to_s
7
+ return self.send :const_model, method_name, *arguments
8
+ end
9
+
10
+ private
11
+
12
+ def const_model(snake_name, response, options)
13
+ klass_name = snake_name.camelize
14
+ hash = JSON.parse(response.raw)
15
+ klass = Kpm::Model.const_get(klass_name)
16
+ if klass.respond_to?(:json_root)
17
+ hash = hash[klass.json_root]
18
+ end
19
+ resp = klass.new(hash)
20
+ return OpenAPI::Handlers::Response.wrap(resp, response)
21
+ end
22
+ end
23
+ end
24
+
25
+ class Binary < OpenAPI::Handler
26
+ class << self
27
+ def fetch(response, options)
28
+ return OpenAPI::Handlers::Response.wrap(response.raw, response)
29
+ end
30
+ end
31
+ end
32
+
33
+ class Array < OpenAPI::Handler
34
+ class << self
35
+ def method_missing(method_symbol, *arguments) #:nodoc:
36
+ method_name = method_symbol.to_s
37
+ return self.send :const_model, method_name, *arguments
38
+ end
39
+
40
+ private
41
+
42
+ def const_model(snake_name, response, options)
43
+ klass_name = snake_name.camelize
44
+ array = JSON.parse(response.raw)
45
+ klass = Kpm::Model.const_get(klass_name)
46
+ resp = []
47
+ array.each do |item|
48
+ if klass.respond_to?(:json_root)
49
+ hash = hash[klass.json_root]
50
+ end
51
+ resp << klass.new(item)
52
+ end
53
+ return OpenAPI::Handlers::Response.wrap(resp, response)
54
+ end
55
+ end
56
+ end
57
+ end
58
+ end
data/lib/kpm/models.rb ADDED
@@ -0,0 +1,15 @@
1
+ $:.unshift(File.dirname(__FILE__))
2
+ module Kpm
3
+ module Model
4
+ autoload :Response, "models/response"
5
+ autoload :Pacakge, "models/package"
6
+ autoload :Packages, "models/package"
7
+
8
+ class Hashie < Virtus::Attribute
9
+ def coerce(value)
10
+ ::Hashie::Mash.new(value)
11
+ end
12
+ end
13
+
14
+ end
15
+ end
@@ -0,0 +1,53 @@
1
+ module Kpm
2
+ module Model
3
+
4
+ class Package
5
+ include Virtus.model
6
+ attribute :id, Integer
7
+ attribute :name, :String
8
+ attribute :vars, Hash
9
+ attribute :created_at, Date
10
+ attribute :updated_at, Date
11
+
12
+ def conf_shell(with_export=false)
13
+ vars.each {|k,v| puts "#{with_export ? 'export ' : ''}#{k}='#{v}'"}
14
+ end
15
+
16
+ def conf_yaml
17
+ vars.each {|k,v| puts "#{k}: '#{v}'"}
18
+ end
19
+
20
+ def conf_k8s(indent=10)
21
+ space = "#{" " * indent}"
22
+ vars.each {|k,v| puts "#{space}- name: #{k}\n#{space} value:'#{v}'"}
23
+ end
24
+
25
+ def conf_json
26
+ vars.to_json
27
+ end
28
+
29
+ def users
30
+ Kpm.list_env_users(params: {environment_id: self.id})
31
+ end
32
+
33
+ def add_var(key, value)
34
+ Kpm.add_vars(params: {id: self.name.gsub("/", "+")}, body: {vars: {key => value}}.to_json)
35
+ end
36
+
37
+ def add_vars(dict)
38
+ Kpm.add_vars(params: {id: self.name.gsub("/", "+")}, body: {vars: dict}.to_json)
39
+ end
40
+
41
+ # def self.json_root
42
+ # @json_root = "environment"
43
+ # end
44
+
45
+ end
46
+
47
+ class Packages
48
+ include Virtus.model
49
+ attribute :packages, Array[Package]
50
+ end
51
+
52
+ end
53
+ end
@@ -0,0 +1,7 @@
1
+ module Kpm
2
+ module Model
3
+ class Response < ::Hashie::Mash
4
+
5
+ end
6
+ end
7
+ end
data/lib/kpm/routes.rb ADDED
@@ -0,0 +1,28 @@
1
+ module Kpm
2
+
3
+ module Routes
4
+ class << self
5
+ def generate(client=Kpm)
6
+ OpenAPI::Route.draw(client) do
7
+ ## AUTH
8
+ match "users/login", "kpm/handlers/model#response", :auth, via: :post, :options => {:skip_auth => true}
9
+
10
+ ## Packages
11
+ match "packages", "kpm/handlers/model#response", :list, via: :get
12
+ match "packages/:name/:version/:type", "kpm/handlers/model#response", :get, via: :get
13
+ match "packages/:name/:version/:type", "kpm/handlers/model#response", :delete, via: :delete
14
+ match "packages/:name", "kpm/handlers/model#response", :push, via: :post
15
+ match "packages/:name/:version/:type/pull", "kpm/handlers/model#response", :pull, via: :get, params: "format"
16
+ match "packages/:name/:version/:type/generate", "kpm/handlers/model#response", :generate, via: :get
17
+ match "packages/:name/:version/:type/generate-tar", "kpm/handlers/binary#fetch", :generate_tar, via: :get
18
+
19
+ # CRUD CALLS
20
+ match "GET", "kpm/handlers/model#response", :GET, via: :get
21
+ match "DELETE", "kpm/handlers/model#response", :DELETE, via: :delete
22
+ match "PUT", "kpm/handlers/model#response", :PUT, via: :get
23
+ match "POST", "kpm/handlers/model#response", :POST, via: :post
24
+ end
25
+ end
26
+ end
27
+ end
28
+ end
@@ -0,0 +1,3 @@
1
+ module Kpm
2
+ VERSION = '0.2.1'
3
+ end
@@ -0,0 +1,99 @@
1
+ # This file was generated by the `rspec --init` command. Conventionally, all
2
+ # specs live under a `spec` directory, which RSpec adds to the `$LOAD_PATH`.
3
+ # The generated `.rspec` file contains `--require spec_helper` which will cause this
4
+ # file to always be loaded, without a need to explicitly require it in any files.
5
+ #
6
+ # Given that it is always loaded, you are encouraged to keep this file as
7
+ # light-weight as possible. Requiring heavyweight dependencies from this file
8
+ # will add to the boot time of your test suite on EVERY test run, even for an
9
+ # individual file that may not need all of that loaded. Instead, consider making
10
+ # a separate helper file that requires the additional dependencies and performs
11
+ # the additional setup, and require it from the spec files that actually need it.
12
+ #
13
+ # The `.rspec` file also contains a few flags that are not defaults but that
14
+ # users commonly want.
15
+ #
16
+ # See http://rubydoc.info/gems/rspec-core/RSpec/Core/Configuration
17
+ require 'simplecov'
18
+ require "codeclimate-test-reporter"
19
+ CodeClimate::TestReporter.start
20
+ SimpleCov.start do
21
+ add_filter 'spec/'
22
+ add_group 'lib', 'lib'
23
+ end
24
+
25
+ require 'varager'
26
+
27
+ RSpec.configure do |config|
28
+ # rspec-expectations config goes here. You can use an alternate
29
+ # assertion/expectation library such as wrong or the stdlib/minitest
30
+ # assertions if you prefer.
31
+ config.expect_with :rspec do |expectations|
32
+ # This option will default to `true` in RSpec 4. It makes the `description`
33
+ # and `failure_message` of custom matchers include text for helper methods
34
+ # defined using `chain`, e.g.:
35
+ # be_bigger_than(2).and_smaller_than(4).description
36
+ # # => "be bigger than 2 and smaller than 4"
37
+ # ...rather than:
38
+ # # => "be bigger than 2"
39
+ expectations.include_chain_clauses_in_custom_matcher_descriptions = true
40
+ end
41
+
42
+ # rspec-mocks config goes here. You can use an alternate test double
43
+ # library (such as bogus or mocha) by changing the `mock_with` option here.
44
+ config.mock_with :rspec do |mocks|
45
+ # Prevents you from mocking or stubbing a method that does not exist on
46
+ # a real object. This is generally recommended, and will default to
47
+ # `true` in RSpec 4.
48
+ mocks.verify_partial_doubles = true
49
+ end
50
+
51
+ # The settings below are suggested to provide a good initial experience
52
+ # with RSpec, but feel free to customize to your heart's content.
53
+ =begin
54
+ # These two settings work together to allow you to limit a spec run
55
+ # to individual examples or groups you care about by tagging them with
56
+ # `:focus` metadata. When nothing is tagged with `:focus`, all examples
57
+ # get run.
58
+ config.filter_run :focus
59
+ config.run_all_when_everything_filtered = true
60
+
61
+ # Limits the available syntax to the non-monkey patched syntax that is recommended.
62
+ # For more details, see:
63
+ # - http://myronmars.to/n/dev-blog/2012/06/rspecs-new-expectation-syntax
64
+ # - http://teaisaweso.me/blog/2013/05/27/rspecs-new-message-expectation-syntax/
65
+ # - http://myronmars.to/n/dev-blog/2014/05/notable-changes-in-rspec-3#new__config_option_to_disable_rspeccore_monkey_patching
66
+ config.disable_monkey_patching!
67
+
68
+ # This setting enables warnings. It's recommended, but in some cases may
69
+ # be too noisy due to issues in dependencies.
70
+ config.warnings = true
71
+
72
+ # Many RSpec users commonly either run the entire suite or an individual
73
+ # file, and it's useful to allow more verbose output when running an
74
+ # individual spec file.
75
+ if config.files_to_run.one?
76
+ # Use the documentation formatter for detailed output,
77
+ # unless a formatter has already been configured
78
+ # (e.g. via a command-line flag).
79
+ config.default_formatter = 'doc'
80
+ end
81
+
82
+ # Print the 10 slowest examples and example groups at the
83
+ # end of the spec run, to help surface which specs are running
84
+ # particularly slow.
85
+ config.profile_examples = 10
86
+
87
+ # Run specs in random order to surface order dependencies. If you find an
88
+ # order dependency and want to debug it, you can fix the order by providing
89
+ # the seed, which is printed after each run.
90
+ # --seed 1234
91
+ config.order = :random
92
+
93
+ # Seed global randomization in this process using the `--seed` CLI option.
94
+ # Setting this allows you to use `--seed` to deterministically reproduce
95
+ # test failures related to randomization by passing the same `--seed` value
96
+ # as the one that triggered the failure.
97
+ Kernel.srand config.seed
98
+ =end
99
+ end
metadata ADDED
@@ -0,0 +1,130 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: kpm-cnr
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.2.1
5
+ platform: ruby
6
+ authors:
7
+ - Antoine Legrand
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2016-12-16 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: openapi
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: '0.10'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: '0.10'
27
+ - !ruby/object:Gem::Dependency
28
+ name: virtus
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '1'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '1'
41
+ - !ruby/object:Gem::Dependency
42
+ name: hashie
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ version: '1'
48
+ type: :runtime
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ version: '1'
55
+ - !ruby/object:Gem::Dependency
56
+ name: rspec
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ">="
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ">="
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: fakeweb
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - ">="
74
+ - !ruby/object:Gem::Version
75
+ version: '0'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - ">="
81
+ - !ruby/object:Gem::Version
82
+ version: '0'
83
+ description: kpm is a Ruby library for interacting with the Kpm API.
84
+ email:
85
+ - ant.legrand@gmail.com
86
+ executables: []
87
+ extensions: []
88
+ extra_rdoc_files: []
89
+ files:
90
+ - Changelog
91
+ - LICENSE
92
+ - README.md
93
+ - Rakefile
94
+ - lib/kpm.rb
95
+ - lib/kpm/auth_token.rb
96
+ - lib/kpm/client.rb
97
+ - lib/kpm/handlers.rb
98
+ - lib/kpm/handlers/json.rb
99
+ - lib/kpm/models.rb
100
+ - lib/kpm/models/package.rb
101
+ - lib/kpm/models/response.rb
102
+ - lib/kpm/routes.rb
103
+ - lib/kpm/version.rb
104
+ - spec/spec_helper.rb
105
+ homepage: http://github.com/kubespray/kpm-ruby-cli
106
+ licenses:
107
+ - MIT
108
+ metadata: {}
109
+ post_install_message:
110
+ rdoc_options: []
111
+ require_paths:
112
+ - lib
113
+ required_ruby_version: !ruby/object:Gem::Requirement
114
+ requirements:
115
+ - - ">="
116
+ - !ruby/object:Gem::Version
117
+ version: 1.9.2
118
+ required_rubygems_version: !ruby/object:Gem::Requirement
119
+ requirements:
120
+ - - ">="
121
+ - !ruby/object:Gem::Version
122
+ version: '0'
123
+ requirements: []
124
+ rubyforge_project:
125
+ rubygems_version: 2.5.2
126
+ signing_key:
127
+ specification_version: 4
128
+ summary: A Ruby wrapper for the Kpm API
129
+ test_files:
130
+ - spec/spec_helper.rb