varager 0.0.1 → 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +59 -2
- data/lib/varager/auth_token.rb +3 -2
- data/lib/varager/handlers.rb +2 -1
- data/lib/varager/handlers/json.rb +50 -0
- data/lib/varager/models/env.rb +14 -15
- data/lib/varager/routes.rb +11 -10
- data/lib/varager/version.rb +1 -1
- metadata +3 -3
- data/lib/varager/handlers/app_response.rb +0 -26
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 343db2b78b491e160f73fefd1400a203bc91b9c0
|
4
|
+
data.tar.gz: 58aee4dfd41b33c3ac43ad5860c1226b6e5d97aa
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 1c3f2427258383e169a31852f41909f43bd12c35ae3bb05d960b725a7889844d1164b9ae8ae1eba2e21e41a84b00384b344e78c89e5e117d5ba518c9324e472b
|
7
|
+
data.tar.gz: 1be20b43f83652ce9a89cc1ac88abcdb7f3ab130238c7745407cadc4678b7263fd49b7115d515fdbba28fa11b17faf5e2a18767701f6533bce9575c620f5eafd
|
data/README.md
CHANGED
@@ -1,2 +1,59 @@
|
|
1
|
-
|
2
|
-
|
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/lib/varager/auth_token.rb
CHANGED
@@ -2,8 +2,9 @@ module Varager
|
|
2
2
|
class AuthToken < OpenAPI::AuthToken
|
3
3
|
|
4
4
|
def initialize
|
5
|
-
super ({"
|
6
|
-
|
5
|
+
super ({"expires_in" => 3600,
|
6
|
+
"header" => "Authorization",
|
7
|
+
"header_format" => "%s"})
|
7
8
|
end
|
8
9
|
|
9
10
|
def new_auth_token()
|
data/lib/varager/handlers.rb
CHANGED
@@ -0,0 +1,50 @@
|
|
1
|
+
module Varager
|
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 = 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
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
class Array < OpenAPI::Handler
|
26
|
+
class << self
|
27
|
+
def method_missing(method_symbol, *arguments) #:nodoc:
|
28
|
+
method_name = method_symbol.to_s
|
29
|
+
return self.send :const_model, method_name, *arguments
|
30
|
+
end
|
31
|
+
|
32
|
+
private
|
33
|
+
|
34
|
+
def const_model(snake_name, response, options)
|
35
|
+
klass_name = snake_name.camelize
|
36
|
+
array = JSON.parse(response.raw)
|
37
|
+
klass = Varager::Model.const_get(klass_name)
|
38
|
+
resp = []
|
39
|
+
array.each do |item|
|
40
|
+
if klass.respond_to?(:json_root)
|
41
|
+
hash = hash[klass.json_root]
|
42
|
+
end
|
43
|
+
resp << klass.new(item)
|
44
|
+
end
|
45
|
+
return OpenAPI::Handlers::Response.wrap(resp, response)
|
46
|
+
end
|
47
|
+
end
|
48
|
+
end
|
49
|
+
end
|
50
|
+
end
|
data/lib/varager/models/env.rb
CHANGED
@@ -5,43 +5,42 @@ module Varager
|
|
5
5
|
include Virtus.model
|
6
6
|
attribute :id, Integer
|
7
7
|
attribute :name, :String
|
8
|
-
attribute :
|
8
|
+
attribute :vars, Hash
|
9
9
|
attribute :created_at, Date
|
10
10
|
attribute :updated_at, Date
|
11
11
|
|
12
|
-
|
13
|
-
|
14
|
-
# def save!
|
15
|
-
# Varager.add_env(self.to_json)
|
16
|
-
# end
|
17
12
|
def conf_shell(with_export=false)
|
18
|
-
|
13
|
+
vars.each {|k,v| puts "#{with_export ? 'export ' : ''}#{k}='#{v}'"}
|
19
14
|
end
|
20
15
|
|
21
16
|
def conf_yaml
|
22
|
-
|
17
|
+
vars.each {|k,v| puts "#{k}: '#{v}'"}
|
23
18
|
end
|
24
19
|
|
25
20
|
def conf_k8s(indent=10)
|
26
21
|
space = "#{" " * indent}"
|
27
|
-
|
22
|
+
vars.each {|k,v| puts "#{space}- name: #{k}\n#{space} value:'#{v}'"}
|
28
23
|
end
|
29
24
|
|
30
25
|
def conf_json
|
31
|
-
|
26
|
+
vars.to_json
|
27
|
+
end
|
28
|
+
|
29
|
+
def users
|
30
|
+
Varager.list_env_users(params: {environment_id: self.id})
|
32
31
|
end
|
33
32
|
|
34
33
|
def add_var(key, value)
|
35
|
-
Varager.add_vars(params: {id: self.name}, body: {
|
34
|
+
Varager.add_vars(params: {id: self.name}, body: {vars: {key => value}}.to_json)
|
36
35
|
end
|
37
36
|
|
38
37
|
def add_vars(dict)
|
39
|
-
Varager.add_vars(params: {id: self.name}, body: {
|
38
|
+
Varager.add_vars(params: {id: self.name}, body: {vars: dict}.to_json)
|
40
39
|
end
|
41
40
|
|
42
|
-
def self.json_root
|
43
|
-
|
44
|
-
end
|
41
|
+
# def self.json_root
|
42
|
+
# @json_root = "environment"
|
43
|
+
# end
|
45
44
|
|
46
45
|
end
|
47
46
|
|
data/lib/varager/routes.rb
CHANGED
@@ -5,22 +5,23 @@ module Varager
|
|
5
5
|
def generate(client=Varager)
|
6
6
|
OpenAPI::Route.draw(client) do
|
7
7
|
## AUTH
|
8
|
-
match "users/sign_in", "varager/handlers/
|
8
|
+
match "users/sign_in", "varager/handlers/model#response", :auth, via: :post, :options => {:skip_auth => true}
|
9
9
|
|
10
10
|
## ENVS
|
11
|
-
match "
|
12
|
-
match "
|
13
|
-
match "
|
14
|
-
match "
|
11
|
+
match "environments", "varager/handlers/array#env", :list_envs, via: :get
|
12
|
+
match "environments/:id", "varager/handlers/model#env", :get_env, via: :get
|
13
|
+
match "environments/:id", "varager/handlers/model#env", :delete_env, via: :delete
|
14
|
+
match "environments/:id/addvars", "varager/handlers/model#env", :add_vars, via: :post
|
15
15
|
|
16
16
|
## USERS
|
17
|
-
match "
|
17
|
+
match "environments/:environment_id/users", "varager/handlers/array#response", :list_env_users, via: :get
|
18
|
+
match "users", "varager/handlers/array#response", :list_users, via: :get
|
18
19
|
|
19
20
|
# CRUD CALLS
|
20
|
-
match "GET", "varager/handlers/
|
21
|
-
match "DELETE", "varager/handlers/
|
22
|
-
match "PUT", "varager/handlers/
|
23
|
-
match "POST", "varager/handlers/
|
21
|
+
match "GET", "varager/handlers/model#response", :GET, via: :get
|
22
|
+
match "DELETE", "varager/handlers/model#response", :DELETE, via: :get
|
23
|
+
match "PUT", "varager/handlers/model#response", :PUT, via: :get
|
24
|
+
match "POST", "varager/handlers/model#response", :POST, via: :post
|
24
25
|
end
|
25
26
|
end
|
26
27
|
end
|
data/lib/varager/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: varager
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0
|
4
|
+
version: 0.1.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Antoine Legrand
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2016-01-
|
11
|
+
date: 2016-01-22 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: openapi
|
@@ -95,7 +95,7 @@ files:
|
|
95
95
|
- lib/varager/auth_token.rb
|
96
96
|
- lib/varager/client.rb
|
97
97
|
- lib/varager/handlers.rb
|
98
|
-
- lib/varager/handlers/
|
98
|
+
- lib/varager/handlers/json.rb
|
99
99
|
- lib/varager/models.rb
|
100
100
|
- lib/varager/models/env.rb
|
101
101
|
- lib/varager/models/response.rb
|
@@ -1,26 +0,0 @@
|
|
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
|