cogitate 0.0.1 → 0.0.2

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.
Files changed (34) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +69 -15
  3. data/lib/cogitate.rb +18 -2
  4. data/lib/cogitate/README.md +8 -0
  5. data/lib/cogitate/client.rb +97 -0
  6. data/lib/cogitate/client/agent_builder.rb +86 -0
  7. data/lib/cogitate/client/data_to_object_coercer.rb +38 -0
  8. data/lib/cogitate/client/exceptions.rb +10 -0
  9. data/lib/cogitate/client/identifier_builder.rb +26 -0
  10. data/lib/cogitate/client/request.rb +56 -0
  11. data/lib/cogitate/client/response_parsers.rb +19 -0
  12. data/lib/cogitate/client/response_parsers/agents_with_detailed_identifiers_extractor.rb +15 -0
  13. data/lib/cogitate/client/response_parsers/agents_without_group_membership_extractor.rb +23 -0
  14. data/lib/cogitate/client/response_parsers/basic_extractor.rb +14 -0
  15. data/lib/cogitate/client/response_parsers/email_extractor.rb +17 -0
  16. data/lib/cogitate/client/retrieve_agent_from_ticket.rb +43 -0
  17. data/lib/cogitate/client/ticket_to_token_coercer.rb +35 -0
  18. data/lib/cogitate/client/token_to_object_coercer.rb +38 -0
  19. data/lib/cogitate/configuration.rb +99 -0
  20. data/lib/cogitate/exceptions.rb +25 -0
  21. data/lib/cogitate/generators/install_generator.rb +10 -0
  22. data/lib/cogitate/generators/templates/cogitate_initializer.rb.erb +17 -0
  23. data/lib/cogitate/interfaces.rb +40 -0
  24. data/lib/cogitate/models.rb +6 -0
  25. data/lib/cogitate/models/agent.rb +143 -0
  26. data/lib/cogitate/models/agent/serializer.rb +75 -0
  27. data/lib/cogitate/models/agent/with_token.rb +29 -0
  28. data/lib/cogitate/models/identifier.rb +114 -0
  29. data/lib/cogitate/models/identifiers.rb +7 -0
  30. data/lib/cogitate/models/identifiers/with_attribute_hash.rb +44 -0
  31. data/lib/cogitate/railtie.rb +8 -0
  32. data/lib/cogitate/services/identifiers_decoder.rb +61 -0
  33. data/lib/cogitate/services/tokenizer.rb +80 -0
  34. metadata +105 -5
@@ -0,0 +1,80 @@
1
+ require 'figaro'
2
+ require 'jwt'
3
+
4
+ module Cogitate
5
+ module Services
6
+ # Responsible for decoding a token and encoding a token.
7
+ #
8
+ # @note This is a slight deviation from some of the class architecture in that there are two primary functions .from_token and
9
+ # .to_token. There is an underlying parameter object (i.e. password, issuer claim, and encryption type) that can be teased apart
10
+ # and thus create 1 data structure and 2 isolated functions instead of the bundled 1 object.
11
+ # @see https://github.com/jwt/ruby-jwt
12
+ class Tokenizer
13
+ # @api public
14
+ #
15
+ # Responsible for decoding a signed and encoded token and returning the `:data` portion of the JWT (JSON Web Token).
16
+ #
17
+ # @param token [String] An encoded token (as encoded via .to_token)
18
+ # @return the :data from the given token
19
+ # @see Cogitate::Services::Tokenizer.to_token
20
+ def self.from_token(token:, **keywords)
21
+ new(**keywords).from_token(token: token)
22
+ end
23
+
24
+ # @api public
25
+ #
26
+ # Responsible for encoding and signing a token who's `:data` payload is the input data.
27
+ #
28
+ # @param data [#as_json] An object that can be converted to a Hash as per #as_json
29
+ # @return [String] an encoded and signed token
30
+ # @see Cogitate::Services::Tokenizer.from_token
31
+ def self.to_token(data:, **keywords)
32
+ new(**keywords).to_token(data: data)
33
+ end
34
+
35
+ def initialize(configuration: default_configuration)
36
+ self.configuration = configuration
37
+ end
38
+
39
+ def to_token(data:)
40
+ JWT.encode({ data: data.as_json, iss: issuer_claim }, coerced_password, encryption_type)
41
+ end
42
+
43
+ def from_token(token:)
44
+ JWT.decode(token, coerced_password, false, 'iss' => issuer_claim, verify_iss: true).first.fetch('data')
45
+ end
46
+
47
+ private
48
+
49
+ attr_accessor :configuration
50
+
51
+ # I need to coerce the password into the correct format.
52
+ def coerced_password
53
+ case encryption_type.to_s
54
+ when /\ARS\d/i
55
+ OpenSSL::PKey::RSA.new(password)
56
+ else
57
+ encryption_type
58
+ end
59
+ end
60
+
61
+ def default_configuration
62
+ require 'cogitate'
63
+ Cogitate.configuration
64
+ end
65
+
66
+ # @note In the case of a Cogitate client this should be a public key; In the case of the Cogitate server this should be a private key.
67
+ def password
68
+ configuration.tokenizer_password
69
+ end
70
+
71
+ def encryption_type
72
+ configuration.tokenizer_encryption_type
73
+ end
74
+
75
+ def issuer_claim
76
+ configuration.tokenizer_issuer_claim
77
+ end
78
+ end
79
+ end
80
+ end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: cogitate
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.0.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jeremy Friesen
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2015-08-10 00:00:00.000000000 Z
11
+ date: 2015-09-22 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -24,6 +24,76 @@ dependencies:
24
24
  - - "~>"
