varager 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/Changelog +7 -0
- data/LICENSE +21 -0
- data/README.md +2 -0
- data/Rakefile +3 -0
- data/lib/varager/auth_token.rb +15 -0
- data/lib/varager/client.rb +43 -0
- data/lib/varager/handlers/app_response.rb +26 -0
- data/lib/varager/handlers.rb +7 -0
- data/lib/varager/models/env.rb +54 -0
- data/lib/varager/models/response.rb +7 -0
- data/lib/varager/models.rb +15 -0
- data/lib/varager/routes.rb +28 -0
- data/lib/varager/version.rb +3 -0
- data/lib/varager.rb +23 -0
- data/spec/spec_helper.rb +99 -0
- metadata +131 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: f1ff884688f9832aa7ede51d9310522c5a5e82dd
|
4
|
+
data.tar.gz: cf580f910d35ddcb7c5f80a7797952007086e2ae
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: de338f460c496885853b7b5fb9ff6fd95c4d434eee4e724f4298ffc8c955cfe3393e7bcbd8f0cd7eb3e589f5feb983e95f973bc3f24e566cb61a80a5d230ae84
|
7
|
+
data.tar.gz: 246d714704e113d108de5d86f6bdcde7791de6a82c571ebe014d2c95c688cfeaf5671342ce6d1a8670d899be45274da94be1d9b2fdea48a2775ad39f9c4faca2
|
data/Changelog
ADDED
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
data/Rakefile
ADDED
@@ -0,0 +1,15 @@
|
|
1
|
+
module Varager
|
2
|
+
class AuthToken < OpenAPI::AuthToken
|
3
|
+
|
4
|
+
def initialize
|
5
|
+
super ({"header" => "Authorization",
|
6
|
+
"header_format" => "%s"})
|
7
|
+
end
|
8
|
+
|
9
|
+
def new_auth_token()
|
10
|
+
auth_response = Varager.auth(body: {user: {email: Varager.user, password: Varager.password}}.to_json)
|
11
|
+
update({"token" => auth_response.authentication_token})
|
12
|
+
end
|
13
|
+
|
14
|
+
end
|
15
|
+
end
|
@@ -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 Varager
|
8
|
+
module ClassMethods
|
9
|
+
include OpenAPI::ClassMethods
|
10
|
+
attr_accessor :user, :password
|
11
|
+
|
12
|
+
def build_path(path, params=nil)
|
13
|
+
uri = URI("/#{path}.json")
|
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 ||= Varager::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] || Varager.user
|
34
|
+
@password = options[:password] || Varager.password
|
35
|
+
@logger = options[:logger] || Varager.logger
|
36
|
+
@site = options[:site] || Varager.site
|
37
|
+
@request_timeout = options[:request_timeout] || Varager.request_timeout || 5
|
38
|
+
@max_retry = options[:max_retry] || Varager.max_retry || 2
|
39
|
+
Varager::Routes.generate(self)
|
40
|
+
# init handlers
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|
@@ -0,0 +1,26 @@
|
|
1
|
+
module Varager
|
2
|
+
module Handlers
|
3
|
+
class AppResponse < 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 = Varager::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
|
+
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
@@ -0,0 +1,54 @@
|
|
1
|
+
module Varager
|
2
|
+
module Model
|
3
|
+
|
4
|
+
class Env
|
5
|
+
include Virtus.model
|
6
|
+
attribute :id, Integer
|
7
|
+
attribute :name, :String
|
8
|
+
attribute :config, Hash
|
9
|
+
attribute :created_at, Date
|
10
|
+
attribute :updated_at, Date
|
11
|
+
|
12
|
+
|
13
|
+
|
14
|
+
# def save!
|
15
|
+
# Varager.add_env(self.to_json)
|
16
|
+
# end
|
17
|
+
def conf_shell(with_export=false)
|
18
|
+
config.each {|k,v| puts "#{with_export ? 'export ' : ''}#{k}='#{v}'"}
|
19
|
+
end
|
20
|
+
|
21
|
+
def conf_yaml
|
22
|
+
config.each {|k,v| puts "#{k}: '#{v}'"}
|
23
|
+
end
|
24
|
+
|
25
|
+
def conf_k8s(indent=10)
|
26
|
+
space = "#{" " * indent}"
|
27
|
+
config.each {|k,v| puts "#{space}- name: #{k}\n#{space} value:'#{v}'"}
|
28
|
+
end
|
29
|
+
|
30
|
+
def conf_json
|
31
|
+
config.to_json
|
32
|
+
end
|
33
|
+
|
34
|
+
def add_var(key, value)
|
35
|
+
Varager.add_vars(params: {id: self.name}, body: {config: {key => value}}.to_json)
|
36
|
+
end
|
37
|
+
|
38
|
+
def add_vars(dict)
|
39
|
+
Varager.add_vars(params: {id: self.name}, body: {config: dict}.to_json)
|
40
|
+
end
|
41
|
+
|
42
|
+
def self.json_root
|
43
|
+
@json_root = "environment"
|
44
|
+
end
|
45
|
+
|
46
|
+
end
|
47
|
+
|
48
|
+
class Envs
|
49
|
+
include Virtus.model
|
50
|
+
attribute :environments, Array[Env]
|
51
|
+
end
|
52
|
+
|
53
|
+
end
|
54
|
+
end
|
@@ -0,0 +1,15 @@
|
|
1
|
+
$:.unshift(File.dirname(__FILE__))
|
2
|
+
module Varager
|
3
|
+
module Model
|
4
|
+
autoload :Response, "models/response"
|
5
|
+
autoload :Env, "models/env"
|
6
|
+
autoload :Envs, "models/env"
|
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,28 @@
|
|
1
|
+
module Varager
|
2
|
+
|
3
|
+
module Routes
|
4
|
+
class << self
|
5
|
+
def generate(client=Varager)
|
6
|
+
OpenAPI::Route.draw(client) do
|
7
|
+
## AUTH
|
8
|
+
match "users/sign_in", "varager/handlers/app_response#response", :auth, via: :post, :options => {:skip_auth => true}
|
9
|
+
|
10
|
+
## ENVS
|
11
|
+
match "api/environments", "varager/handlers/app_response#envs", :list_envs, via: :get
|
12
|
+
match "api/environments/:id", "varager/handlers/app_response#env", :get_env, via: :get
|
13
|
+
match "api/environments/:id", "varager/handlers/app_response#env", :delete_env, via: :delete
|
14
|
+
match "api/environments/:id", "varager/handlers/app_response#env", :add_vars, via: :put
|
15
|
+
|
16
|
+
## USERS
|
17
|
+
match "api/users", "varager/handlers/app_response#response", :list_users, via: :get
|
18
|
+
|
19
|
+
# CRUD CALLS
|
20
|
+
match "GET", "varager/handlers/app_response#response", :GET, via: :get
|
21
|
+
match "DELETE", "varager/handlers/app_response#response", :DELETE, via: :get
|
22
|
+
match "PUT", "varager/handlers/app_response#response", :PUT, via: :get
|
23
|
+
match "POST", "varager/handlers/app_response#response", :POST, via: :post
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
data/lib/varager.rb
ADDED
@@ -0,0 +1,23 @@
|
|
1
|
+
require 'hashie'
|
2
|
+
require 'virtus'
|
3
|
+
require 'openapi'
|
4
|
+
require 'varager/auth_token'
|
5
|
+
require 'varager/models'
|
6
|
+
require 'varager/handlers'
|
7
|
+
require 'varager/routes'
|
8
|
+
require 'varager/client'
|
9
|
+
|
10
|
+
# LAST
|
11
|
+
|
12
|
+
## MOVE TO APP ""
|
13
|
+
require 'logger'
|
14
|
+
Varager.application_secret = "sk_test_2qITuuqhz7iuUExfIGHhBR"
|
15
|
+
Varager.site = "http://localhost:3000"
|
16
|
+
Varager.user = 'admin@email.com'
|
17
|
+
Varager.password = 'adminvarager'
|
18
|
+
|
19
|
+
Varager.logger = Logger.new(STDOUT)
|
20
|
+
OpenAPI.logger = Varager.logger
|
21
|
+
OpenAPI.cache = false
|
22
|
+
|
23
|
+
Varager::Routes.generate(Varager)
|
data/spec/spec_helper.rb
ADDED
@@ -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,131 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: varager
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Antoine Legrand
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2016-01-21 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: varager is a Ruby library for interacting with the Varager 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/varager.rb
|
95
|
+
- lib/varager/auth_token.rb
|
96
|
+
- lib/varager/client.rb
|
97
|
+
- lib/varager/handlers.rb
|
98
|
+
- lib/varager/handlers/app_response.rb
|
99
|
+
- lib/varager/models.rb
|
100
|
+
- lib/varager/models/env.rb
|
101
|
+
- lib/varager/models/response.rb
|
102
|
+
- lib/varager/routes.rb
|
103
|
+
- lib/varager/version.rb
|
104
|
+
- spec/spec_helper.rb
|
105
|
+
homepage: http://github.com/ant31/openapi-varager
|
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.4.5
|
126
|
+
signing_key:
|
127
|
+
specification_version: 4
|
128
|
+
summary: A Ruby wrapper for the Varager API
|
129
|
+
test_files:
|
130
|
+
- spec/spec_helper.rb
|
131
|
+
has_rdoc:
|