Commit 7f5dbe5
Changed files (6)
lib
spec
scim
kit
lib/scim/kit/v2/templates/resource.json.jbuilder
@@ -1,12 +1,12 @@
# frozen_string_literal: true
json.key_format! camelize: :lower
-json.schemas schemas.map(&:id)
-json.id id
-json.external_id external_id
json.meta do
render meta, json: json
end
+json.schemas schemas.map(&:id)
+json.id id
+json.external_id external_id
schemas.each do |schema|
if schema.core?
schema.attributes.each do |type|
lib/scim/kit/v2/templates/schema.json.jbuilder
@@ -1,13 +1,12 @@
# frozen_string_literal: true
json.key_format! camelize: :lower
+json.meta do
+ render meta, json: json
+end
json.id id
json.name name
json.description description
-json.meta do
- json.resource_type 'Schema'
- json.location location
-end
json.attributes attributes do |attribute|
render attribute, json: json
end
lib/scim/kit/v2/templates/service_provider_configuration.json.jbuilder
@@ -1,6 +1,9 @@
# frozen_string_literal: true
json.key_format! camelize: :lower
+json.meta do
+ render meta, json: json
+end
json.schemas [Scim::Kit::V2::Schemas::SERVICE_PROVIDER_CONFIGURATION]
json.documentation_uri documentation_uri
json.patch do
@@ -24,6 +27,3 @@ end
json.authentication_schemes authentication_schemes do |authentication_scheme|
render authentication_scheme, json: json
end
-json.meta do
- render meta, json: json
-end
lib/scim/kit/v2/configuration.rb
@@ -3,10 +3,13 @@
module Scim
module Kit
module V2
+ # Represents an application SCIM configuration.
class Configuration
+ # @private
class Builder
def initialize
@resource_types = {}
+ @schemas = {}
end
def service_provider_configuration(location:)
@@ -16,17 +19,25 @@ module Scim
def resource_type(id:, location:)
@resource_types[id] ||= ResourceType.new(location: location)
+ @resource_types[id].id = id
yield @resource_types[id]
end
+ def schema(id:, name:, location:)
+ @schemas[id] ||= Schema.new(id: id, name: name, location: location)
+ yield @schemas[id]
+ end
+
def apply_to(configuration)
configuration.service_provider_configuration = @sp_config
configuration.resource_types = @resource_types
+ configuration.schemas = @schemas
end
end
attr_accessor :service_provider_configuration
attr_accessor :resource_types
+ attr_accessor :schemas
def initialize
builder = Builder.new
lib/scim/kit/v2/schema.rb
@@ -7,13 +7,14 @@ module Scim
class Schema
include Templatable
- attr_reader :id, :name, :location, :attributes
+ attr_reader :id, :name, :attributes, :meta
attr_accessor :description
def initialize(id:, name:, location:)
@id = id
@name = name
- @location = location
+ @meta = Meta.new('Schema', location)
+ @meta.created = @meta.last_modified = @meta.version = nil
@attributes = []
end
spec/scim/kit/v2/configuration_spec.rb
@@ -13,17 +13,28 @@ RSpec.describe Scim::Kit::V2::Configuration do
x.resource_type(id: 'Group', location: group_type_location) do |y|
y.schema = Scim::Kit::V2::Schemas::GROUP
end
+ x.schema(id: 'User', name: 'User', location: user_schema_location) do |y|
+ y.add_attribute(name: 'userName')
+ end
end
end
let(:sp_location) { FFaker::Internet.uri('https') }
let(:user_type_location) { FFaker::Internet.uri('https') }
let(:group_type_location) { FFaker::Internet.uri('https') }
+ let(:user_schema_location) { FFaker::Internet.uri('https') }
specify { expect(subject.service_provider_configuration.meta.location).to eql(sp_location) }
specify { expect(subject.service_provider_configuration.authentication_schemes[0].type).to be(:oauthbearertoken) }
specify { expect(subject.service_provider_configuration.change_password.supported).to be(true) }
specify { expect(subject.resource_types['User'].schema).to eql(Scim::Kit::V2::Schemas::USER) }
+ specify { expect(subject.resource_types['User'].id).to eql('User') }
specify { expect(subject.resource_types['Group'].schema).to eql(Scim::Kit::V2::Schemas::GROUP) }
+ specify { expect(subject.resource_types['Group'].id).to eql('Group') }
+
+ specify { expect(subject.schemas['User'].id).to eql('User') }
+ specify { expect(subject.schemas['User'].name).to eql('User') }
+ specify { expect(subject.schemas['User'].meta.location).to eql(user_schema_location) }
+ specify { expect(subject.schemas['User'].attributes[0].name).to eql('user_name') }
end