Class: EnfCli::CTX
Overview
EnfCli Context
Instance Attribute Summary collapse
-
#session ⇒ Object
Returns the value of attribute session.
Instance Method Summary collapse
- #auth_token ⇒ Object
- #domain_admin? ⇒ Boolean
- #domain_user? ⇒ Boolean
- #edit_domain_role? ⇒ Boolean
- #has_role?(role) ⇒ Boolean
- #host ⇒ Object
- #init(host, user, session) ⇒ Object
-
#initialize ⇒ CTX
constructor
A new instance of CTX.
- #network_admin? ⇒ Boolean
- #network_user? ⇒ Boolean
- #prompt ⇒ Object
- #user ⇒ Object
- #xaptum_admin? ⇒ Boolean
Constructor Details
#initialize ⇒ CTX
Returns a new instance of CTX.
178 179 180 181 182 183 |
# File 'lib/enfcli.rb', line 178 def initialize @prompt = "enfcli" @host = "" @user = "" @session = nil end |
Instance Attribute Details
#session ⇒ Object
Returns the value of attribute session.
176 177 178 |
# File 'lib/enfcli.rb', line 176 def session @session end |
Instance Method Details
#auth_token ⇒ Object
230 231 232 |
# File 'lib/enfcli.rb', line 230 def auth_token @session[:token] end |
#domain_admin? ⇒ Boolean
196 197 198 |
# File 'lib/enfcli.rb', line 196 def domain_admin? has_role? "DOMAIN_ADMIN" end |
#domain_user? ⇒ Boolean
200 201 202 |
# File 'lib/enfcli.rb', line 200 def domain_user? has_role? "DOMAIN_USER" end |
#edit_domain_role? ⇒ Boolean
212 213 214 |
# File 'lib/enfcli.rb', line 212 def edit_domain_role? xaptum_admin? || domain_admin? end |
#has_role?(role) ⇒ Boolean
216 217 218 219 220 221 222 223 224 |
# File 'lib/enfcli.rb', line 216 def has_role?(role) all_roles = @session[:roles] all_roles.each do |cur_role| if cur_role[:role] == role return true end end false end |
#host ⇒ Object
226 227 228 |
# File 'lib/enfcli.rb', line 226 def host @host.to_s end |
#init(host, user, session) ⇒ Object
185 186 187 188 189 190 |
# File 'lib/enfcli.rb', line 185 def init(host, user, session) @host = host @user = user @session = session @prompt = "enfcli-#{user}" if user end |
#network_admin? ⇒ Boolean
204 205 206 |
# File 'lib/enfcli.rb', line 204 def network_admin? has_role? "NETWORK_ADMIN" end |
#network_user? ⇒ Boolean
208 209 210 |
# File 'lib/enfcli.rb', line 208 def network_user? has_role? "NETWORK_USER" end |
#prompt ⇒ Object
238 239 240 |
# File 'lib/enfcli.rb', line 238 def prompt "\001\033[1;32m\002#{@prompt}>\001\033[0m\002 " end |
#user ⇒ Object
234 235 236 |
# File 'lib/enfcli.rb', line 234 def user @user end |
#xaptum_admin? ⇒ Boolean
192 193 194 |
# File 'lib/enfcli.rb', line 192 def xaptum_admin? has_role? "XAPTUM_ADMIN" end |