Sha256: 391ea32f1de88c681bcadae7af28f3edba5c27b87cd7b3ee435151c55adc0b70
Contents?: true
Size: 1.24 KB
Versions: 3
Compression:
Stored size: 1.24 KB
Contents
# frozen_string_literal: true class GlobusClient # Lookup of a Globus identity ID class Identity def initialize(config) @config = config end def get_identity_id(user_id) @email = user_id response = lookup_identity UnexpectedResponse.call(response) unless response.success? data = JSON.parse(response.body) extract_id(data) end def exists?(user_id) get_identity_id(user_id) true rescue false end private attr_reader :config def connection Faraday.new(url: config.auth_url) end def lookup_identity id_endpoint = "/v2/api/identities" connection.get(id_endpoint) do |req| req.params["usernames"] = @email req.headers["Authorization"] = "Bearer #{config.token}" end end def extract_id(data) identities = data["identities"] # Select identity with "used" or "private" status matching_users = identities.select { |id| id["username"] == @email } active_users = matching_users.select { |user| (user["status"] == "used" || user["status"] == "private") } raise "No matching active Globus user found for #{@email}." if active_users.empty? active_users.first["id"] end end end
Version data entries
3 entries across 3 versions & 1 rubygems
Version | Path |
---|---|
globus_client-0.7.0 | lib/globus_client/identity.rb |
globus_client-0.6.0 | lib/globus_client/identity.rb |
globus_client-0.5.0 | lib/globus_client/identity.rb |