soar-registry-staff 0.0.2 → 0.0.3
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/README.md +13 -8
- data/lib/soar/registry/staff/identifier/factory.rb +40 -0
- data/lib/soar/registry/staff/identifier/hash.rb +24 -0
- data/lib/soar/registry/staff/identifier/id.rb +18 -0
- data/lib/soar/registry/staff/identity.rb +9 -7
- data/lib/soar/registry/staff/translator/dynamo_db.rb +0 -16
- metadata +4 -1
    
        checksums.yaml
    CHANGED
    
    | @@ -1,7 +1,7 @@ | |
| 1 1 | 
             
            ---
         | 
| 2 2 | 
             
            SHA1:
         | 
| 3 | 
            -
              metadata.gz:  | 
| 4 | 
            -
              data.tar.gz:  | 
| 3 | 
            +
              metadata.gz: b870c2449a793ab6ce47a3b265be8eecd6f7d688
         | 
| 4 | 
            +
              data.tar.gz: dcab46f89e3425a949580f83a78f00ab240953fc
         | 
| 5 5 | 
             
            SHA512:
         | 
| 6 | 
            -
              metadata.gz:  | 
| 7 | 
            -
              data.tar.gz:  | 
| 6 | 
            +
              metadata.gz: 152fa38f09839258442d7e73b4f2a18124786d40f8770d4bc174c690e8efeb20afc386eca7851d4d2e92cf5e5eef4aaa2514edf4749ca63f334cbecca626b13e
         | 
| 7 | 
            +
              data.tar.gz: d8f7afdcbdf5607a9997d58a3b539e39e04a99afe144d5adaa0f4d9da5a8500b598147af83b458e4a05a05a17e0c8af477b48fde474620087755a73ce4b51c11
         | 
    
        data/README.md
    CHANGED
    
    | @@ -23,21 +23,24 @@ provider: | |
| 23 23 |  | 
| 24 24 | 
             
            ### Create an instance of the staff identity registry
         | 
| 25 25 | 
             
            ```ruby
         | 
| 26 | 
            +
            require 'soar/registry/staff/identity'
         | 
| 26 27 | 
             
            @idr = Soar::Registry::Staff::Identity.new(configuration)
         | 
| 27 28 | 
             
            ```
         | 
| 28 29 |  | 
| 29 30 | 
             
            ### Getting a list of identifiers
         | 
| 30 31 | 
             
            ```ruby
         | 
| 31 | 
            -
            > identifiers = @idr.get_identifiers( | 
| 32 | 
            -
            > identifiers = @idr.get_identifiers( | 
| 32 | 
            +
            > identifiers = @idr.get_identifiers("identity-820d5660-2204-4f7d-8c04-746313439b81") 
         | 
| 33 | 
            +
            > identifiers = @idr.get_identifiers({"email" => "admin@hetzner.co.za"}.to_json) 
         | 
| 34 | 
            +
            > identifiers = @idr.get_identifiers({"identity_id" => "identity-820d5660-2204-4f7d-8c04-746313439b81"}.to_json) 
         | 
| 33 35 | 
             
            > puts identifiers.inspect
         | 
| 34 36 | 
             
            ["admin@hetzner.co.za", "identity-820d5660-2204-4f7d-8c04-746313439b81"]
         | 
| 35 37 | 
             
            ```
         | 
| 36 38 |  | 
| 37 39 | 
             
            ### Getting a list of roles
         | 
| 38 40 | 
             
            ```ruby
         | 
| 39 | 
            -
            > roles = @idr.get_roles( | 
| 40 | 
            -
            > roles = @idr.get_roles( | 
| 41 | 
            +
            > roles = @idr.get_roles("identity-820d5660-2204-4f7d-8c04-746313439b81")
         | 
| 42 | 
            +
            > roles = @idr.get_roles({"email" => "admin@hetzner.co.za"}.to_json)
         | 
| 43 | 
            +
            > roles = @idr.get_roles({"identity_id" => "identity-820d5660-2204-4f7d-8c04-746313439b81"}.to_json)
         | 
| 41 44 | 
             
            > puts roles.inspect
         | 
| 42 45 | 
             
            ["staff", "configuration_publisher", "configuration_consumer"]
         | 
| 43 46 | 
             
            ```
         | 
