summaryrefslogtreecommitdiff
path: root/lib/saml/kit/cli/commands/metadata.rb
blob: 6701d708a5f7ba60d4510906da410c5a8d4a3999 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
module Saml
  module Kit
    module Cli
      module Commands
        class Metadata < Thor
          desc 'register url', 'Registers the Metadata from the remote url.'
          def register(url)
            say registry.register_url(url).to_xml(pretty: true), :green
          end

          desc 'list', "List each of the registered entityId's"
          def list
            if registry.count.zero?
              say "Please register metadata using `saml-kit metadata register <url>`"
            end
            registry.each do |x|
              say x.entity_id, :green
            end
          end

          desc 'show entity_id', 'show the metadata associated with an entityId'
          def show(entity_id)
            metadata = registry.metadata_for(entity_id)
            if metadata
              Report.new(metadata).print(self)
            else
              say "`#{entity_id}` is not registered", :red
            end
          end

          private

          def registry
            Saml::Kit.registry
          end
        end
      end
    end
  end
end