etcdv3 0.0.3

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,3 @@
1
+ class Etcd
2
+ VERSION = "0.0.3"
3
+ end
data/lib/etcdv3.rb ADDED
@@ -0,0 +1,98 @@
1
+
2
+ require 'grpc'
3
+ require 'uri'
4
+
5
+ require 'etcdv3/etcdrpc/rpc_services_pb'
6
+ require 'etcdv3/auth'
7
+ require 'etcdv3/kv'
8
+
9
+ class Etcd
10
+
11
+ def options
12
+ Marshal.load(Martial.dump(@options))
13
+ end
14
+
15
+ def uri
16
+ URI(@options[:url])
17
+ end
18
+
19
+ def scheme
20
+ uri.scheme
21
+ end
22
+
23
+ def port
24
+ uri.port
25
+ end
26
+
27
+ def hostname
28
+ uri.hostname
29
+ end
30
+
31
+ def user
32
+ @options[:user]
33
+ end
34
+
35
+ def password
36
+ @options[:password]
37
+ end
38
+
39
+ def token
40
+ @metadata[:token]
41
+ end
42
+
43
+ def credentials
44
+ @credentials
45
+ end
46
+
47
+ def initialize(options={})
48
+ @options = options
49
+ @credentials = resolve_credentials
50
+ @metadata = {}
51
+ unless user.nil?
52
+ @metadata[:token] = auth.generate_token(user, password)
53
+ end
54
+ end
55
+
56
+ def put(key, value)
57
+ kv.put(key, value, @metadata)
58
+ end
59
+
60
+ def range(key, range_end)
61
+ kv.range(key, range_end, @metadata)
62
+ end
63
+
64
+
65
+ def add_user(user, password)
66
+ auth.add_user(user, password, @metadata)
67
+ end
68
+
69
+ def delete_user(user)
70
+ auth.delete_user(user, @metadata)
71
+ end
72
+
73
+ def user_list
74
+ auth.user_list(@metadata)
75
+ end
76
+
77
+ private
78
+
79
+ def auth
80
+ Etcd::Auth.new(hostname, port, @credentials)
81
+ end
82
+
83
+ def kv
84
+ Etcd::KV.new(hostname, port, @credentials)
85
+ end
86
+
87
+ def resolve_credentials
88
+ case scheme
89
+ when "http"
90
+ :this_channel_is_insecure
91
+ when "https"
92
+ # Use default certs for now.
93
+ GRPC::Core::ChannelCredentials.new
94
+ else
95
+ raise "Unknown scheme: #{scheme}"
96
+ end
97
+ end
98
+ end
data/spec/etcd_spec.rb ADDED
@@ -0,0 +1,52 @@
1
+ require 'spec_helper'
2
+
3
+ describe Etcd do
4
+
5
+ context 'Insecure connection without Auth' do
6
+
7
+ let(:conn){ Etcd.new(
8
+ url: 'http://127.0.0.1:2379'
9
+ )}
10
+
11
+ describe '#initialize' do
12
+
13
+ it 'assigns scheme' do
14
+ expect(conn.scheme).to eq('http')
15
+ end
16
+
17
+ it 'assigns host' do
18
+ expect(conn.hostname).to eq('127.0.0.1')
19
+ end
20
+
21
+ it 'assigns port' do
22
+ expect(conn.port).to eq(2379)
23
+ end
24
+
25
+ it 'returns nil token' do
26
+ expect(conn.token).to eq(nil)
27
+ end
28
+
29
+ it 'assigns proper credentials' do
30
+ expect(conn.credentials).to eq(:this_channel_is_insecure)
31
+ end
32
+ end
33
+
34
+ describe "#put" do
35
+ it 'issues put request' do
36
+ expect(conn.put('test', 'test')).to be_an_instance_of(Etcdserverpb::PutResponse)
37
+ end
38
+ end
39
+
40
+ describe "#range" do
41
+ it 'returns protobuf' do
42
+ expect(conn.range('test', '')).to be_an_instance_of(Google::Protobuf::RepeatedField)
43
+ end
44
+
45
+ it 'returns correct result' do
46
+ expect(conn.range('test', '').first.key).to eq('test')
47
+ end
48
+ end
49
+
50
+ end
51
+
52
+ end
@@ -0,0 +1,38 @@
1
+ # require 'spec_helper'
2
+ # require 'securerandom'
3
+ #
4
+ # describe Etcd::Auth do
5
+ #
6
+ # context "User managment without Auth" do
7
+ #
8
+ # let(:stub){ Etcd::Auth.new("127.0.0.1", 2379, :this_channel_is_insecure)}
9
+ # let(:rando) { SecureRandom.hex(10) }
10
+ #
11
+ # describe "#add_user" do
12
+ # it 'adds user' do
13
+ # expect(stub.add_user(rando, 'test')).to be_an_instance_of(Etcdserverpb::AuthUserAddResponse)
14
+ # end
15
+ # end
16
+ #
17
+ # describe "#user_list" do
18
+ # it 'has correct data type' do
19
+ # expect(stub.user_list).to be_an_instance_of(Google::Protobuf::RepeatedField)
20
+ # end
21
+ #
22
+ # it 'contains user testy' do
23
+ # puts stub.user_list
24
+ # expect(stub.user_list).to eq(rando)
25
+ # end
26
+ # end
27
+ #
28
+ # describe "#delete_user" do
29
+ #
30
+ # it 'deletes user' do
31
+ # expect(stub.delete_user(rando)).to be_an_instance_of(Etcdserverpb::AuthUserDeleteResponse)
32
+ # end
33
+ #
34
+ # end
35
+ #
36
+ # end
37
+ #
38
+ # end
@@ -0,0 +1,14 @@
1
+ lib = File.expand_path('../lib', __FILE__)
2
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
3
+
4
+ require 'etcdv3'
5
+ RSpec.configure do |config|
6
+ config.expect_with :rspec do |expectations|
7
+ expectations.include_chain_clauses_in_custom_matcher_descriptions = true
8
+ end
9
+
10
+ config.mock_with :rspec do |mocks|
11
+ mocks.verify_partial_doubles = true
12
+ end
13
+ config.shared_context_metadata_behavior = :apply_to_host_groups
14
+ end
metadata ADDED
@@ -0,0 +1,98 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: etcdv3
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.3
5
+ platform: ruby
6
+ authors:
7
+ - Shaun Davis
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2017-03-30 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: grpc
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - '='
18
+ - !ruby/object:Gem::Version
19
+ version: 1.2.0
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - '='
25
+ - !ruby/object:Gem::Version
26
+ version: 1.2.0
27
+ - !ruby/object:Gem::Dependency
28
+ name: rspec
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - '='
32
+ - !ruby/object:Gem::Version
33
+ version: 3.5.4
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - '='
39
+ - !ruby/object:Gem::Version
40
+ version: 3.5.4
41
+ description: Etcd v3 Ruby Client
42
+ email: davissp14@gmail.com
43
+ executables: []
44
+ extensions: []
45
+ extra_rdoc_files: []
46
+ files:
47
+ - ".gitignore"
48
+ - ".rspec"
49
+ - ".ruby-version"
50
+ - Gemfile
51
+ - README.md
52
+ - etcdv3.gemspec
53
+ - lib/etcdv3.rb
54
+ - lib/etcdv3/auth.rb
55
+ - lib/etcdv3/etcdrpc/auth_pb.rb
56
+ - lib/etcdv3/etcdrpc/kv_pb.rb
57
+ - lib/etcdv3/etcdrpc/rpc_pb.rb
58
+ - lib/etcdv3/etcdrpc/rpc_services_pb.rb
59
+ - lib/etcdv3/kv.rb
60
+ - lib/etcdv3/protos/annotations.proto
61
+ - lib/etcdv3/protos/auth.proto
62
+ - lib/etcdv3/protos/descriptor.proto
63
+ - lib/etcdv3/protos/gogo.proto
64
+ - lib/etcdv3/protos/http.proto
65
+ - lib/etcdv3/protos/kv.proto
66
+ - lib/etcdv3/protos/rpc.proto
67
+ - lib/etcdv3/version.rb
68
+ - spec/etcd_spec.rb
69
+ - spec/etcdv3/auth_spec.rb
70
+ - spec/spec_helper.rb
71
+ homepage: https://github.com/davissp14/etcdv3-ruby
72
+ licenses:
73
+ - MIT
74
+ metadata: {}
75
+ post_install_message:
76
+ rdoc_options: []
77
+ require_paths:
78
+ - lib
79
+ required_ruby_version: !ruby/object:Gem::Requirement
80
+ requirements:
81
+ - - ">="
82
+ - !ruby/object:Gem::Version
83
+ version: '0'
84
+ required_rubygems_version: !ruby/object:Gem::Requirement
85
+ requirements:
86
+ - - ">="
87
+ - !ruby/object:Gem::Version
88
+ version: '0'
89
+ requirements: []
90
+ rubyforge_project:
91
+ rubygems_version: 2.6.11
92
+ signing_key:
93
+ specification_version: 4
94
+ summary: A Etcd client library for Version 3
95
+ test_files:
96
+ - spec/etcd_spec.rb
97
+ - spec/etcdv3/auth_spec.rb
98
+ - spec/spec_helper.rb