Module: PeRbac::Action

Defined in:
lib/pe_rbac/action.rb

Class Method Summary collapse

Class Method Details

.login(login, password, lifetime = false) ⇒ Object



42
43
44
45
46
47
48
49
50
# File 'lib/pe_rbac/action.rb', line 42

def self.(, password, lifetime=false)
  dirname = Dir.home + '/.puppetlabs'
  tokenfile = dirname + '/token'
  if ! Dir.exist?(dirname)
    Dir.mkdir(dirname, 0700)
  end
  File.write(tokenfile, token(, password, lifetime))
  File.chmod(0600, tokenfile)
end

.reset_password(login, password) ⇒ Object



52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
# File 'lib/pe_rbac/action.rb', line 52

def self.reset_password(, password)
  # lookup user id
  user_id = User::get_user_id()
  status = false
  if user_id
    # get password reset token
    reset_token = PeRbac::Core::request(:post, "/users/#{user_id}/password/reset").body

    # reset password
    PeRbac::Core::request(:post, '/auth/reset', {
      'token'     => reset_token,
      'password'  => password,
    })
    status = true
  end
  status
end

.show_permissionsObject



70
71
72
73
# File 'lib/pe_rbac/action.rb', line 70

def self.show_permissions
  resp = PeRbac::Permission::get_permissions
  puts JSON.pretty_generate(resp)
end

.token(login, password, lifetime = false) ⇒ Object

Token



28
29
30
31
32
33
34
35
36
37
38
39
40
# File 'lib/pe_rbac/action.rb', line 28

def self.token(, password, lifetime=false)
  payload = {
    "login"     => ,
    "password"  => password,
  }

  # see https://docs.puppet.com/pe/latest/rbac_token_auth.html#setting-a-token-specific-lifetime
  if lifetime
    payload["lifetime"] = lifetime
  end
  resp = PeRbac::Core::request(:post, '/auth/token', payload)
  resp ? JSON.parse(resp.body)['token'] : false
end