confyio 1.3.0 → 2.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 639af2dec4aaf421b6d016f8463dab340383fe1f
4
- data.tar.gz: 2d820b39bb1860f009291e418b2c832df001c044
3
+ metadata.gz: 77ed0ba6c5ab8d60c7c39c315413f72b130f9f7b
4
+ data.tar.gz: f33fabe1345355b732028fcdcaf8319b06d37d28
5
5
  SHA512:
6
- metadata.gz: 00d3892daec80f5552f41f1d28d00491febfe4887c2563414fc212163191163873a9fbf9105db7f111d70ca8416efb274dbd023e578c1304063b935fbb9b84ca
7
- data.tar.gz: 1c0374d9dd59cbf13bd0a38d5f396aead590a3119d9de9ca9b0085b15d3ff6f818dbccde35e72df053e4cef6d9c822969ec8cfeb6a0ca81e3e177907541a5612
6
+ metadata.gz: 8e588a7f0a687049eacc1b0ee268f4d6ba6d2e198b2c8faecb27acbe7bad8bc27a55c8c4d17543cc7d944763ee91c665df640b5269645955cbcb70dd1901d1c1
7
+ data.tar.gz: e2133bb0a2fef3a09a08c104dc9336e68f13907c29e498e0febf12819807fd9d029778f52dc32d1f18641811221adb8dfb3974f04a2b3c5bde2cef54d83445e5
@@ -2,7 +2,7 @@ module Confy
2
2
 
3
3
  module Api
4
4
 
5
- # List of teams who has access to the project. Default team __Owners__ will have access to every project. Authenticated user should be the owner of the organization for the below endpoints.
5
+ # List of teams whic have access to the project. Default team __Owners__ will have access to every project. Authenticated user should be the owner of the organization for the below endpoints.
6
6
  #
7
7
  # org - Name of the organization
8
8
  # project - Name of the project
@@ -14,7 +14,16 @@ module Confy
14
14
  @client = client
15
15
  end
16
16
 
17
- # Give the team access to the given project. The __team__ in the request needs to be a string.
17
+ # Retrieve a list of teams which have access to the given project. Authenticated user should be a member of the team.
18
+ #
19
+ # '/orgs/:org/projects/:project/access' GET
20
+ def list(options = {})
21
+ body = options.fetch(:query, {})
22
+
23
+ @client.get("/orgs/#{@org}/projects/#{@project}/access", body, options)
24
+ end
25
+
26
+ # Give the team access to the given project. The __team__ in the request needs to be a string and should be the name of a valid team. Authenticated user should be the owner of the organization.
18
27
  #
19
28
  # '/orgs/:org/projects/:project/access' POST
20
29
  #
@@ -26,7 +35,7 @@ module Confy
26
35
  @client.post("/orgs/#{@org}/projects/#{@project}/access", body, options)
27
36
  end
28
37
 
29
- # Remove project access for the given team. The __team__ in the request needs to be a string. Can't delete default team's access.
38
+ # Remove project access for the given team. The __team__ in the request needs to be a string and should be the name of a valid team. Can't delete default team's access. Authenticated user should be the owner of the organization.
30
39
  #
31
40
  # '/orgs/:org/projects/:project/access' DELETE
32
41
  #
@@ -16,7 +16,7 @@ module Confy
16
16
  @client = client
17
17
  end
18
18
 
19
- # Get an environment config of the project.
19
+ # Get an environment configuration
20
20
  #
21
21
  # '/orgs/:org/projects/:project/envs/:env/config' GET
22
22
  def retrieve(options = {})
@@ -29,11 +29,23 @@ module Confy
29
29
  #
30
30
  # '/orgs/:org/projects/:project/envs/:env/config' PATCH
31
31
  #
32
- # body - Configuration to update
33
- def update(body, options = {})
32
+ # config - Configuration to update
33
+ def update(config, options = {})
34
+ body = options.fetch(:body, {})
35
+ body[:config] = config
36
+
34
37
  @client.patch("/orgs/#{@org}/projects/#{@project}/envs/#{@env}/config", body, options)
