seiso-connector 0.1.2 → 0.1.3

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,15 @@
1
1
  ---
2
- SHA1:
3
- metadata.gz: 2207917a82352c542779238c44ccc6198af2f8b1
4
- data.tar.gz: f856185df1fa582f846df8e7e5223cee1c9c7d33
2
+ !binary "U0hBMQ==":
3
+ metadata.gz: !binary |-
4
+ OTM0N2JjZDM5Zjk4MGRkZjIzMjI5MWI5ZjM4YWFlZDA3ZDhmN2RiOA==
5
+ data.tar.gz: !binary |-
6
+ MjU4YzBlYzkyYjYxYjc4YWJhNmU1MDZlNDA1MDE4ODgwZmMyNzExYw==
5
7
  SHA512:
6
- metadata.gz: b5c6801df649b5eace7f24997c9b5c8353c799d3583de34071200e1e7ab3cb473ed9ab060fd0228720c4b23e54af268213f6593b0ab0a21f3c1ac126b103839d
7
- data.tar.gz: a907382f7eb7c9e08105c17d0e016417424f38af719e5f1879bc8c156d8048d33b27e11c4d05c60610ae39f1b60abe6d092253bf8aa79994ae4dcc571447dbde
8
+ metadata.gz: !binary |-
9
+ MzA0ZWFjMDM0ZTM1NzQ5M2MyZmVmYzFmZjA1OTA2NWY1MmMwNTFhNjJjYWJl
10
+ YzY1MWUzYjFiZTBiOTU3YWYzMTRmNzFjZDllYTc3MTQ1YWJjMGFhOTRlYjBi
11
+ YTMzYjdiNWNlYmQxY2E1M2FjNWQ1Y2FiMjk4ZjYyYzdiNzdjMjE=
12
+ data.tar.gz: !binary |-
13
+ ZTUzYWQ0Mjg0ODI2NmYxZDhhMTg0N2Y3MzRlYTM0MGJlOGNkMDYzMDczNjA3
14
+ MWRkMzgzOGMzNTJiZjJjNDdjNDY2MGRjYzc0OTk3OGVmOTlkNzBkMWQwMTAw
15
+ Y2ZmYjgxNmQzOTdjZjdlMzA3NTlmZmZiNTdkYzQwY2ZmNzhiNzc=
data/README.md CHANGED
@@ -6,6 +6,8 @@
6
6
 
7
7
  Seiso connector for Ruby clients.
8
8
 
9
+ Note that this gem is a bit of a mess right now. We're moving toward using a more generic REST connector (standard verbs, identify resources with URIs, etc.) instead of having method like `getServices()`, `getServiceInstance(key)`, etc. So please pay attention to deprecation notices.
10
+
9
11
  ## Installation
10
12
 
11
13
  Add this line to your application's Gemfile:
@@ -33,3 +35,9 @@ TODO: Write usage instructions here
33
35
  3. Commit your changes (`git commit -am 'Add some feature'`)
34
36
  4. Push to the branch (`git push origin my-new-feature`)
35
37
  5. Create a new Pull Request
38
+
39
+ ## Development
40
+
41
+ To build and install the gem locally:
42
+
43
+ $ rake install
@@ -2,6 +2,7 @@ require 'json'
2
2
  require 'net/http'
3
3
  require_relative 'request_failed_error'
4
4
 
5
+ # DEPRECATED
5
6
  module Seiso
6
7
  class Connector
7
8
  class ConnectorV1
@@ -1,6 +1,7 @@
1
1
  require 'net/http'
2
2
  require_relative 'request_failed_error'
3
3
 
4
+ # DEPRECATED
4
5
  module Seiso
5
6
  class Connector
6
7
  class ConnectorV2
