scim-kit 0.2.1 → 0.2.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.
- checksums.yaml +4 -4
- data/.gitlab-ci.yml +11 -0
- data/README.md +1 -1
- data/bin/console +1 -1
- data/bin/setup +1 -1
- data/lib/scim/kit/dynamic_attributes.rb +1 -1
- data/lib/scim/kit/templatable.rb +1 -1
- data/lib/scim/kit/v2/attributable.rb +50 -0
- data/lib/scim/kit/v2/attribute.rb +31 -0
- data/lib/scim/kit/v2/attribute_type.rb +23 -6
- data/lib/scim/kit/v2/meta.rb +2 -1
- data/lib/scim/kit/v2/resource.rb +25 -0
- data/lib/scim/kit/v2/schema.rb +5 -1
- data/lib/scim/kit/v2/templates/attribute.json.jbuilder +12 -0
- data/lib/scim/kit/v2/templates/meta.json.jbuilder +1 -1
- data/lib/scim/kit/v2/templates/resource.json.jbuilder +22 -0
- data/lib/scim/kit/version.rb +1 -1
- data/lib/scim/kit.rb +4 -0
- metadata +8 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 7c3b973655a3edf5be7d0be213b847b21b7d92a8262a20f9f832f2a10be7097b
|
4
|
+
data.tar.gz: d9da0db47fd0e17964961cee7cc22d8a013d66466c2f47b8fd6dd913c2b0a233
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: c846c9afa7135dace4e4f88659a6a5d6a77c3ca981ca1261087eebfd4315c1517558e05560f4ffa1c5ccdf169feede591f213e8ddde69e8cca6f4e4a61668b49
|
7
|
+
data.tar.gz: e8ac0b13d604ab5ee0546a116092b409777b8dbc23d16892798d16e0aba232752c638ccb91b99f36c256a30c6ee89beb56a61bf1d910fa45908a991d7e70bf0c
|
data/.gitlab-ci.yml
ADDED
data/README.md
CHANGED
@@ -83,7 +83,7 @@ To install this gem onto your local machine, run `bundle exec rake install`. To
|
|
83
83
|
|
84
84
|
## Contributing
|
85
85
|
|
86
|
-
Bug reports and pull requests are welcome on GitHub at https://github.com/
|
86
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/mokha/scim-kit.
|
87
87
|
|
88
88
|
## License
|
89
89
|
|
data/bin/console
CHANGED
data/bin/setup
CHANGED
data/lib/scim/kit/templatable.rb
CHANGED
@@ -0,0 +1,50 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Scim
|
4
|
+
module Kit
|
5
|
+
module V2
|
6
|
+
# Represents a dynamic attribute that corresponds to a SCIM type
|
7
|
+
module Attributable
|
8
|
+
attr_reader :dynamic_attributes
|
9
|
+
|
10
|
+
def define_attributes_for(types)
|
11
|
+
@dynamic_attributes = {}.with_indifferent_access
|
12
|
+
types.each do |type|
|
13
|
+
dynamic_attributes[type.name] = Attribute.new(type: type)
|
14
|
+
extend(create_module_for(type))
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
private
|
19
|
+
|
20
|
+
def attribute_for(name)
|
21
|
+
dynamic_attributes[name]
|
22
|
+
end
|
23
|
+
|
24
|
+
def read_attribute(name)
|
25
|
+
attribute = attribute_for(name)
|
26
|
+
return attribute._value if attribute.type.multi_valued
|
27
|
+
|
28
|
+
attribute.type.complex? ? attribute : attribute._value
|
29
|
+
end
|
30
|
+
|
31
|
+
def write_attribute(name, value)
|
32
|
+
attribute_for(name)._value = value
|
33
|
+
end
|
34
|
+
|
35
|
+
def create_module_for(type)
|
36
|
+
name = type.name.to_sym
|
37
|
+
Module.new do
|
38
|
+
define_method(name) do |*_args|
|
39
|
+
read_attribute(name)
|
40
|
+
end
|
41
|
+
|
42
|
+
define_method("#{name}=") do |*args|
|
43
|
+
write_attribute(name, args[0])
|
44
|
+
end
|
45
|
+
end
|
46
|
+
end
|
47
|
+
end
|
48
|
+
end
|
49
|
+
end
|
50
|
+
end
|
@@ -0,0 +1,31 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Scim
|
4
|
+
module Kit
|
5
|
+
module V2
|
6
|
+
# Represents a SCIM Attribute
|
7
|
+
class Attribute
|
8
|
+
include Attributable
|
9
|
+
include Templatable
|
10
|
+
attr_reader :type
|
11
|
+
attr_reader :_value
|
12
|
+
|
13
|
+
def initialize(type:, value: nil)
|
14
|
+
@type = type
|
15
|
+
@_value = value
|
16
|
+
define_attributes_for(type.attributes)
|
17
|
+
end
|
18
|
+
|
19
|
+
def _value=(new_value)
|
20
|
+
@_value = type.coerce(new_value)
|
21
|
+
|
22
|
+
if type.canonical_values &&
|
23
|
+
!type.canonical_values.empty? &&
|
24
|
+
!type.canonical_values.include?(new_value)
|
25
|
+
raise ArgumentError, new_value
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
@@ -16,6 +16,13 @@ module Scim
|
|
16
16
|
reference: 'reference',
|
17
17
|
complex: 'complex'
|
18
18
|
}.freeze
|
19
|
+
COERCION = {
|
20
|
+
string: ->(x) { x.to_s },
|
21
|
+
decimal: ->(x) { x.to_f },
|
22
|
+
integer: ->(x) { x.to_i },
|
23
|
+
datetime: ->(x) { x.is_a?(::String) ? DateTime.parse(x) : x },
|
24
|
+
binary: ->(x) { Base64.strict_encode64(x) }
|
25
|
+
}.freeze
|
19
26
|
attr_accessor :canonical_values
|
20
27
|
attr_accessor :case_exact
|
21
28
|
attr_accessor :description
|
@@ -28,8 +35,8 @@ module Scim
|
|
28
35
|
attr_reader :uniqueness
|
29
36
|
|
30
37
|
def initialize(name:, type: :string)
|
31
|
-
@name = name
|
32
|
-
@type = type
|
38
|
+
@name = name.to_s.underscore
|
39
|
+
@type = type.to_sym
|
33
40
|
@description = ''
|
34
41
|
@multi_valued = false
|
35
42
|
@required = false
|
@@ -37,7 +44,7 @@ module Scim
|
|
37
44
|
@mutability = Mutability::READ_WRITE
|
38
45
|
@returned = Returned::DEFAULT
|
39
46
|
@uniqueness = Uniqueness::NONE
|
40
|
-
raise ArgumentError, :type unless DATATYPES[type
|
47
|
+
raise ArgumentError, :type unless DATATYPES[@type]
|
41
48
|
end
|
42
49
|
|
43
50
|
def mutability=(value)
|
@@ -53,9 +60,9 @@ module Scim
|
|
53
60
|
end
|
54
61
|
|
55
62
|
def add_attribute(name:, type: :string)
|
56
|
-
@type = :complex
|
57
63
|
attribute = AttributeType.new(name: name, type: type)
|
58
64
|
yield attribute if block_given?
|
65
|
+
@type = :complex
|
59
66
|
attributes << attribute
|
60
67
|
end
|
61
68
|
|
@@ -64,8 +71,6 @@ module Scim
|
|
64
71
|
@reference_types = value
|
65
72
|
end
|
66
73
|
|
67
|
-
private
|
68
|
-
|
69
74
|
def attributes
|
70
75
|
@attributes ||= []
|
71
76
|
end
|
@@ -74,6 +79,18 @@ module Scim
|
|
74
79
|
type_is?(:complex)
|
75
80
|
end
|
76
81
|
|
82
|
+
def coerce(value)
|
83
|
+
if type_is?(:boolean) && ![true, false].include?(value)
|
84
|
+
raise ArgumentError, value
|
85
|
+
end
|
86
|
+
return value if multi_valued
|
87
|
+
|
88
|
+
coercion = COERCION[type]
|
89
|
+
coercion ? coercion.call(value) : value
|
90
|
+
end
|
91
|
+
|
92
|
+
private
|
93
|
+
|
77
94
|
def string?
|
78
95
|
type_is?(:string)
|
79
96
|
end
|
data/lib/scim/kit/v2/meta.rb
CHANGED
@@ -0,0 +1,25 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Scim
|
4
|
+
module Kit
|
5
|
+
module V2
|
6
|
+
# Represents a SCIM Resource
|
7
|
+
class Resource
|
8
|
+
include Attributable
|
9
|
+
include Templatable
|
10
|
+
|
11
|
+
attr_accessor :id, :external_id
|
12
|
+
attr_reader :meta
|
13
|
+
attr_reader :schemas
|
14
|
+
|
15
|
+
def initialize(schemas:, location:)
|
16
|
+
@meta = Meta.new(schemas[0].name, location)
|
17
|
+
@schemas = schemas
|
18
|
+
schemas.each do |schema|
|
19
|
+
define_attributes_for(schema.attributes)
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
data/lib/scim/kit/v2/schema.rb
CHANGED
@@ -20,7 +20,11 @@ module Scim
|
|
20
20
|
def add_attribute(name:, type: :string)
|
21
21
|
attribute = AttributeType.new(name: name, type: type)
|
22
22
|
yield attribute if block_given?
|
23
|
-
|
23
|
+
attributes << attribute
|
24
|
+
end
|
25
|
+
|
26
|
+
def core?
|
27
|
+
id.include?(Schemas::CORE)
|
24
28
|
end
|
25
29
|
|
26
30
|
def self.build(*args)
|
@@ -0,0 +1,12 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
json.key_format! camelize: :lower
|
4
|
+
if type.complex? && !type.multi_valued
|
5
|
+
json.set! type.name do
|
6
|
+
dynamic_attributes.values.each do |attribute|
|
7
|
+
render attribute, json: json
|
8
|
+
end
|
9
|
+
end
|
10
|
+
else
|
11
|
+
json.set! type.name, _value
|
12
|
+
end
|
@@ -0,0 +1,22 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
json.key_format! camelize: :lower
|
4
|
+
json.schemas schemas.map(&:id)
|
5
|
+
json.id id
|
6
|
+
json.external_id external_id
|
7
|
+
json.meta do
|
8
|
+
render meta, json: json
|
9
|
+
end
|
10
|
+
schemas.each do |schema|
|
11
|
+
if schema.core?
|
12
|
+
schema.attributes.each do |type|
|
13
|
+
render dynamic_attributes[type.name], json: json
|
14
|
+
end
|
15
|
+
else
|
16
|
+
json.set! schema.id do
|
17
|
+
schema.attributes.each do |type|
|
18
|
+
render dynamic_attributes[type.name], json: json
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
data/lib/scim/kit/version.rb
CHANGED
data/lib/scim/kit.rb
CHANGED
@@ -2,17 +2,21 @@
|
|
2
2
|
|
3
3
|
require 'tilt'
|
4
4
|
require 'tilt/jbuilder'
|
5
|
+
require 'active_support/core_ext/hash/indifferent_access'
|
5
6
|
|
6
7
|
require 'scim/kit/dynamic_attributes'
|
7
8
|
require 'scim/kit/templatable'
|
8
9
|
require 'scim/kit/template'
|
9
10
|
require 'scim/kit/version'
|
10
11
|
|
12
|
+
require 'scim/kit/v2/attributable'
|
13
|
+
require 'scim/kit/v2/attribute'
|
11
14
|
require 'scim/kit/v2/attribute_type'
|
12
15
|
require 'scim/kit/v2/authentication_scheme'
|
13
16
|
require 'scim/kit/v2/messages'
|
14
17
|
require 'scim/kit/v2/meta'
|
15
18
|
require 'scim/kit/v2/mutability'
|
19
|
+
require 'scim/kit/v2/resource'
|
16
20
|
require 'scim/kit/v2/resource_type'
|
17
21
|
require 'scim/kit/v2/returned'
|
18
22
|
require 'scim/kit/v2/schema'
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: scim-kit
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.2.
|
4
|
+
version: 0.2.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- mo
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2019-01-
|
11
|
+
date: 2019-01-08 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: tilt
|
@@ -159,6 +159,7 @@ extensions: []
|
|
159
159
|
extra_rdoc_files: []
|
160
160
|
files:
|
161
161
|
- ".gitignore"
|
162
|
+
- ".gitlab-ci.yml"
|
162
163
|
- ".rspec"
|
163
164
|
- ".rubocop.yml"
|
164
165
|
- ".travis.yml"
|
@@ -177,21 +178,26 @@ files:
|
|
177
178
|
- lib/scim/kit/dynamic_attributes.rb
|
178
179
|
- lib/scim/kit/templatable.rb
|
179
180
|
- lib/scim/kit/template.rb
|
181
|
+
- lib/scim/kit/v2/attributable.rb
|
182
|
+
- lib/scim/kit/v2/attribute.rb
|
180
183
|
- lib/scim/kit/v2/attribute_type.rb
|
181
184
|
- lib/scim/kit/v2/authentication_scheme.rb
|
182
185
|
- lib/scim/kit/v2/messages.rb
|
183
186
|
- lib/scim/kit/v2/meta.rb
|
184
187
|
- lib/scim/kit/v2/mutability.rb
|
188
|
+
- lib/scim/kit/v2/resource.rb
|
185
189
|
- lib/scim/kit/v2/resource_type.rb
|
186
190
|
- lib/scim/kit/v2/returned.rb
|
187
191
|
- lib/scim/kit/v2/schema.rb
|
188
192
|
- lib/scim/kit/v2/schemas.rb
|
189
193
|
- lib/scim/kit/v2/service_provider_configuration.rb
|
190
194
|
- lib/scim/kit/v2/supportable.rb
|
195
|
+
- lib/scim/kit/v2/templates/attribute.json.jbuilder
|
191
196
|
- lib/scim/kit/v2/templates/attribute_type.json.jbuilder
|
192
197
|
- lib/scim/kit/v2/templates/authentication_scheme.json.jbuilder
|
193
198
|
- lib/scim/kit/v2/templates/meta.json.jbuilder
|
194
199
|
- lib/scim/kit/v2/templates/nil_class.json.jbuilder
|
200
|
+
- lib/scim/kit/v2/templates/resource.json.jbuilder
|
195
201
|
- lib/scim/kit/v2/templates/resource_type.json.jbuilder
|
196
202
|
- lib/scim/kit/v2/templates/schema.json.jbuilder
|
197
203
|
- lib/scim/kit/v2/templates/service_provider_configuration.json.jbuilder
|