35
38
  end
36
39
 
40
+ # List the last 10 versions of the environment configuration
41
+ #
42
+ # '/orgs/:org/projects/:project/envs/:env/versions' GET
43
+ def versions(options = {})
44
+ body = options.fetch(:query, {})
45
+
46
+ @client.get("/orgs/#{@org}/projects/#{@project}/envs/#{@env}/versions", body, options)
47
+ end
48
+
37
49
  end
38
50
 
39
51
  end
@@ -2,7 +2,7 @@ module Confy
2
2
 
3
3
  module Api
4
4
 
5
- # Every project has a default environment named Production. Each environment has one configuration document which can have many keys and values.
5
+ # Every project has a default environment named Production. Each environment has __one__ configuration document which can have many keys and values.
6
6
  #
7
7
  # org - Name of the organization
8
8
  # project - Name of the project
@@ -14,7 +14,7 @@ module Confy
14
14
  @client = client
15
15
  end
16
16
 
17
- # List all the environmens of the project which can be seen by the authenticated user.
17
+ # List all the environmens of the project. The authenticated user should have access to the project.
18
18
  #
19
19
  # '/orgs/:org/projects/:project/envs' GET
20
20
  def list(options = {})
@@ -23,7 +23,7 @@ module Confy
23
23
  @client.get("/orgs/#{@org}/projects/#{@project}/envs", body, options)
24
24
  end
25
25
 
26
- # Create an environment for the given project. Authenticated user should have access to the project.
26
+ # Create an environment. The authenticated user should have access to the project.
27
27
  #
28
28
  # '/orgs/:org/projects/:project/envs' POST
29
29
  #
@@ -37,7 +37,7 @@ module Confy
37
37
  @client.post("/orgs/#{@org}/projects/#{@project}/envs", body, options)
38
38
  end
39
39
 
40
- # Get an environment of the project the user has access to.
40
+ # Get the given environment in the given project. The authenticated user should have access to the project.
41
41
  #
42
42
  # '/orgs/:org/projects/:project/envs/:env' GET
43
43
  #
@@ -48,7 +48,7 @@ module Confy
48
48
  @client.get("/orgs/#{@org}/projects/#{@project}/envs/#{env}", body, options)
49
49
  end
50
50
 
51
- # Update an environment. Authenticated user should have access to the project.
51
+ # Update the given environment. __Description__ is the only thing which can be updated. Authenticated user should have access to the project.
52
52
  #
53
53
  # '/orgs/:org/projects/:project/envs/:env' PATCH
54
54
  #
@@ -61,7 +61,7 @@ module Confy
61
61
  @client.patch("/orgs/#{@org}/projects/#{@project}/envs/#{env}", body, options)
62
62
  end
63
63
 
64
- # Delete the given environment of the project. Authenticated user should have access to the project. Cannot delete the default environment.
64
+ # Delete the given environment. Authenticated user should have access to the project. Cannot delete the default environment.
65
65
  #
66
66
  # '/orgs/:org/projects/:project/envs/:env' DELETE
67
67
  #
@@ -14,7 +14,16 @@ module Confy
14
14
  @client = client
15
15
  end
16
16
 
17
- # Add the user to the given team. The __user__ in the request needs to be a string.
17
+ # List all the members in the given team. Authenticated user should be a member of the team or the owner of the org.
18
+ #
19
+ # '/orgs/:org/teams/:team/member' GET
20
+ def list(options = {})
21
+ body = options.fetch(:query, {})
22
+
23
+ @client.get("/orgs/#{@org}/teams/#{@team}/member", body, options)
24
+ end
25
+
26
+ # Add the user to the given team. The __user__ in the request needs to be a string and be the username of a valid user. The Authenticated user should be the owner of the organization.
18
27
  #
19
28
  # '/orgs/:org/teams/:team/member' POST
20
29
  #
@@ -26,7 +35,7 @@ module Confy
26
35
  @client.post("/orgs/#{@org}/teams/#{@team}/member", body, options)
27
36
  end
28
37
 
