scim-kit 0.2.6 → 0.2.7
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/lib/scim/kit/v2/attribute.rb +29 -6
- data/lib/scim/kit/v2/attribute_type.rb +40 -22
- data/lib/scim/kit/v2/resource.rb +19 -0
- data/lib/scim/kit/v2/schema.rb +1 -0
- data/lib/scim/kit/v2.rb +45 -0
- data/lib/scim/kit/version.rb +1 -1
- data/lib/scim/kit.rb +2 -1
- data/scim-kit.gemspec +2 -1
- metadata +18 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 71f2c3e794e6d3203aacae277565ca28934f455ea4328e860d3b9227041a9e21
|
4
|
+
data.tar.gz: b98a7c46d298ca348c6ee51873e8dac278a6fb8dceb27bf918599f22af9263dc
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 4025c01e0ce569a6c0567db2dc4d043229123543076824a7edb43cee21c66d0ce02403bded2c1dd07aa2eb6493cae612d7d8794423a2fbd76d859b7f1fa93b55
|
7
|
+
data.tar.gz: 15b39a9c896ee626a832b225070284d362266b83d50246de79ca67fddda306ec11d13291aecd243b3466bbf60ac924bee0765549d9ce8ae2cb3fa2e78898915c
|
@@ -5,25 +5,48 @@ module Scim
|
|
5
5
|
module V2
|
6
6
|
# Represents a SCIM Attribute
|
7
7
|
class Attribute
|
8
|
+
include ::ActiveModel::Validations
|
8
9
|
include Attributable
|
9
10
|
include Templatable
|
10
11
|
attr_reader :type
|
11
12
|
attr_reader :_value
|
12
13
|
|
14
|
+
validate :presence_of_value, if: proc { |x| x.type.required }
|
15
|
+
validate :inclusion_of_value, if: proc { |x| x.type.canonical_values }
|
16
|
+
validate :validate_type
|
17
|
+
|
13
18
|
def initialize(type:, value: nil)
|
14
19
|
@type = type
|
15
20
|
@_value = value
|
16
21
|
define_attributes_for(type.attributes)
|
17
22
|
end
|
18
23
|
|
24
|
+
def _assign(new_value, coerce: true)
|
25
|
+
@_value = coerce ? type.coerce(new_value) : new_value
|
26
|
+
end
|
27
|
+
|
19
28
|
def _value=(new_value)
|
20
|
-
|
29
|
+
_assign(new_value, coerce: true)
|
30
|
+
end
|
31
|
+
|
32
|
+
private
|
33
|
+
|
34
|
+
def presence_of_value
|
35
|
+
return unless type.required && _value.blank?
|
36
|
+
|
37
|
+
errors.add(type.name, I18n.t('errors.messages.blank'))
|
38
|
+
end
|
39
|
+
|
40
|
+
def inclusion_of_value
|
41
|
+
return if type.canonical_values.include?(_value)
|
42
|
+
|
43
|
+
errors.add(type.name, I18n.t('errors.messages.inclusion'))
|
44
|
+
end
|
45
|
+
|
46
|
+
def validate_type
|
47
|
+
return if type.valid?(_value)
|
21
48
|
|
22
|
-
|
23
|
-
!type.canonical_values.empty? &&
|
24
|
-
!type.canonical_values.include?(new_value)
|
25
|
-
raise ArgumentError, new_value
|
26
|
-
end
|
49
|
+
errors.add(type.name, I18n.t('errors.messages.invalid'))
|
27
50
|
end
|
28
51
|
end
|
29
52
|
end
|
@@ -6,23 +6,6 @@ module Scim
|
|
6
6
|
# Represents a scim Attribute type
|
7
7
|
class AttributeType
|
8
8
|
include Templatable
|
9
|
-
DATATYPES = {
|
10
|
-
string: 'string',
|
11
|
-
boolean: 'boolean',
|
12
|
-
decimal: 'decimal',
|
13
|
-
integer: 'integer',
|
14
|
-
datetime: 'dateTime',
|
15
|
-
binary: 'binary',
|
16
|
-
reference: 'reference',
|
17
|
-
complex: 'complex'
|
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
|
26
9
|
attr_accessor :canonical_values
|
27
10
|
attr_accessor :case_exact
|
28
11
|
attr_accessor :description
|
@@ -80,17 +63,52 @@ module Scim
|
|
80
63
|
end
|
81
64
|
|
82
65
|
def coerce(value)
|
83
|
-
|
84
|
-
|
66
|
+
return value if complex?
|
67
|
+
|
68
|
+
if multi_valued
|
69
|
+
return value unless value.respond_to?(:to_a)
|
70
|
+
|
71
|
+
value.to_a.map do |x|
|
72
|
+
COERCION.fetch(type, ->(y) { y }).call(x)
|
73
|
+
end
|
74
|
+
else
|
75
|
+
COERCION.fetch(type, ->(x) { x }).call(value)
|
76
|
+
end
|
77
|
+
end
|
78
|
+
|
79
|
+
def valid?(value)
|
80
|
+
if multi_valued
|
81
|
+
return false unless value.respond_to?(:to_a)
|
82
|
+
|
83
|
+
return value.to_a.all? { |x| validate(x) }
|
85
84
|
end
|
86
|
-
return value if multi_valued
|
87
85
|
|
88
|
-
|
89
|
-
coercion ? coercion.call(value) : value
|
86
|
+
complex? ? valid_complex?(value) : valid_simple?(value)
|
90
87
|
end
|
91
88
|
|
92
89
|
private
|
93
90
|
|
91
|
+
def validate(value)
|
92
|
+
complex? ? valid_complex?(value) : valid_simple?(value)
|
93
|
+
end
|
94
|
+
|
95
|
+
def valid_simple?(value)
|
96
|
+
VALIDATIONS[type]&.call(value)
|
97
|
+
end
|
98
|
+
|
99
|
+
def valid_complex?(item)
|
100
|
+
return false unless item.is_a?(Hash)
|
101
|
+
|
102
|
+
item.keys.each do |key|
|
103
|
+
return false unless type_for(key)&.valid?(item[key])
|
104
|
+
end
|
105
|
+
end
|
106
|
+
|
107
|
+
def type_for(name)
|
108
|
+
name = name.to_s.underscore
|
109
|
+
attributes.find { |x| x.name.to_s.underscore == name }
|
110
|
+
end
|
111
|
+
|
94
112
|
def string?
|
95
113
|
type_is?(:string)
|
96
114
|
end
|
data/lib/scim/kit/v2/resource.rb
CHANGED
@@ -5,6 +5,7 @@ module Scim
|
|
5
5
|
module V2
|
6
6
|
# Represents a SCIM Resource
|
7
7
|
class Resource
|
8
|
+
include ::ActiveModel::Validations
|
8
9
|
include Attributable
|
9
10
|
include Templatable
|
10
11
|
|
@@ -12,6 +13,9 @@ module Scim
|
|
12
13
|
attr_reader :meta
|
13
14
|
attr_reader :schemas
|
14
15
|
|
16
|
+
validates_presence_of :id
|
17
|
+
validate :schema_validations
|
18
|
+
|
15
19
|
def initialize(schemas:, location:)
|
16
20
|
@meta = Meta.new(schemas[0].name, location)
|
17
21
|
@schemas = schemas
|
@@ -19,6 +23,21 @@ module Scim
|
|
19
23
|
define_attributes_for(schema.attributes)
|
20
24
|
end
|
21
25
|
end
|
26
|
+
|
27
|
+
private
|
28
|
+
|
29
|
+
def schema_validations
|
30
|
+
schemas.each do |schema|
|
31
|
+
schema.attributes.each do |type|
|
32
|
+
validate_attribute(type)
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
37
|
+
def validate_attribute(type)
|
38
|
+
attribute = attribute_for(type.name)
|
39
|
+
errors.copy!(attribute.errors) unless attribute.valid?
|
40
|
+
end
|
22
41
|
end
|
23
42
|
end
|
24
43
|
end
|
data/lib/scim/kit/v2/schema.rb
CHANGED
data/lib/scim/kit/v2.rb
CHANGED
@@ -21,6 +21,51 @@ module Scim
|
|
21
21
|
module Kit
|
22
22
|
# Version 2 of the SCIM RFC https://tools.ietf.org/html/rfc7644
|
23
23
|
module V2
|
24
|
+
BASE64 = %r(
|
25
|
+
\A([A-Za-z0-9+/]{4})*([A-Za-z0-9+/]{2}==|[A-Za-z0-9+/]{3}=)?\Z
|
26
|
+
)x.freeze
|
27
|
+
BOOLEAN_VALUES = [true, false].freeze
|
28
|
+
DATATYPES = {
|
29
|
+
string: 'string',
|
30
|
+
boolean: 'boolean',
|
31
|
+
decimal: 'decimal',
|
32
|
+
integer: 'integer',
|
33
|
+
datetime: 'dateTime',
|
34
|
+
binary: 'binary',
|
35
|
+
reference: 'reference',
|
36
|
+
complex: 'complex'
|
37
|
+
}.freeze
|
38
|
+
COERCION = {
|
39
|
+
binary: lambda { |x|
|
40
|
+
VALIDATIONS[:binary].call(x) ? x : Base64.strict_encode64(x)
|
41
|
+
},
|
42
|
+
boolean: lambda { |x|
|
43
|
+
return true if x == 'true'
|
44
|
+
return false if x == 'false'
|
45
|
+
|
46
|
+
x
|
47
|
+
},
|
48
|
+
datetime: ->(x) { x.is_a?(::String) ? DateTime.parse(x) : x },
|
49
|
+
decimal: ->(x) { x.to_f },
|
50
|
+
integer: ->(x) { x.to_i },
|
51
|
+
string: ->(x) { x.to_s }
|
52
|
+
}.freeze
|
53
|
+
VALIDATIONS = {
|
54
|
+
binary: ->(x) { x.is_a?(String) && x.match?(BASE64) },
|
55
|
+
boolean: ->(x) { BOOLEAN_VALUES.include?(x) },
|
56
|
+
datetime: ->(x) { x.is_a?(DateTime) },
|
57
|
+
decimal: ->(x) { x.is_a?(Float) },
|
58
|
+
integer: lambda { |x|
|
59
|
+
begin
|
60
|
+
x&.integer?
|
61
|
+
rescue StandardError
|
62
|
+
false
|
63
|
+
end
|
64
|
+
},
|
65
|
+
reference: ->(x) { x =~ /\A#{URI.regexp(%w[http https])}\z/ },
|
66
|
+
string: ->(x) { x.is_a?(String) }
|
67
|
+
}.freeze
|
68
|
+
|
24
69
|
class << self
|
25
70
|
def configuration
|
26
71
|
@configuration ||= ::Scim::Kit::V2::Configuration.new
|
data/lib/scim/kit/version.rb
CHANGED
data/lib/scim/kit.rb
CHANGED
@@ -1,8 +1,9 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
+
require 'active_model'
|
4
|
+
require 'active_support/core_ext/hash/indifferent_access'
|
3
5
|
require 'tilt'
|
4
6
|
require 'tilt/jbuilder'
|
5
|
-
require 'active_support/core_ext/hash/indifferent_access'
|
6
7
|
|
7
8
|
require 'scim/kit/dynamic_attributes'
|
8
9
|
require 'scim/kit/templatable'
|
data/scim-kit.gemspec
CHANGED
@@ -12,7 +12,7 @@ Gem::Specification.new do |spec|
|
|
12
12
|
|
13
13
|
spec.summary = 'A SCIM library.'
|
14
14
|
spec.description = 'A SCIM library.'
|
15
|
-
spec.homepage = 'https://www.
|
15
|
+
spec.homepage = 'https://www.github.com/mokhan/scim-kit'
|
16
16
|
spec.license = 'MIT'
|
17
17
|
|
18
18
|
# Specify which files should be added to the gem when it is released.
|
@@ -28,6 +28,7 @@ Gem::Specification.new do |spec|
|
|
28
28
|
end
|
29
29
|
spec.require_paths = ['lib']
|
30
30
|
|
31
|
+
spec.add_dependency 'activemodel', '>= 5.2.0'
|
31
32
|
spec.add_dependency 'tilt', '~> 2.0'
|
32
33
|
spec.add_dependency 'tilt-jbuilder', '~> 0.7'
|
33
34
|
spec.add_development_dependency 'bundler', '~> 1.17'
|
metadata
CHANGED
@@ -1,15 +1,29 @@
|
|
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.7
|
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-11 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: activemodel
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ">="
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: 5.2.0
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ">="
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: 5.2.0
|
13
27
|
- !ruby/object:Gem::Dependency
|
14
28
|
name: tilt
|
15
29
|
requirement: !ruby/object:Gem::Requirement
|
@@ -207,7 +221,7 @@ files:
|
|
207
221
|
- lib/scim/kit/v2/uniqueness.rb
|
208
222
|
- lib/scim/kit/version.rb
|
209
223
|
- scim-kit.gemspec
|
210
|
-
homepage: https://www.
|
224
|
+
homepage: https://www.github.com/mokhan/scim-kit
|
211
225
|
licenses:
|
212
226
|
- MIT
|
213
227
|
metadata: {}
|
@@ -226,7 +240,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
226
240
|
- !ruby/object:Gem::Version
|
227
241
|
version: '0'
|
228
242
|
requirements: []
|
229
|
-
rubygems_version: 3.0.
|
243
|
+
rubygems_version: 3.0.2
|
230
244
|
signing_key:
|
231
245
|
specification_version: 4
|
232
246
|
summary: A SCIM library.
|