@@ -0,0 +1,100 @@
1
+ require "json"
2
+ require "net/http"
3
+ require "openssl"
4
+
5
+ module Seiso
6
+ class Connector
7
+
8
+ # Author:: Willie Wheeler (mailto:wwheeler@expedia.com)
9
+ # Copyright:: Copyright (c) 2014-2015 Expedia, Inc.
10
+ # License:: Apache 2.0
11
+ class RestConnector
12
+ HN_ACCEPT = "Accept"
13
+ HN_CONTENT_TYPE = "Content-Type"
14
+
15
+ def initialize(host, port, use_ssl, ignore_cert, username, password, media_type)
16
+ @host = host
17
+ @port = port
18
+ @use_ssl = use_ssl
19
+ @ignore_cert = ignore_cert
20
+ @username = username
21
+ @password = password
22
+ @media_type = media_type
23
+
24
+ # FIXME Not secure
25
+ @verify_mode = OpenSSL::SSL::VERIFY_NONE if @use_ssl
26
+ end
27
+
28
+ def get(uri)
29
+ request = Net::HTTP::Get.new uri.request_uri
30
+ request[HN_ACCEPT] = @media_type
31
+ request.basic_auth(@username, @password)
32
+ do_request(http, request)
33
+ end
34
+
35
+ def post(uri, resource)
36
+ request = Net::HTTP::Post.new uri.request_uri
37
+ request[HN_CONTENT_TYPE] = @media_type
38
+ request.basic_auth(@username, @password)
39
+ request.body = resource.to_json
40
+ do_request(http, request)
41
+ end
42
+
43
+ # Puts all resources using a keepalive connection
44
+ def put_all(uri_resource_pairs)
45
+ Net::HTTP.start(
46
+ @host,
47
+ @port,
48
+ :use_ssl => @use_ssl,
49
+ :verify_mode => @verify_mode) do |http|
50
+
51
+ uri_resource_pairs.each do |pair|
52
+ pair_uri = pair['uri']
53
+ pair_resource = pair['resource']
54
+ request = Net::HTTP::Put.new pair_uri.request_uri
55
+ request[HN_CONTENT_TYPE] = @media_type
56
+ request.basic_auth(@username, @password)
57
+ request.body = pair_resource.to_json
58
+ do_request(http, request)
59
+ end
60
+ end
61
+ end
62
+
63
+ def put(uri, resource)
64
+ request = Net::HTTP::Put.new uri.request_uri
65
+ request[HN_CONTENT_TYPE] = @media_type
66
+ request.basic_auth(@username, @password)
67
+ request.body = resource.to_json
68
+ do_request(http, request)
69
+ end
70
+
71
+ def delete(uri)
72
+ puts "DELETE #{uri}"
73
+ request = Net::HTTP::Delete.new uri.request_uri
74
+ request.basic_auth(@username, @password)
75
+ do_request(http, request)
76
+ end
77
+
78
+ private
79
+
80
+ def http
81
+ # Not sure if I can reuse this, so for now I'm just creating a new one every time.
82
+ http = Net::HTTP.new(@host, @port)
83
+ http.use_ssl = @use_ssl
84
+ http.verify_mode = @verify_mode
85
+ http
86
+ end
87
+
88
+ def do_request(http, request)
89
+ response = http.request request
90
+
91
+ if response.code.start_with?("4") || response.code.start_with?("5")
92
+ details = "(#{JSON.parse response.body})"
93
+ end
94
+ puts "#{request.method} #{request.path} => #{response.code} #{response.message} #{details}"
95
+ response
96
+ end
97
+
98
+ end # class RestConnector
99
+ end # class Connector
100
+ end # module Seiso
@@ -0,0 +1,60 @@
1
+ require "uri"
2
+
3
+ module Seiso
4
+ class Connector
5
+
6
+ # Seiso API v1 URI factory.
7
+ #
8
+ # URI templating (embodied here) is a temporary strategy for obtaining URIs. The plan is
9
+ # to adopt something like a Traverson-style strategy.
10
+ #
11
+ # Author:: Willie Wheeler (mailto:wwheeler@expedia.com)
12
+ # Copyright:: Copyright (c) 2014-2015 Expedia, Inc.
13
+ # License:: Apache 2.0
14
+ class UriFactoryV1
15
+
16
+ def initialize(base_uri)
17
+ @base_uri = base_uri
18
+ end
19
+
20
+ def nodes_uri(batch)
21
+ if batch
22
+ uri "/nodes?mode=batch"
23
+ else
24
+ uri "/nodes"
25
+ end
26
+ end
27
+
28
+ def node_uri(name)
29
+ uri "/nodes/#{name}"
30
+ end
31
+
32
+ def node_ip_address_uri(node_name, ip_address)
33
+ uri "/nodes/#{node_name}/ip-addresses/#{ip_address}"
34
+ end
35
+
36
+ def services_uri(batch)
37
+ if batch
38
+ uri "/services?mode=batch"
39
+ else
40
+ uri "/services"
41
+ end
42
+ end
43
+
44
+ def service_instances_uri(batch)
45
+ if batch
46
+ uri "/service-instances?mode=batch"
47
+ else
48
+ uri "/service-instances"
49
+ end
50
+ end
51
+
52
+ private
53
+
54
+ def uri(path)
55
+ URI.parse "#{@base_uri}#{path}"
56
+ end
57
+
58
+ end # class UriFactoryV1
59
+ end # class Connector
60
+ end # module Seiso
@@ -0,0 +1,36 @@
1
+ require "uri"
2
+
3
+ module Seiso
4
+ class Connector
5
+
6
+ # Seiso API v2 URI factory.
7
+ #
8
+ # URI templating (embodied here) is a temporary strategy for obtaining URIs. The plan is
9
+ # to adopt something like a Traverson-style strategy.
10
+ #
11
+ # Author:: Willie Wheeler (mailto:wwheeler@expedia.com)
12
+ # Copyright:: Copyright (c) 2014-2015 Expedia, Inc.
13
+ # License:: Apache 2.0
14
+ class UriFactoryV2
15
+
16
+ def initialize(base_uri)
17
+ @base_uri = base_uri
18
+ end
19
+
20
+ def doc_links_uri(service_key)
21
+ uri "/services/#{service_key}/doc-links"
22
+ end
23
+
24
+ def find_seyren_check_uri(seyren_base_url, seyren_id)
25
+ uri "/seyren-checks/search/find-by-base-url-and-id?url=#{seyren_base_url}&id=#{seyren_id}"
26
+ end
27
+
28
+ private
29
+
30
+ def uri(path)
31
+ URI.parse "#{@base_uri}#{path}"
32
+ end
33
+
34
+ end # class UriFactoryV2
35
+ end # class Connector
36
+ end # module Seiso
@@ -3,7 +3,11 @@ require "openssl"
3
3
  require "uri"