29
- # Remove users from the given team. The __user__ in the request needs to be a string. Cannot delete the default member in a team.
38
+ # Remove users from the given team. The __user__ in the request needs to be a string and be the username of a valid user. Cannot delete the default member in a team. The Authenticated user should be the owner of the organization.
30
39
  #
31
40
  # '/orgs/:org/teams/:team/member' DELETE
32
41
  #
@@ -18,21 +18,7 @@ module Confy
18
18
  @client.get("/orgs", body, options)
19
19
  end
20
20
 
21
- # Create an organization with a name and the email for billing.
22
- #
23
- # '/orgs' POST
24
- #
25
- # name - Name of the organization
26
- # email - Billing email of the organization
27
- def create(name, email, options = {})
28
- body = options.fetch(:body, {})
29
- body[:name] = name
30
- body[:email] = email
31
-
32
- @client.post("/orgs", body, options)
33
- end
34
-
35
- # Get an organization the user has access to.
21
+ # Get the given organization if the authenticated user is a member.
36
22
  #
37
23
  # '/orgs/:org' GET
38
24
  #
@@ -43,7 +29,7 @@ module Confy
43
29
  @client.get("/orgs/#{org}", body, options)
44
30
  end
45
31
 
46
- # Update an organization the user is owner of.
32
+ # Update the given organization if the authenticated user is the owner. __Email__ is the only thing which can be updated.
47
33
  #
48
34
  # '/orgs/:org' PATCH
49
35
  #
@@ -12,7 +12,7 @@ module Confy
12
12
  @client = client
13
13
  end
14
14
 
15
- # List all the projects of the organization which can be seen by the authenticated user.
15
+ # List all the projects of the given organization which can be accessed by the authenticated user.
16
16
  #
17
17
  # '/orgs/:org/projects' GET
18
18
  def list(options = {})
@@ -21,7 +21,7 @@ module Confy
21
21
  @client.get("/orgs/#{@org}/projects", body, options)
22
22
  end
23
23
 
24
- # Create a project for the given organization. Authenticated user should be the owner of the organization.
24
+ # Create a project if the authenticated user is the owner of the given organization. Only the __owners__ team will be able to see the project initially.
25
25
  #
26
26
  # '/orgs/:org/projects' POST
27
27
  #
@@ -35,7 +35,7 @@ module Confy
35
35
  @client.post("/orgs/#{@org}/projects", body, options)
36
36
  end
37
37
 
38
- # Get a project the user has access to.
38
+ # Get the given project in the given organization. Works only if the authenticated user has access to the project.
39
39
  #
40
40
  # '/orgs/:org/projects/:project' GET
41
41
  #
@@ -46,7 +46,7 @@ module Confy
46
46
  @client.get("/orgs/#{@org}/projects/#{project}", body, options)
47
47
  end
48
48
 
49
- # Update a project. Authenticated user should be the owner of the organization.
49
+ # Update the given project. __Description__ is the only thing which can be updated. Authenticated user should be the owner of the organization.
50
50
  #
51
51
  # '/orgs/:org/projects/:project' PATCH
52
52
  #
@@ -59,7 +59,7 @@ module Confy
59
59
  @client.patch("/orgs/#{@org}/projects/#{project}", body, options)
60
60
  end
61
61
 
62
- # Delete the given project. Cannot delete the default project in the organization. Authenticated user should be the owner of the organization.
62
+ # Delete the given project. Authenticated user should be the owner of the organization.
63
63
  #
64
64
  # '/orgs/:org/projects/:project' DELETE
65
65
  #
@@ -2,7 +2,7 @@ module Confy
2
2
 
3
3
  module Api
4
4
 
5
- # Every organization will have a default team named Owners. Owner of the organization will be a default member for every team.
5
+ # Every organization will have a default team named __Owners__. Owner of the organization will be a default member for every team.
6
6
  #
7
7
  # org - Name of the organization
8
8
  class Teams
@@ -35,7 +35,7 @@ module Confy
35
35
  @client.post("/orgs/#{@org}/teams", body, options)
