alcatraz-client 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 725aa0215082696d330926bbf9b4b07b1242723c
4
+ data.tar.gz: e31b724eeed37915f66d82d01607ec354af4af86
5
+ SHA512:
6
+ metadata.gz: 68db6e29f012441ba0ffc36b789fa34421e3986662ee0009a6c90e20d8390dfc1fe10c2194cc191d1ac2c11f70942f4d35c21897c27c8143a38cd878ec380c43
7
+ data.tar.gz: 88bfc8fdccb2df476bd42e1aa892d3eeae468ccea037442d117eded4ebe491c8efc51752932f33caa752a648fb21df4e2571439c9c75975753a81967df634e2e
data/.gitignore ADDED
@@ -0,0 +1,17 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ Gemfile.lock
7
+ InstalledFiles
8
+ _yardoc
9
+ coverage
10
+ doc/
11
+ lib/bundler/man
12
+ pkg
13
+ rdoc
14
+ spec/reports
15
+ test/tmp
16
+ test/version_tmp
17
+ tmp
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in alcatraz-client.gemspec
4
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2014 Brian McManus
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,110 @@
1
+ # Alcatraz::Client
2
+
3
+ A client library for the Alcatraz PCI-compliant data store.
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ gem 'alcatraz-client'
10
+
11
+ And then execute:
12
+
13
+ $ bundle
14
+
15
+ Or install it yourself as:
16
+
17
+ $ gem install alcatraz-client
18
+
19
+ ## Usage
20
+
21
+ You will need your Alcatraz API keys (both public and secret) to use alcatraz-client.
22
+
23
+ First, set up your connection.
24
+
25
+ conn = Alcatraz::Client::Connection.new(public_key: ENV['ALCATRAZ_PUBLIC_KEY'], secret_key: ENV['ALCATRAZ_SECRET_KEY'])
26
+
27
+ After that you can use any of the public API methods for Alcatraz.
28
+
29
+ ### Store credit card data
30
+
31
+ The first thing you'll want to do with Alcatraz is store credit card data securely. That's the whole game after all!
32
+
33
+ card = conn.store_card!(
34
+ name: 'Jane Doe',
35
+ number: '4111111111111111',
36
+ expiration_month: '5',
37
+ expiration_year: '2015',
38
+ cvv: '123',
39
+ postal_code: '94107',
40
+ country_code: 'US'
41
+ )
42
+ card.href # => '/cards/afbfe408-8e66-4e11-aecb-e21825512b16'
43
+ card.number # => '411111******1111'
44
+
45
+ The Alcatraz API does not technically require any sort of authentication to store data but in the case of this client,
46
+ we provide it. Only masked data will be returned from a call to store_card!.
47
+
48
+ If the card is created successfully it will automatically be authorized to your client.
49
+
50
+ ### Fetch credit card data
51
+
52
+ You can pull card data back out of Alcatraz. Depending on your client's level of access, this data may or may not be masked.
53
+
54
+ card = conn.get_card('afbfe408-8e66-4e11-aecb-e21825512b16')
55
+ # If your client had decryption access...
56
+ card.number # => '4111111111111111'
57
+ # otherwise...
58
+ card.number # => '411111******1111'
59
+
60
+ ### Store arbitrary secure data
61
+
62
+ Alcatraz also allows for the storage of arbitrary "secure" data such as social security numbers, passport numbers, etc.
63
+
64
+ The API to store arbitrary data is almost identical as storing credit card data.
65
+
66
+ data = conn.store_data!(
67
+ ssn: '123456789'
68
+ )
69
+ data.href # => '/secure_data/3a5ca937-7a08-434b-8648-4c34986bfb54'
70
+ data.ssn # => '*********'
71
+
72
+ You'll notice that for arbitrary data, Alcatraz does not do any special processing like it does with credit cards because
73
+ we do not know what you are sending in. For masked data, the values sent in are fully masked instead of partially masked.
74
+
75
+ ### Fetch secure data
76
+
77
+ Fetching secure data is the same as fetching card data. Again, depending on your access level, the data may or may not be masked.
78
+
79
+ data = conn.get_data('3a5ca937-7a08-434b-8648-4c34986bfb54')
80
+ # With decryption enabled...
81
+ data.ssn # => '123456789'
82
+ # otherwise...
83
+ data.ssn # => '*********'
84
+
85
+ ### Create additional API clients
86
+
87
+ Allows for creation of additional API clients for use with Alcatraz. Your authenticated client must have appropriate authority
88
+ to use this endpoint. The newly created client will only return its public key.
89
+
90
+ client = conn.create_client!(name: 'Some Name')
91
+ client.inspect # => { id: '3a5ca937-7a08-434b-8648-4c34986bfb54', name: 'Some Name', href: 'api_clients/3a5ca937-7a08-434b-8648-4c34986bfb54', public_key: '3a5ca937-7a08-434b-8648-4c34986bfb54'}
92
+
93
+ ### Authorize/Deauthorize data to clients
94
+
95
+ Allows you to control which of your clients have access to data using their API keys. Used to "claim" data that has been stored in Alcatraz previously.
96
+ If you store data using the API calls above you will automatically be authorized to it. This method is only to authorize other API clients to access the
97
+ data with their public/secret key pairs.
98
+
99
+ data = conn.get_data('3a5ca937-7a08-434b-8648-4c34986bfb54')
100
+ authorize_data_for_client!(data, 'some-other-client-public-key')
101
+ # Later, to revoke a client's authority to some data...
102
+ deauthorize_data_for_client!(data, 'some-other-client-public-key')
103
+
104
+ ## Contributing
105
+
106
+ 1. Fork it ( http://github.com/<my-github-username>/alcatraz-client/fork )
107
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
108
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
109
+ 4. Push to the branch (`git push origin my-new-feature`)
110
+ 5. Create new Pull Request
data/Rakefile ADDED
@@ -0,0 +1,9 @@
1
+ require "bundler/gem_tasks"
2
+
3
+ task :console do
4
+ require 'irb'
5
+ require 'irb/completion'
6
+ require 'alcatraz/client' # You know what to do.
7
+ ARGV.clear
8
+ IRB.start
9
+ end
@@ -0,0 +1,30 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'alcatraz/client/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = 'alcatraz-client'
8
+ spec.version = Alcatraz::Client::VERSION
9
+ spec.authors = ['Brian McManus']
10
+ spec.email = ['brian@checkmate.io']
11
+ spec.summary = %q{A client library for the Alcatraz PCI-compliant data store.}
12
+ spec.homepage = ''
13
+ spec.license = 'MIT'
14
+
15
+ spec.files = `git ls-files`.split($/)
16
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
17
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
18
+ spec.require_paths = ['lib']
19
+
20
+ spec.add_development_dependency 'bundler', '~> 1.5'
21
+ spec.add_development_dependency 'rake'
22
+ spec.add_development_dependency 'rspec'
23
+ spec.add_development_dependency 'webmock', '~> 1.15'
24
+ spec.add_development_dependency 'vcr', '~> 2.8.0'
25
+
26
+ spec.add_runtime_dependency 'hashie', '~> 2.1.1'
27
+ spec.add_runtime_dependency 'faraday', '~> 0.9.0'
28
+ spec.add_runtime_dependency 'faraday_middleware'
29
+ spec.add_runtime_dependency 'warden-hmac-authentication', '~> 0.6.4'
30
+ end
@@ -0,0 +1,15 @@
1
+ require 'faraday/request/hmac'
2
+ require 'alcatraz/client/version'
3
+ require 'alcatraz/client/configuration'
4
+ require 'alcatraz/client/connection'
5
+
6
+ module Alcatraz
7
+ module Client
8
+ extend Configuration
9
+ class << self
10
+ def new(options = {})
11
+ Alcatraz::Client::Connection.new(options)
12
+ end
13
+ end
14
+ end
15
+ end
@@ -0,0 +1,26 @@
1
+ module Alcatraz
2
+ module Client
3
+ module Configuration
4
+ VALID_OPTIONS = [ :public_key, :secret_key, :api_url ]
5
+ DEFAULT_API_URL = "https://alcatraz.checkmate.io"
6
+
7
+ attr_accessor *VALID_OPTIONS
8
+
9
+ def self.extended(base)
10
+ base.reset
11
+ end
12
+
13
+ def reset
14
+ self.api_url = DEFAULT_API_URL
15
+ end
16
+
17
+ def configure
18
+ yield self
19
+ end
20
+
21
+ def options
22
+ Hash[ * VALID_OPTIONS.map { |key| [key, send(key)] }.flatten ]
23
+ end
24
+ end
25
+ end
26
+ end
@@ -0,0 +1,103 @@
1
+ require 'faraday_middleware'
2
+
3
+ module Alcatraz
4
+ module Client
5
+ class Connection
6
+ attr_accessor *Configuration::VALID_OPTIONS
7
+
8
+ def initialize(options = {})
9
+ merged_options = ::Alcatraz::Client.options.merge(options)
10
+
11
+ Configuration::VALID_OPTIONS.each do |key|
12
+ public_send("#{key}=", merged_options[key])
13
+ end
14
+ end
15
+
16
+ def get_card(id)
17
+ parse_response_to_secure_object(get("/cards/#{id}"))
18
+ end
19
+
20
+ def store_card!(params)
21
+ card = parse_response_to_secure_object(post('/cards', params))
22
+ authorize_data_for_client!(card, public_key) if card && card.id
23
+ card
24
+ end
25
+
26
+ def get_data(id)
27
+ parse_response_to_secure_object(get("/secure_data/#{id}"))
28
+ end
29
+
30
+ def store_data!(params)
31
+ data = parse_response_to_secure_object(post('/secure_data', params))
32
+ authorize_data_for_client!(data, public_key) if data && data.id
33
+ data
34
+ end
35
+
36
+ def create_client!(name)
37
+ response = post('/api_clients', api_client: {name: name})
38
+ if response.success?
39
+ response.body.api_client
40
+ else
41
+ nil
42
+ end
43
+ end
44
+
45
+ def authorize_data_for_client!(data_or_id, client_or_public_key)
46
+ data_id = unwrap_to_id data_or_id
47
+ public_key = unwrap_to_key client_or_public_key
48
+ post("/secure_data/#{data_id}/authorizations", public_key: public_key).success?
49
+ end
50
+
51
+ def deauthorize_data_for_client!(data_or_id, client_or_public_key)
52
+ data_id = unwrap_to_id data_or_id
53
+ public_key = unwrap_to_key client_or_public_key
54
+ delete("/secure_data/#{data_id}/authorizations/#{public_key}")
55
+ end
56
+
57
+ private
58
+
59
+ def unwrap_to_id(object_or_id)
60
+ object_or_id = object_or_id.id unless object_or_id.kind_of?(String)
61
+ object_or_id
62
+ end
63
+
64
+ def unwrap_to_key(object_or_key)
65
+ object_or_key = object_or_key.public_key unless object_or_key.kind_of?(String)
66
+ object_or_key
67
+ end
68
+
69
+ def connection
70
+ Faraday.new(url: api_url) do |conn|
71
+ conn.request :json
72
+ conn.use Faraday::Request::Hmac, secret_key, nonce: (Time.now.to_f * 1e6).to_i.to_s, query_based: true, extra_auth_params: {public_key: public_key}
73
+ conn.use Faraday::Response::Mashify
74
+ conn.response :json, content_type: /\bjson$/
75
+ conn.adapter Faraday.default_adapter
76
+ end
77
+ end
78
+
79
+ def get(path, options = {})
80
+ connection.get(path, options)
81
+ end
82
+
83
+ def post(path, options = {})
84
+ connection.post(path, options)
85
+ end
86
+
87
+ def delete(path)
88
+ response = connection.delete(path)
89
+ response.success?
90
+ end
91
+
92
+ def parse_response_to_secure_object(response)
93
+ if response.body.respond_to? :card
94
+ response.body.card
95
+ elsif response.body.respond_to? :secure_datum
96
+ response.body.secure_datum
97
+ else
98
+ response.body
99
+ end
100
+ end
101
+ end
102
+ end
103
+ end
@@ -0,0 +1,5 @@
1
+ module Alcatraz
2
+ module Client
3
+ VERSION = "0.0.1"
4
+ end
5
+ end
metadata ADDED
@@ -0,0 +1,180 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: alcatraz-client
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Brian McManus
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2014-06-17 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '1.5'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.5'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rspec
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: webmock
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '1.15'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '1.15'
69
+ - !ruby/object:Gem::Dependency
70
+ name: vcr
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - "~>"
74
+ - !ruby/object:Gem::Version
75
+ version: 2.8.0
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - "~>"
81
+ - !ruby/object:Gem::Version
82
+ version: 2.8.0
83
+ - !ruby/object:Gem::Dependency
84
+ name: hashie
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - "~>"
88
+ - !ruby/object:Gem::Version
89
+ version: 2.1.1
90
+ type: :runtime
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - "~>"
95
+ - !ruby/object:Gem::Version
96
+ version: 2.1.1
97
+ - !ruby/object:Gem::Dependency
98
+ name: faraday
99
+ requirement: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - "~>"
102
+ - !ruby/object:Gem::Version
103
+ version: 0.9.0
104
+ type: :runtime
105
+ prerelease: false
106
+ version_requirements: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - "~>"
109
+ - !ruby/object:Gem::Version
110
+ version: 0.9.0
111
+ - !ruby/object:Gem::Dependency
112
+ name: faraday_middleware
113
+ requirement: !ruby/object:Gem::Requirement
114
+ requirements:
115
+ - - ">="
116
+ - !ruby/object:Gem::Version
117
+ version: '0'
118
+ type: :runtime
119
+ prerelease: false
120
+ version_requirements: !ruby/object:Gem::Requirement
121
+ requirements:
122
+ - - ">="
123
+ - !ruby/object:Gem::Version
124
+ version: '0'
125
+ - !ruby/object:Gem::Dependency
126
+ name: warden-hmac-authentication
127
+ requirement: !ruby/object:Gem::Requirement
128
+ requirements:
129
+ - - "~>"
130
+ - !ruby/object:Gem::Version
131
+ version: 0.6.4
132
+ type: :runtime
133
+ prerelease: false
134
+ version_requirements: !ruby/object:Gem::Requirement
135
+ requirements:
136
+ - - "~>"
137
+ - !ruby/object:Gem::Version
138
+ version: 0.6.4
139
+ description:
140
+ email:
141
+ - brian@checkmate.io
142
+ executables: []
143
+ extensions: []
144
+ extra_rdoc_files: []
145
+ files:
146
+ - ".gitignore"
147
+ - Gemfile
148
+ - LICENSE.txt
149
+ - README.md
150
+ - Rakefile
151
+ - alcatraz-client.gemspec
152
+ - lib/alcatraz/client.rb
153
+ - lib/alcatraz/client/configuration.rb
154
+ - lib/alcatraz/client/connection.rb
155
+ - lib/alcatraz/client/version.rb
156
+ homepage: ''
157
+ licenses:
158
+ - MIT
159
+ metadata: {}
160
+ post_install_message:
161
+ rdoc_options: []
162
+ require_paths:
163
+ - lib
164
+ required_ruby_version: !ruby/object:Gem::Requirement
165
+ requirements:
166
+ - - ">="
167
+ - !ruby/object:Gem::Version
168
+ version: '0'
169
+ required_rubygems_version: !ruby/object:Gem::Requirement
170
+ requirements:
171
+ - - ">="
172
+ - !ruby/object:Gem::Version
173
+ version: '0'
174
+ requirements: []
175
+ rubyforge_project:
176
+ rubygems_version: 2.2.2
177
+ signing_key:
178
+ specification_version: 4
179
+ summary: A client library for the Alcatraz PCI-compliant data store.
180
+ test_files: []