4
4
  require_relative "connector/connector_v1"
5
5
  require_relative "connector/connector_v2"
6
+ require_relative "connector/rest_connector"
7
+ require_relative "connector/uri_factory_v1"
8
+ require_relative "connector/uri_factory_v2"
6
9
 
10
+ # DEPRECATED
7
11
  # Seiso namespace module
8
12
  module Seiso
9
13
 
@@ -24,8 +28,8 @@ module Seiso
24
28
  def initialize(settings)
25
29
  host = settings['host']
26
30
  port = settings['port']
27
- use_ssl = settings['use_ssl'] | false
28
- ignore_cert = settings['ignore_cert'] | false
31
+ use_ssl = settings['use_ssl'] || false
32
+ ignore_cert = settings['ignore_cert'] || false
29
33
  username = settings['username']
30
34
  password = settings['password']
31
35
 
@@ -4,7 +4,7 @@ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
4
 
5
5
  Gem::Specification.new do |spec|
6
6
  spec.name = "seiso-connector"
7
- spec.version = "0.1.2"
7
+ spec.version = "0.1.3"
8
8
  spec.authors = ["Willie Wheeler"]
9
9
  spec.email = ["wwheeler@expedia.com"]
10
10
  spec.summary = "Connector to make it easier for Ruby clients to talk to the Seiso REST API."
metadata CHANGED
@@ -1,55 +1,55 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: seiso-connector
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.2
4
+ version: 0.1.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Willie Wheeler
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-03-12 00:00:00.000000000 Z
11
+ date: 2015-05-20 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
15
15
  requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
- - - "~>"
17
+ - - ~>
18
18
  - !ruby/object:Gem::Version
19
19
  version: '1.7'
20
20
  type: :development
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
- - - "~>"
24
+ - - ~>
25
25
  - !ruby/object:Gem::Version
26
26
  version: '1.7'
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: rake
29
29
  requirement: !ruby/object:Gem::Requirement
30
30
  requirements:
31
- - - "~>"
31
+ - - ~>
32
32
  - !ruby/object:Gem::Version
33
33
  version: '10.0'
34
34
  type: :development
35
35
  prerelease: false
36
36
  version_requirements: !ruby/object:Gem::Requirement
37
37
  requirements:
38
- - - "~>"
38
+ - - ~>
39
39
  - !ruby/object:Gem::Version
40
40
  version: '10.0'
41
41
  - !ruby/object:Gem::Dependency
42
42
  name: json
43
43
  requirement: !ruby/object:Gem::Requirement
44
44
  requirements:
45
- - - "~>"
45
+ - - ~>
46
46
  - !ruby/object:Gem::Version
47
47
  version: '1.7'
48
48
  type: :runtime
49
49
  prerelease: false
50
50
  version_requirements: !ruby/object:Gem::Requirement
51
51
  requirements:
52
- - - "~>"
52
+ - - ~>
53
53
  - !ruby/object:Gem::Version
54
54
  version: '1.7'
55
55
  description: Very basic at this point. Plan to support pagination, sorting, searching
@@ -60,8 +60,8 @@ executables: []
60
60
  extensions: []
61
61
  extra_rdoc_files: []
62
62
  files:
63
- - ".gitignore"
64
- - ".travis.yml"
63
+ - .gitignore
64
+ - .travis.yml
65
65
  - CHANGELOG.md
66
66
  - Gemfile
67
67
  - LICENSE.txt
@@ -71,6 +71,9 @@ files:
71
71
  - lib/seiso/connector/connector_v1.rb
72
72
  - lib/seiso/connector/connector_v2.rb
73
73
  - lib/seiso/connector/request_failed_error.rb
74
+ - lib/seiso/connector/rest_connector.rb
75
+ - lib/seiso/connector/uri_factory_v1.rb
76
+ - lib/seiso/connector/uri_factory_v2.rb
74
77
  - seiso-connector.gemspec
75
78
  - test/test_connector.rb
76
79
  - test/test_connector_v1.rb
@@ -85,17 +88,17 @@ require_paths:
85
88
  - lib
86
89
  required_ruby_version: !ruby/object:Gem::Requirement
87
90
  requirements:
88
- - - ">="
91
+ - - ! '>='
89
92
  - !ruby/object:Gem::Version
90
93
  version: '0'
91
94
  required_rubygems_version: !ruby/object:Gem::Requirement
92
95
  requirements:
93
- - - ">="
96
+ - - ! '>='
94
97
  - !ruby/object:Gem::Version
95
98
  version: '0'
96
99
  requirements: []
97
100
  rubyforge_project:
98
- rubygems_version: 2.2.2
101
+ rubygems_version: 2.4.6
99
102
  signing_key:
100
103
  specification_version: 4
101
104
  summary: Connector to make it easier for Ruby clients to talk to the Seiso REST API.