36
36
  end
37
37
 
38
- # Get a team the user is member of.
38
+ # Get the given team in the given organization. Access only if the authenticated user is a member of the team.
39
39
  #
40
40
  # '/orgs/:org/teams/:team' GET
41
41
  #
@@ -46,7 +46,7 @@ module Confy
46
46
  @client.get("/orgs/#{@org}/teams/#{team}", body, options)
47
47
  end
48
48
 
49
- # Update a team. Authenticated user should be the owner of the organization.
49
+ # Update the given team. __Description__ is the only thing which can be updated. Authenticated user should be the owner of the organization.
50
50
  #
51
51
  # '/orgs/:org/teams/:team' PATCH
52
52
  #
@@ -70,6 +70,17 @@ module Confy
70
70
  @client.delete("/orgs/#{@org}/teams/#{team}", body, options)
71
71
  end
72
72
 
73
+ # Retrieve the list of projects the given team has access to. Authenticated user should be a member of the team.
74
+ #
75
+ # '/orgs/:org/teams/:team/projects' GET
76
+ #
77
+ # team - Name of the team
78
+ def projects(team, options = {})
79
+ body = options.fetch(:query, {})
80
+
81
+ @client.get("/orgs/#{@org}/teams/#{team}/projects", body, options)
82
+ end
83
+
73
84
  end
74
85
 
75
86
  end
@@ -18,14 +18,12 @@ module Confy
18
18
  @client.get("/user", body, options)
19
19
  end
20
20
 
21
- # Update the authenticated user's profile
21
+ # Update the authenticated user's profile. Should use basic authentication.
22
22
  #
23
23
  # '/user' PATCH
24
24
  #
25
- # email - Profile email of the user
26
- def update(email, options = {})
25
+ def update(options = {})
27
26
  body = options.fetch(:body, {})
28
- body[:email] = email
29
27
 
30
28
  @client.patch("/user", body, options)
31
29
  end
@@ -28,7 +28,7 @@ module Confy
28
28
  Confy::Api::Orgs.new(@http_client)
29
29
  end
30
30
 
31
- # Every organization will have a default team named Owners. Owner of the organization will be a default member for every team.
31
+ # Every organization will have a default team named __Owners__. Owner of the organization will be a default member for every team.
32
32
  #
33
33
  # org - Name of the organization
34
34
  def teams(org)
@@ -50,7 +50,7 @@ module Confy
50
50
  Confy::Api::Projects.new(org, @http_client)
51
51
  end
52
52
 
53
- # List of teams who has access to the project. Default team __Owners__ will have access to every project. Authenticated user should be the owner of the organization for the below endpoints.
53
+ # List of teams whic have access to the project. Default team __Owners__ will have access to every project. Authenticated user should be the owner of the organization for the below endpoints.
54
54
  #
55
55
  # org - Name of the organization
56
56
  # project - Name of the project
@@ -58,7 +58,7 @@ module Confy
58
58
  Confy::Api::Access.new(org, project, @http_client)
59
59
  end
60
60
 
61
- # Every project has a default environment named Production. Each environment has one configuration document which can have many keys and values.
61
+ # Every project has a default environment named Production. Each environment has __one__ configuration document which can have many keys and values.
62
62
  #
63
63
  # org - Name of the organization
64
64
  # project - Name of the project
@@ -1,25 +1,58 @@
1
+ require "json"
2
+ require "openssl"
3
+ require "digest/md5"
4
+ require "base64"
5
+
1
6
  module Confy
2
7
 
3
8
  class Config
4
9
 
5
10
  def self.load(url = {})
6
11
  if url.is_a?(String)
7
- regex = Regexp.new('(https?:\/\/)(.*):(.*)@(.*)\/orgs\/([a-z0-9]*)\/projects\/([a-z0-9]*)\/envs\/([a-z0-9]*)\/config', true)
8
- matches = regex.match(url)
12
+ name_regex = '([a-z0-9][a-z0-9-]*[a-z0-9])'
13
+ path_regex = 'orgs\\/' + name_regex + '\\/projects\\/' + name_regex + '\\/envs\\/' + name_regex
14
+ url_regex = Regexp.new('(https?:\\/\\/)(.*):(.*)@(.*)\\/(' + path_regex + '|heroku)\\/config', true)
15
+
16
+ matches = url_regex.match(url)
9
17
 