25
25
  - !ruby/object:Gem::Version
26
26
  version: '1.8'
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.2'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '3.2'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rspec-its
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '1.2'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '1.2'
55
+ - !ruby/object:Gem::Dependency
56
+ name: contracts
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '0.1'
62
+ type: :runtime
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '0.1'
69
+ - !ruby/object:Gem::Dependency
70
+ name: jwt
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - "~>"
74
+ - !ruby/object:Gem::Version
75
+ version: '1.5'
76
+ type: :runtime
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - "~>"
81
+ - !ruby/object:Gem::Version
82
+ version: '1.5'
83
+ - !ruby/object:Gem::Dependency
84
+ name: rest-client
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - "~>"
88
+ - !ruby/object:Gem::Version
89
+ version: '1.8'
90
+ type: :runtime
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - "~>"
95
+ - !ruby/object:Gem::Version
96
+ version: '1.8'
27
97
  description: A client library for the Cogitate service.
28
98
  email:
29
99
  - jeremy.n.friesen@gmail.com
@@ -34,6 +104,36 @@ files:
34
104
  - LICENSE
35
105
  - README.md
36
106
  - lib/cogitate.rb
107
+ - lib/cogitate/README.md
108
+ - lib/cogitate/client.rb
109
+ - lib/cogitate/client/agent_builder.rb
110
+ - lib/cogitate/client/data_to_object_coercer.rb
111
+ - lib/cogitate/client/exceptions.rb
112
+ - lib/cogitate/client/identifier_builder.rb
113
+ - lib/cogitate/client/request.rb
114
+ - lib/cogitate/client/response_parsers.rb
115
+ - lib/cogitate/client/response_parsers/agents_with_detailed_identifiers_extractor.rb
116
+ - lib/cogitate/client/response_parsers/agents_without_group_membership_extractor.rb
117
+ - lib/cogitate/client/response_parsers/basic_extractor.rb
118
+ - lib/cogitate/client/response_parsers/email_extractor.rb
119
+ - lib/cogitate/client/retrieve_agent_from_ticket.rb
120
+ - lib/cogitate/client/ticket_to_token_coercer.rb
121
+ - lib/cogitate/client/token_to_object_coercer.rb
122
+ - lib/cogitate/configuration.rb
123
+ - lib/cogitate/exceptions.rb
124
+ - lib/cogitate/generators/install_generator.rb
125
+ - lib/cogitate/generators/templates/cogitate_initializer.rb.erb
126
+ - lib/cogitate/interfaces.rb
127
+ - lib/cogitate/models.rb
128
+ - lib/cogitate/models/agent.rb
129
+ - lib/cogitate/models/agent/serializer.rb
130
+ - lib/cogitate/models/agent/with_token.rb
131
+ - lib/cogitate/models/identifier.rb
132
+ - lib/cogitate/models/identifiers.rb
133
+ - lib/cogitate/models/identifiers/with_attribute_hash.rb
134
+ - lib/cogitate/railtie.rb
135
+ - lib/cogitate/services/identifiers_decoder.rb
136
+ - lib/cogitate/services/tokenizer.rb
37
137
  homepage: https://github.com/ndlib/cogitate
38
138
  licenses:
39
139
  - APACHE2
@@ -44,9 +144,9 @@ require_paths:
44
144
  - lib
45
145
  required_ruby_version: !ruby/object:Gem::Requirement
46
146
  requirements:
47
- - - ">="
147
+ - - "~>"
48
148
  - !ruby/object:Gem::Version
49
- version: '0'
149
+ version: 2.2.2
50
150
  required_rubygems_version: !ruby/object:Gem::Requirement
51
151
  requirements:
52
152
  - - ">="
@@ -54,7 +154,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
54
154
  version: '0'
55
155
  requirements: []
56
156
  rubyforge_project:
57
- rubygems_version: 2.4.7
157
+ rubygems_version: 2.4.5.1
58
158
  signing_key:
59
159
  specification_version: 4
60
160
  summary: A client library for the Cogitate service.