aboutsummaryrefslogtreecommitdiff
path: root/bin
diff options
context:
space:
mode:
authorSchanzenbach, Martin <mschanzenbach@posteo.de>2019-04-26 00:16:00 +0200
committerSchanzenbach, Martin <mschanzenbach@posteo.de>2019-04-26 00:16:00 +0200
commitcd02c836de772007c472553bcbe976ccb18589d7 (patch)
tree3a3277e8acc22a7c4cd75b9fcf47c159ab1c2dd2 /bin
parente654053eb19dc25c0f8dba47b0231bec3dcaf27a (diff)
downloadreclaim-oidc-cd02c836de772007c472553bcbe976ccb18589d7.tar.gz
reclaim-oidc-cd02c836de772007c472553bcbe976ccb18589d7.zip
towards working tool
Diffstat (limited to 'bin')
-rwxr-xr-x[-rw-r--r--]bin/reclaim-oidc129
1 files changed, 129 insertions, 0 deletions
diff --git a/bin/reclaim-oidc b/bin/reclaim-oidc
index e69de29..7ce6d57 100644..100755
--- a/bin/reclaim-oidc
+++ b/bin/reclaim-oidc
@@ -0,0 +1,129 @@
1#!/usr/bin/env ruby
2require 'optparse'
3require './lib/reclaim_oidc.rb'
4
5class OptParser
6 class ScriptOptions
7 attr_accessor :name, :add, :delete, :list, :description, :redirect_uri,
8 :verbose
9
10 def initialize
11 self.delete = false
12 self.add = false
13 self.list = false
14 self.verbose = false
15 end
16
17 def define_options(parser)
18 parser.banner = "Usage: reclaim-oidc [options]"
19 parser.separator ""
20 parser.separator "Specific options:"
21
22 # add additional options
23 add_option(parser)
24 delete_option(parser)
25 list_option(parser)
26 client_name_option(parser)
27 client_redirect_option(parser)
28 client_description_option(parser)
29 boolean_verbose_option(parser)
30
31 parser.separator ""
32 parser.separator "Common options:"
33 # No argument, shows at tail. This will print an options summary.
34 parser.on_tail("-h", "--help", "Show this message") do
35 puts parser
36 exit
37 end
38 # Another typical switch to print the version.
39 parser.on_tail("--version", "Show version") do
40 puts ReclaimOidc.version
41 exit
42 end
43 end
44
45 def client_name_option(parser)
46 parser.on("-n", "--client-name [NAME]",
47 "Name of the OIDC client") do |n|
48 self.name = n
49 end
50 end
51
52 def client_redirect_option(parser)
53 parser.on("-r", "--redirect [URI]",
54 "The OIDC redirect_uri parameter") do |n|
55 self.redirect_uri = n
56 end
57 end
58
59 def client_description_option(parser)
60 parser.on("-D", "--description [DESCRIPTION]",
61 "The OIDC client description") do |n|
62 self.description = n
63 end
64 end
65
66 def add_option(parser)
67 parser.on("-a", "--add", "Add a client") do |v|
68 self.add = v
69 end
70 end
71
72 def delete_option(parser)
73 parser.on("-d", "--delete", "Delete a client") do |v|
74 self.delete = v
75 end
76 end
77
78 def list_option(parser)
79 parser.on("-l", "--list", "List clients") do |v|
80 self.list = v
81 end
82 end
83
84 def boolean_verbose_option(parser)
85 # Boolean switch.
86 parser.on("-v", "--[no-]verbose", "Run verbosely") do |v|
87 self.verbose = v
88 end
89 end
90 end
91
92 #
93 # Return a structure describing the options.
94 #
95 def parse(args)
96 # The options specified on the command line will be collected in
97 # *options*.
98
99 @options = ScriptOptions.new
100 @args = OptionParser.new do |parser|
101 @options.define_options(parser)
102 parser.parse!(args)
103 end
104 @options
105 end
106
107 attr_reader :parser, :options
108end # class OptparseExample
109
110op = OptParser.new
111options = op.parse(ARGV)
112#pp options
113#pp ARGV
114
115x = ReclaimOidc.new(options.verbose)
116
117if (options.list)
118 x.get_clients
119 exit
120end
121if (options.add)
122 raise if options.name.nil? or options.redirect_uri.nil?
123 x.add_client(options.name,options.redirect_uri,options.description)
124 exit
125end
126if (options.delete)
127 x.delete_client(options.name)
128end
129