10
18
  raise 'Invalid url' if matches.nil?
11
19
 
12
20
  url = {
13
- :host => matches[1] + matches[4], :user => matches[2], :pass => matches[3],
14
- :org => matches[5], :project => matches[6], :env => matches[7]
21
+ :host => matches[1] + matches[4], :path => "/#{matches[5]}/config",
22
+ :user => matches[2], :pass => matches[3]
15
23
  }
16
24
  end
17
25
 
26
+ raise 'Invalid url' if !url.is_a?(Hash)
27
+
18
28
  client = Confy::Client.new({
19
29
  :username => url[:user], :password => url[:pass]
20
30
  }, { :base => url[:host] })
21
31
 
22
- client.config(url[:org], url[:project], url[:env]).retrieve().body
32
+ body = client.instance_variable_get(:@http_client).get(url[:path]).body
33
+
34
+ return body if body.is_a?(Hash)
35
+
36
+ decryptPass = ENV['CONFY_DECRYPT_PASS']
37
+
38
+ raise 'Invalid credential document' if !body.is_a?(String)
39
+ raise 'No decryption password found. Fill env var CONFY_DECRYPT_PASS' if decryptPass.nil?
40
+
41
+ # Strip quotes
42
+ body = body[1..-2] if body[0] == '"' and body[-1] == '"'
43
+
44
+ cipher = OpenSSL::Cipher::Cipher.new('aes-256-cbc')
45
+ cipher.decrypt
46
+ cipher.iv = Base64.decode64(body[0..23])
47
+ cipher.key = Digest::MD5.hexdigest(decryptPass)
48
+
49
+ decrypted = cipher.update(Base64.decode64(body[24..-1])) + cipher.final
50
+
51
+ begin
52
+ body = JSON.parse(decrypted)
53
+ rescue JSON::ParserError
54
+ raise 'Decryption password is wrong'
55
+ end
23
56
  end
24
57
 
25
58
  def self.env(url = {})
@@ -46,7 +46,7 @@ module Confy
46
46
 
47
47
  # Basic Authorization with username and password
48
48
  def http_password(env)
49
- code = Base64.encode64 "#{@auth[:username]}:#{@auth[:password]}"
49
+ code = Base64.strict_encode64 "#{@auth[:username]}:#{@auth[:password]}"
50
50
 
51
51
  env[:request_headers]["Authorization"] = "Basic #{code}"
52
52
 
@@ -27,7 +27,7 @@ module Confy
27
27
  end
28
28
 
29
29
  # If JSON, a particular field is taken and used
30
- if type.include?("json") and body.is_a?(Hash)
30
+ if type and type.include?("json") and body.is_a?(Hash)
31
31
  if body.has_key?("message")
32
32
  message = body["message"]
33
33
  else
@@ -10,8 +10,12 @@ module Confy
10
10
  body = response.body
11
11
 
12
12
  # Response body is in JSON
13
- if type.include?("json")
14
- body = JSON.parse body
13
+ if type and type.include?("json")
14
+ begin
15
+ body = JSON.parse body
16
+ rescue JSON::ParserError
17
+ return body
18
+ end
15
19
  end
16
20
 
17
21
  return body
@@ -0,0 +1,3 @@
1
+ module Confy
2
+ VERSION = "2.0.0"
3
+ end
@@ -1,5 +1,6 @@
1
1
  require "rubygems"
2
2
 
3
+ require "confy/version"
3
4
  require "confy/client"
4
5
  require "confy/config"
5
6
  require "confy/error"
metadata CHANGED
@@ -1,41 +1,53 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: confyio
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.3.0
4
+ version: 2.0.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Pavan Kumar Sunkara
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-05-18 00:00:00.000000000 Z
11
+ date: 2015-08-23 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: faraday
15
15
  requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
