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.



167
168
169
170
171
172
# File 'lib/enfcli.rb', line 167

def initialize
  @prompt = "enfcli"
  @host = ""
  @user = ""
  @session = nil
end

Instance Attribute Details

#sessionObject

Returns the value of attribute session.



165
166
167
# File 'lib/enfcli.rb', line 165

def session
  @session
end

Instance Method Details

#auth_tokenObject



219
220
221
# File 'lib/enfcli.rb', line 219

def auth_token
  @session[:token]
end

#domain_admin?Boolean

Returns:

  • (Boolean)


185
186
187
# File 'lib/enfcli.rb', line 185

def domain_admin?
  has_role? "DOMAIN_ADMIN"
end

#domain_user?Boolean

Returns:

  • (Boolean)


189
190
191
# File 'lib/enfcli.rb', line 189

def domain_user?
  has_role? "DOMAIN_USER"
end

#edit_domain_role?Boolean

Returns:

  • (Boolean)


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

def edit_domain_role?
  xaptum_admin? || domain_admin?
end

#has_role?(role) ⇒ Boolean

Returns:

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

#hostObject



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

Returns:

  • (Boolean)


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

def network_admin?
  has_role? "NETWORK_ADMIN"
end

#network_user?Boolean

Returns:

  • (Boolean)


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

def network_user?
  has_role? "NETWORK_USER"
end

#promptObject



227
228
229
# File 'lib/enfcli.rb', line 227

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

#userObject



223
224
225
# File 'lib/enfcli.rb', line 223

def user
  @user
end

#xaptum_admin?Boolean

Returns:

  • (Boolean)


181
182
183
# File 'lib/enfcli.rb', line 181

def xaptum_admin?
  has_role? "XAPTUM_ADMIN"
end