| @@ -45,8 +48,9 @@ provider: | |
| 45 48 | 
             
            ### Getting a hash of attributes for a role 
         | 
| 46 49 | 
             
            ```ruby
         | 
| 47 50 | 
             
            > role = 'staff'
         | 
| 48 | 
            -
            > attributes = @idr.get_attributes( | 
| 49 | 
            -
            > attributes = @idr.get_attributes( | 
| 51 | 
            +
            > attributes = @idr.get_attributes("identity-820d5660-2204-4f7d-8c04-746313439b81", role)
         | 
| 52 | 
            +
            > attributes = @idr.get_attributes({"email" => "admin@hetzner.co.za"}.to_json, role)
         | 
| 53 | 
            +
            > attributes = @idr.get_attributes({"identity_id" => "identity-820d5660-2204-4f7d-8c04-746313439b81"}.to_json, role)
         | 
| 50 54 | 
             
            > puts attributes.inspect
         | 
| 51 55 | 
             
            {
         | 
| 52 56 | 
             
                "staff": {
         | 
| @@ -58,8 +62,9 @@ provider: | |
| 58 62 |  | 
| 59 63 | 
             
            ### Getting a hash of all attributes
         | 
| 60 64 | 
             
            ```ruby
         | 
| 61 | 
            -
            > attributes = @idr.get_attributes( | 
| 62 | 
            -
            > attributes = @idr.get_attributes( | 
| 65 | 
            +
            > attributes = @idr.get_attributes("identity-820d5660-2204-4f7d-8c04-746313439b81")
         | 
| 66 | 
            +
            > attributes = @idr.get_attributes({"email" => "admin@hetzner.co.za"}.to_json)
         | 
| 67 | 
            +
            > attributes = @idr.get_attributes({"identity_id" => "identity-820d5660-2204-4f7d-8c04-746313439b81"}.to_json)
         | 
| 63 68 | 
             
            > puts attributes.inspect
         | 
| 64 69 | 
             
            {
         | 
| 65 70 | 
             
                "identity_id" => "identity-820d5660-2204-4f7d-8c04-746313439b81",
         | 
| @@ -0,0 +1,40 @@ | |
| 1 | 
            +
            require 'soar/registry/staff/identifier/id'
         | 
| 2 | 
            +
            require 'soar/registry/staff/identifier/hash'
         | 
| 3 | 
            +
             | 
| 4 | 
            +
            module Soar
         | 
| 5 | 
            +
              module Registry
         | 
| 6 | 
            +
                module Staff
         | 
| 7 | 
            +
                  module Identifier
         | 
| 8 | 
            +
                    class Factory
         | 
| 9 | 
            +
             | 
| 10 | 
            +
                      ##
         | 
| 11 | 
            +
                      # @param [String] identifier_id or a json serialized hash with length 1 eg. '{"email":"test@example.com"}'
         | 
| 12 | 
            +
                      # @return [Soar::Registry::Staff::Identifier::Id|Soar::Registry::Staff::Identifier::Hash] identifier
         | 
| 13 | 
            +
                      ##
         | 
| 14 | 
            +
                      def get_identifier(identifier)
         | 
| 15 | 
            +
                        if is_json?(identifier)
         | 
| 16 | 
            +
                          return Soar::Registry::Staff::Identifier::Hash.new(identifier)
         | 
| 17 | 
            +
                        else
         | 
| 18 | 
            +
                          return Soar::Registry::Staff::Identifier::Id.new(identifier)
         | 
| 19 | 
            +
                        end
         | 
| 20 | 
            +
                      end
         | 
| 21 | 
            +
             | 
| 22 | 
            +
                      private
         | 
| 23 | 
            +
             | 
| 24 | 
            +
                      def is_json?(identifier)
         | 
| 25 | 
            +
                        begin
         | 
| 26 | 
            +
                          return JSON.parse(identifier)
         | 
| 27 | 
            +
                          return true
         | 
| 28 | 
            +
                        rescue JSON::ParserError => e
         | 
| 29 | 
            +
                          return false
         | 
| 30 | 
            +
                        end
         | 
| 31 | 
            +
                      end
         | 
| 32 | 
            +
             | 
| 33 | 
            +
                    end
         | 
| 34 | 
            +
             | 
| 35 | 
            +
                  end
         | 
| 36 | 
            +
             | 
| 37 | 
            +
                end
         | 
| 38 | 
            +
              end
         | 
| 39 | 
            +
            end
         | 
| 40 | 
            +
             | 
| @@ -0,0 +1,24 @@ | |
| 1 | 
            +
            module Soar
         | 
| 2 | 
            +
              module Registry
         | 
| 3 | 
            +
                module Staff
         | 
| 4 | 
            +
                  module Identifier
         | 
| 5 | 
            +
                    class Hash
         | 
| 6 | 
            +
             | 
| 7 | 
            +
                      class MultipleIdentifierTypesError < StandardError; end;
         | 
| 8 | 
            +
             | 
| 9 | 
            +
                      attr_reader :type
         | 
| 10 | 
            +
                      attr_reader :value
         | 
| 11 | 
            +
             | 
| 12 | 
            +
                      def initialize(identifier)
         | 
| 13 | 
            +
                        identifier = JSON.parse(identifier)
         | 
| 14 | 
            +
                        raise MultipleIdentifierTypesError, 'Multiple identifier types are not allowed' if identifier.length > 1
         | 
| 15 | 
            +
                        @type = identifier.keys[0]
         | 
| 16 | 
            +
                        @value = identifier[identifier.keys[0]]
         | 
| 17 | 
            +
                      end
         | 
| 18 | 
            +
             | 
| 19 | 
            +
                    end
         | 
| 20 | 
            +
                  end
         | 
| 21 | 
            +
                end
         | 
| 22 | 
            +
              end
         | 
| 23 | 
            +
            end
         | 
| 24 | 
            +
             | 
| @@ -1,6 +1,7 @@ | |
| 1 1 | 
             
            require 'soar_idm/soar_idm'
         | 
| 2 2 | 
             
            require 'soar/registry/staff/translator/dynamo_db'
         | 
| 3 3 | 
             
            require 'soar/registry/staff/directory/dynamo_db/identity'
         | 
| 4 | 
            +
            require 'soar/registry/staff/identifier/factory'
         | 
| 4 5 |  | 
| 5 6 | 
             
            module Soar
         | 
| 6 7 | 
             
              module Registry
         | 
| @@ -76,15 +77,16 @@ module Soar | |
| 76 77 | 
             
                    end
         | 
| 77 78 |  | 
| 78 79 | 
             
                    ##
         | 
| 79 | 
            -
                    # @param [String | 
| 80 | 
            -
                    # @return [ | 
| 80 | 
            +
                    # @param [String] identifier primary key (identity_id) or a json serialized hash with length 1 eg. '{"email":"test@example.com"}'
         | 
| 81 | 
            +
                    # @return [Hash] an identity
         | 
| 81 82 | 
             
                    def calculate_identities(identifier)
         | 
| 82 | 
            -
                       | 
| 83 | 
            -
             | 
| 84 | 
            -
             | 
| 85 | 
            -
                        return [@translator.get_identity( | 
| 83 | 
            +
                      identifier_factory = Soar::Registry::Staff::Identifier::Factory.new
         | 
| 84 | 
            +
                      identifier = identifier_factory.get_identifier(identifier)
         | 
| 85 | 
            +
                      if identifier.is_a?(Soar::Registry::Staff::Identifier::Id)
         | 
| 86 | 
            +
                        return [@translator.get_identity(@directory.fetch_identity(identifier.value))]
         | 
| 86 87 | 
             
                      end
         | 
| 87 | 
            -
                       | 
| 88 | 
            +
                      entries = @directory.search_identities(identifier.type, identifier.value )
         | 
| 89 | 
            +
                      return [@translator.get_identity(entries)[0]]
         | 
| 88 90 | 
             
                    end
         | 
| 89 91 |  | 
| 90 92 | 
             
                  end
         | 
| @@ -12,15 +12,6 @@ module Soar | |
| 12 12 | 
             
                        return entry
         | 
| 13 13 | 
             
                      end
         | 
| 14 14 |  | 
| 15 | 
            -
                      def is_json?(json)
         | 
| 16 | 
            -
                        begin
         | 
| 17 | 
            -
                          JSON.parse(json)
         | 
| 18 | 
            -
                          return true
         | 
| 19 | 
            -
                        rescue JSON::ParserError => e
         | 
| 20 | 
            -
                          return false
         | 
| 21 | 
            -
                        end
         | 
| 22 | 
            -
                      end
         | 
| 23 | 
            -
             | 
| 24 15 | 
             
                      ##
         | 
| 25 16 | 
             
                      # @param [Array] entries a list of entries from data source
         | 
| 26 17 | 
             
                      # @return [Array] identities a list of identities
         | 
| @@ -29,13 +20,6 @@ module Soar | |
| 29 20 | 
             
                        return entries
         | 
| 30 21 | 
             
                      end
         | 
| 31 22 |  | 
| 32 | 
            -
                      ##
         | 
| 33 | 
            -
                      # @param [String|Hash] identifier could be a json string or a ruby hash
         | 
| 34 | 
            -
                      # @return [Hash] identifier with identifying attribute key and attribute value
         | 
| 35 | 
            -
                      ##
         | 
| 36 | 
            -
                      def get_identifier(identifier)
         | 
| 37 | 
            -
                        identifier.is_a?(Hash) ? identifier : JSON.parse(identifier)
         | 
| 38 | 
            -
                      end
         | 
| 39 23 | 
             
                    end
         | 
| 40 24 | 
             
                  end
         | 
| 41 25 | 
             
                end
         | 
    
        metadata
    CHANGED
    
    | @@ -1,7 +1,7 @@ | |
| 1 1 | 
             
            --- !ruby/object:Gem::Specification
         | 
| 2 2 | 
             
            name: soar-registry-staff
         | 
| 3 3 | 
             
            version: !ruby/object:Gem::Version
         | 
| 4 | 
            -
              version: 0.0. | 
| 4 | 
            +
              version: 0.0.3
         | 
| 5 5 | 
             
            platform: ruby
         | 
| 6 6 | 
             
            authors:
         | 
| 7 7 | 
             
            - Charles Mulder
         | 
| @@ -94,6 +94,9 @@ files: | |
| 94 94 | 
             
            - lib/soar/registry/staff/directory/dynamo_db/base.rb
         | 
| 95 95 | 
             
            - lib/soar/registry/staff/directory/dynamo_db/identity.rb
         | 
| 96 96 | 
             
            - lib/soar/registry/staff/directory/error.rb
         | 
| 97 | 
            +
            - lib/soar/registry/staff/identifier/factory.rb
         | 
| 98 | 
            +
            - lib/soar/registry/staff/identifier/hash.rb
         | 
| 99 | 
            +
            - lib/soar/registry/staff/identifier/id.rb
         | 
| 97 100 | 
             
            - lib/soar/registry/staff/identity.rb
         | 
| 98 101 | 
             
            - lib/soar/registry/staff/translator/dynamo_db.rb
         | 
| 99 102 | 
             
            homepage: https://gitlab.host-h.net/registries/staff
         |