- - - ">="
17
+ - - ~>
18
+ - !ruby/object:Gem::Version
19
+ version: '0.9'
20
+ - - '>='
18
21
  - !ruby/object:Gem::Version
19
22
  version: 0.9.0
20
23
  type: :runtime
21
24
  prerelease: false
22
25
  version_requirements: !ruby/object:Gem::Requirement
23
26
  requirements:
24
- - - ">="
27
+ - - ~>
28
+ - !ruby/object:Gem::Version
29
+ version: '0.9'
30
+ - - '>='
25
31
  - !ruby/object:Gem::Version
26
32
  version: 0.9.0
27
33
  - !ruby/object:Gem::Dependency
28
34
  name: json
29
35
  requirement: !ruby/object:Gem::Requirement
30
36
  requirements:
31
- - - ">="
37
+ - - ~>
38
+ - !ruby/object:Gem::Version
39
+ version: '1.7'
40
+ - - '>='
32
41
  - !ruby/object:Gem::Version
33
42
  version: 1.7.7
34
43
  type: :runtime
35
44
  prerelease: false
36
45
  version_requirements: !ruby/object:Gem::Requirement
37
46
  requirements:
38
- - - ">="
47
+ - - ~>
48
+ - !ruby/object:Gem::Version
49
+ version: '1.7'
50
+ - - '>='
39
51
  - !ruby/object:Gem::Version
40
52
  version: 1.7.7
41
53
  description: Official Confy API library client for ruby
@@ -44,24 +56,25 @@ executables: []
44
56
  extensions: []
45
57
  extra_rdoc_files: []
46
58
  files:
47
- - lib/confy/http_client/response_handler.rb
48
- - lib/confy/http_client/request_handler.rb
49
- - lib/confy/http_client/response.rb
50
- - lib/confy/http_client/error_handler.rb
51
- - lib/confy/http_client/auth_handler.rb
52
59
  - lib/confy/api/access.rb
53
- - lib/confy/api/envs.rb
54
- - lib/confy/api/teams.rb
55
60
  - lib/confy/api/config.rb
56
- - lib/confy/api/projects.rb
61
+ - lib/confy/api/envs.rb
57
62
  - lib/confy/api/members.rb
58
63
  - lib/confy/api/orgs.rb
64
+ - lib/confy/api/projects.rb
65
+ - lib/confy/api/teams.rb
59
66
  - lib/confy/api/user.rb
60
- - lib/confy/http_client.rb
61
67
  - lib/confy/client.rb
62
- - lib/confy/error/client_error.rb
63
68
  - lib/confy/config.rb
64
69
  - lib/confy/error.rb
70
+ - lib/confy/error/client_error.rb
71
+ - lib/confy/http_client.rb
72
+ - lib/confy/http_client/auth_handler.rb
73
+ - lib/confy/http_client/error_handler.rb
74
+ - lib/confy/http_client/request_handler.rb
75
+ - lib/confy/http_client/response.rb
76
+ - lib/confy/http_client/response_handler.rb
77
+ - lib/confy/version.rb
65
78
  - lib/confyio.rb
66
79
  homepage: https://confy.io
67
80
  licenses:
@@ -73,18 +86,19 @@ require_paths:
73
86
  - lib
74
87
  required_ruby_version: !ruby/object:Gem::Requirement
75
88
  requirements:
76
- - - ">="
89
+ - - '>='
77
90
  - !ruby/object:Gem::Version
78
91
  version: '0'
79
92
  required_rubygems_version: !ruby/object:Gem::Requirement
80
93
  requirements:
81
- - - ">="
94
+ - - '>='
82
95
  - !ruby/object:Gem::Version
83
96
  version: '0'
84
97
  requirements: []
85
98
  rubyforge_project:
86
- rubygems_version: 2.1.11
99
+ rubygems_version: 2.4.5
87
100
  signing_key:
88
101
  specification_version: 4
89
102
  summary: Official Confy API library client for ruby
90
103
  test_files: []
104
+ has_rdoc: