Class: Spid::SynchronizeIdpMetadata

Inherits:
Object
  • Object
show all
Defined in:
lib/spid/synchronize_idp_metadata.rb

Overview

:nodoc:

Instance Method Summary collapse

Constructor Details

#initializeSynchronizeIdpMetadata

Returns a new instance of SynchronizeIdpMetadata.



8
9
10
# File 'lib/spid/synchronize_idp_metadata.rb', line 8

def initialize
  FileUtils.mkdir_p(Spid.configuration.)
end

Instance Method Details

#callObject



12
13
14
15
16
17
18
19
# File 'lib/spid/synchronize_idp_metadata.rb', line 12

def call
  idp_list.map do |name, url|
     = "#{name.delete(' ').downcase}-metadata.xml"
     = (url)

    File.open((), "wb") { |f| f.write  }
  end
end

#entitiesObject



48
49
50
51
52
# File 'lib/spid/synchronize_idp_metadata.rb', line 48

def entities
  return [] if idp_list_raw.nil?

  JSON.parse(idp_list_raw)["spidFederationRegistry"]["entities"]
end

#get_metadata_from_url(url) ⇒ Object



54
55
56
57
58
59
60
61
62
63
64
65
# File 'lib/spid/synchronize_idp_metadata.rb', line 54

def (url)
  uri = URI(url)
  req = Net::HTTP::Get.new(uri)

  res = Net::HTTP.start(
    uri.host, uri.port, use_ssl: uri.scheme == "https"
  ) do |http|
    http.request(req)
  end

  res.body
end

#idp_listObject



21
22
23
24
25
26
27
28
29
30
31
# File 'lib/spid/synchronize_idp_metadata.rb', line 21

def idp_list
  .each.with_object({}) do |(name, url), acc|
    uri = URI(url)
    res = Net::HTTP.get_response(uri)
    acc[name] = if res.code == "302"
                  res["Location"]
                else
                  url
                end
  end
end

#idp_list_rawObject



67
68
69
70
71
72
73
74
75
76
77
78
79
80
# File 'lib/spid/synchronize_idp_metadata.rb', line 67

def idp_list_raw
  uri = URI(registry_url)

  req = Net::HTTP::Get.new(uri)
  req["Accept"] = "application/json"

  res = Net::HTTP.start(
    uri.host, uri.port, use_ssl: uri.scheme == "https"
  ) do |http|
    http.request(req)
  end

  res.body
end

#metadata_listObject



33
34
35
36
37
38
39
# File 'lib/spid/synchronize_idp_metadata.rb', line 33

def 
  entities.each.with_object({}) do |entity, acc|
    entity_name = entity["entity_name"]
    entity_name = "SPIDItalia" if entity_name =~ /SPIDItalia/
    acc[entity_name] = entity["metadata_url"]
  end
end

#metadata_path(name) ⇒ Object



41
42
43
44
45
46
# File 'lib/spid/synchronize_idp_metadata.rb', line 41

def (name)
  File.join(
    Spid.configuration.,
    name
  )
end

#registry_urlObject



82
83
84
# File 'lib/spid/synchronize_idp_metadata.rb', line 82

def registry_url
  "https://registry.spid.gov.it/api/identity-providers"
end