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.
167 168 169 170 171 172 |
# File 'lib/enfcli.rb', line 167 def initialize @prompt = "enfcli" @host = "" @user = "" @session = nil end |
Instance Attribute Details
#session ⇒ Object
Returns the value of attribute session.
165 166 167 |
# File 'lib/enfcli.rb', line 165 def session @session end |
Instance Method Details
#auth_token ⇒ Object
219 220 221 |
# File 'lib/enfcli.rb', line 219 def auth_token @session[:token] end |
#domain_admin? ⇒ Boolean
185 186 187 |
# File 'lib/enfcli.rb', line 185 def domain_admin? has_role? "DOMAIN_ADMIN" end |
#domain_user? ⇒ Boolean
189 190 191 |
# File 'lib/enfcli.rb', line 189 def domain_user? has_role? "DOMAIN_USER" end |
#edit_domain_role? ⇒ Boolean
201 202 203 |
# File 'lib/enfcli.rb', line 201 def edit_domain_role? xaptum_admin? || domain_admin? end |
#has_role?(role) ⇒ Boolean
205 206 207 208 209 210 211 212 213 |
# File 'lib/enfcli.rb', line 205 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
215 216 217 |
# File 'lib/enfcli.rb', line 215 def host @host.to_s end |
#init(host, user, session) ⇒ Object
174 175 176 177 178 179 |
# File 'lib/enfcli.rb', line 174 def init(host, user, session) @host = host @user = user @session = session @prompt = "enfcli-#{user}" if user end |
#network_admin? ⇒ Boolean
193 194 195 |
# File 'lib/enfcli.rb', line 193 def network_admin? has_role? "NETWORK_ADMIN" end |
#network_user? ⇒ Boolean
197 198 199 |
# File 'lib/enfcli.rb', line 197 def network_user? has_role? "NETWORK_USER" end |
#prompt ⇒ Object
227 228 229 |
# File 'lib/enfcli.rb', line 227 def prompt "\001\033[1;32m\002#{@prompt}>\001\033[0m\002 " end |
#user ⇒ Object
223 224 225 |
# File 'lib/enfcli.rb', line 223 def user @user end |
#xaptum_admin? ⇒ Boolean
181 182 183 |
# File 'lib/enfcli.rb', line 181 def xaptum_admin? has_role? "XAPTUM_ADMIN" end |