11# frozen_string_literal: true
22
3+ require 'byebug'
34require 'uffizzi'
45require 'uffizzi/config_file'
56
@@ -9,39 +10,40 @@ class Cli::Install < Thor
910 HELM_DEPLOYED_STATUS = 'deployed'
1011 CHART_NAME = 'uffizzi-app'
1112 VALUES_FILE_NAME = 'helm_values.yaml'
13+ DEFAULT_ISSUER = 'letsencrypt'
14+ DEFAULT_NAMESPACE = 'default'
1215
13- desc 'by-wizard [NAMESPACE]' , 'Install uffizzi to cluster'
14- def by_wizard ( namespace )
15- run_installation do
16- ask_installation_params ( namespace )
17- end
18- end
19-
20- desc 'by-options [NAMESPACE]' , 'Install uffizzi to cluster'
21- method_option :domain , required : true , type : :string , aliases : '-d'
22- method_option :'user-email' , required : false , type : :string , aliases : '-e'
16+ desc 'application' , 'Install uffizzi to cluster'
17+ method_option :namespace , required : false , type : :string
18+ method_option :domain , required : false , type : :string
19+ method_option :'user-email' , required : false , type : :string
2320 method_option :'acme-email' , required : false , type : :string
2421 method_option :'user-password' , required : false , type : :string
2522 method_option :'controller-password' , required : false , type : :string
26- method_option :issuer , type : :string , enum : [ 'letsencrypt' , 'zerossl' ] , default : 'letsencrypt'
23+ method_option :issuer , type : :string , enum : [ 'letsencrypt' , 'zerossl' ]
2724 method_option :'wildcard-cert-path' , required : false , type : :string
2825 method_option :'wildcard-key-path' , required : false , type : :string
2926 method_option :'without-wildcard-tls' , required : false , type : :boolean
30- def by_options ( namespace )
27+ def application
3128 run_installation do
32- validate_installation_options ( namespace , options )
29+ if options . present?
30+ validate_installation_options
31+ else
32+ ask_installation_params
33+ end
3334 end
3435 end
3536
36- desc 'add-wildcard-tls [NAMESPACE]' , 'Add wildcard tls from files'
37- method_option :cert , required : true , type : :string , aliases : '-c'
38- method_option :key , required : true , type : :string , aliases : '-k'
39- method_option :domain , required : true , type : :string , aliases : '-d'
40- def add_wildcard_tls ( namespace )
37+ desc 'wildcard-tls' , 'Add wildcard tls from files'
38+ method_option :domain , required : true , type : :string
39+ method_option :cert , required : true , type : :string
40+ method_option :key , required : true , type : :string
41+ method_option :namespace , required : false , type : :string
42+ def add_wildcard_tls
4143 kubectl_exists?
4244
4345 params = {
44- namespace : namespace ,
46+ namespace : options [ : namespace] ,
4547 domain : options [ :domain ] ,
4648 wildcard_cert_path : options [ :cert ] ,
4749 wildcard_key_path : options [ :key ] ,
@@ -111,6 +113,8 @@ def helm_release_list(namespace)
111113 end
112114
113115 def helm_install ( namespace )
116+ Uffizzi . ui . say ( 'Start helm release installation' )
117+
114118 release_name = namespace
115119 cmd = "helm install #{ release_name } #{ HELM_REPO_NAME } /#{ CHART_NAME } " \
116120 " --values #{ helm_values_file_path } " \
@@ -145,25 +149,19 @@ def ask_wildcard_cert
145149 return { wildcard_cert_path : cert_path , wildcard_key_path : key_path }
146150 end
147151
148- add_later = Uffizzi . prompt . yes? ( 'Do you want to add wildcard certificate later?' )
149-
150- if add_later
151- Uffizzi . ui . say ( 'You can set command "uffizzi install add-wildcard-cert [NAMESPACE]' \
152- ' -d your.domain.com -c /path/to/cert -k /path/to/key"' )
152+ Uffizzi . ui . say ( 'Uffizzi does not work properly without a wildcard certificate.' )
153+ Uffizzi . ui . say ( 'You can add wildcard cert later with command:' )
154+ Uffizzi . ui . say ( 'uffizzi install wildcard-tls --domain your.domain.com --cert /path/to/cert --key /path/to/key' )
153155
154- { wildcard_cert_path : nil , wildcard_key_path : nil }
155- else
156- Uffizzi . ui . say ( 'Sorry, but uffizzi can not work correctly without wildcard certificate' )
157- exit ( 0 )
158- end
156+ { wildcard_cert_path : nil , wildcard_key_path : nil }
159157 end
160158
161- def ask_installation_params ( namespace )
159+ def ask_installation_params
162160 wildcard_cert_paths = ask_wildcard_cert
161+ namespace = Uffizzi . prompt . ask ( 'Namespace: ' , required : true , default : DEFAULT_NAMESPACE )
163162 domain = Uffizzi . prompt . ask ( 'Domain: ' , required : true , default : 'example.com' )
164163 user_email = Uffizzi . prompt . ask ( 'User email: ' , required : true , default : "admin@#{ domain } " )
165164 user_password = Uffizzi . prompt . ask ( 'User password: ' , required : true , default : generate_password )
166- controller_password = Uffizzi . prompt . ask ( 'Controller password: ' , required : true , default : generate_password )
167165 cert_email = Uffizzi . prompt . ask ( 'Email address for ACME registration: ' , required : true , default : user_email )
168166 cluster_issuers = [
169167 { name : 'Letsencrypt' , value : 'letsencrypt' } ,
@@ -176,21 +174,21 @@ def ask_installation_params(namespace)
176174 domain : domain ,
177175 user_email : user_email ,
178176 user_password : user_password ,
179- controller_password : controller_password ,
177+ controller_password : generate_password ,
180178 cert_email : cert_email ,
181179 cluster_issuer : cluster_issuer ,
182180 } . merge ( wildcard_cert_paths )
183181 end
184182
185- def validate_installation_options ( namespace , options )
183+ def validate_installation_options
186184 base_params = {
187- namespace : namespace ,
185+ namespace : options [ : namespace] || DEFAULT_NAMESPACE ,
188186 domain : options [ :domain ] ,
189187 user_email : options [ :'user-email' ] || "admin@#{ options [ :domain ] } " ,
190188 user_password : options [ :'user-password' ] || generate_password ,
191189 controller_password : options [ :'controller-password' ] || generate_password ,
192190 cert_email : options [ :'acme-email' ] || options [ :'user-email' ] ,
193- cluster_issuer : options [ :issuer ] ,
191+ cluster_issuer : options [ :issuer ] || DEFAULT_ISSUER ,
194192 wildcard_cert_path : nil ,
195193 wildcard_key_path : nil ,
196194 }
@@ -200,7 +198,7 @@ def validate_installation_options(namespace, options)
200198 empty_key = [ :'wildcard-cert-path' , :'wildcard-key-path' ] . detect { |k | options [ k ] . nil? }
201199
202200 if empty_key . present?
203- return Uffizzi . ui . say_error_and_exit ( "#{ empty_key } is required or use the flag without-wildcard-tls" )
201+ return Uffizzi . ui . say_error_and_exit ( "#{ empty_key } is required or use the flag -- without-wildcard-tls" )
204202 end
205203
206204 wildcard_params = {
0 commit comments