Class: EnfCli::CTX

Inherits:
Object
  • Object
show all
Includes:
Singleton
Defined in:
lib/enfcli.rb

Overview

EnfCli Context

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeCTX

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

#sessionObject

Returns the value of attribute session.



176
177
178
# File 'lib/enfcli.rb', line 176

def session
  @session
end

Instance Method Details

#auth_tokenObject



230
231
232
# File 'lib/enfcli.rb', line 230

def auth_token
  @session[:token]
end

#domain_admin?Boolean

Returns:

  • (Boolean)


196
197
198
# File 'lib/enfcli.rb', line 196

def domain_admin?
  has_role? "DOMAIN_ADMIN"
end

#domain_user?Boolean

Returns:

  • (Boolean)


200
201
202
# File 'lib/enfcli.rb', line 200

def domain_user?
  has_role? "DOMAIN_USER"
end

#edit_domain_role?Boolean

Returns:

  • (Boolean)


212
213
214
# File 'lib/enfcli.rb', line 212

def edit_domain_role?
  xaptum_admin? || domain_admin?
end

#has_role?(role) ⇒ Boolean

Returns:

  • (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

#hostObject



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

Returns:

  • (Boolean)


204
205
206
# File 'lib/enfcli.rb', line 204

def network_admin?
  has_role? "NETWORK_ADMIN"
end

#network_user?Boolean

Returns:

  • (Boolean)


208
209
210
# File 'lib/enfcli.rb', line 208

def network_user?
  has_role? "NETWORK_USER"
end

#promptObject



238
239
240
# File 'lib/enfcli.rb', line 238

def prompt
  "\001\033[1;32m\002#{@prompt}>\001\033[0m\002 "
end

#userObject



234
235
236
# File 'lib/enfcli.rb', line 234

def user
  @user
end

#xaptum_admin?Boolean

Returns:

  • (Boolean)


192
193
194
# File 'lib/enfcli.rb', line 192

def xaptum_admin?
  has_role? "XAPTUM_ADMIN"
end