Class: ChefServerSlice::OpenidRegister

Inherits:
Application
  • Object
show all
Defined in:
app/controllers/openid_register.rb

Instance Method Summary collapse

Methods inherited from Application

#absolute_slice_url, #access_denied, #authorized_node, #escape_node_id, #expand_cookbook_deps, #fix_up_node_id, #get_available_recipes, #load_all_files, #load_cookbook_segment, #login_required, #redirect_back_or_default, #segment_files, #specific_cookbooks, #store_location

Instance Method Details

#adminObject



103
104
105
106
107
108
109
110
111
112
# File 'app/controllers/openid_register.rb', line 103

def admin
  begin
    r = Chef::OpenIDRegistration.load(params[:id])
  rescue Exception => e
    raise BadRequest, "Cannot find the registration for #{params[:id]}"
  end
  r.admin = r.admin ? false : true
  r.save
  redirect slice_url(:registrations)
end

#createObject



52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
# File 'app/controllers/openid_register.rb', line 52

def create
  params.has_key?(:id) or raise BadRequest, "You must provide an id to register"
  params.has_key?(:password) or raise BadRequest, "You must provide a password to register"
  if Chef::OpenIDRegistration.has_key?(params[:id])
    raise BadRequest, "You cannot re-register #{params[:id]}!"
  end
  @registered_node = Chef::OpenIDRegistration.new
  @registered_node.name = params[:id]
  @registered_node.set_password(params[:password])
  if Chef::Config[:validation_token]
    if params[:validation_token] == Chef::Config[:validation_token]
      @registered_node.validated = true
    else
      @registered_node.validated = false
    end
  else
    @registered_node.validated = false
  end
  @registered_node.save
  display @registered_node
end

#destroyObject



78
79
80
81
82
83
84
85
86
87
88
89
90
# File 'app/controllers/openid_register.rb', line 78

def destroy
  begin
    r = Chef::OpenIDRegistration.load(params[:id])
  rescue Exception => e
    raise BadRequest, "Cannot find the registration for #{params[:id]}"
  end
  r.destroy
  if content_type == :html
    redirect slice_url(:registrations)
  else
    display({ :message => "Deleted registration for #{params[:id]}"})
  end
end

#indexObject



31
32
33
34
35
36
# File 'app/controllers/openid_register.rb', line 31

def index
  @headers['X-XRDS-Location'] = Chef::Config[:openid_url] + "/openid/server/server/xrds"
  @registered_nodes = Chef::OpenIDRegistration.list(true)
  Chef::Log.debug(@registered_nodes.inspect)
  display @registered_nodes
end

#showObject



38
39
40
41
42
43
44
45
46
47
48
49
50
# File 'app/controllers/openid_register.rb', line 38

def show
  begin
    @registered_node = Chef::OpenIDRegistration.load(params[:id])
  rescue Net::HTTPServerException => e
    if e.message =~ /^404/
      raise NotFound, "Cannot load node registration for #{params[:id]}"
    else
      raise e
    end
  end
   Chef::Log.debug(@registered_node.inspect)
   display @registered_node
end

#updateObject

Raises:

  • (BadRequest)


74
75
76
# File 'app/controllers/openid_register.rb', line 74

def update
  raise BadRequest, "You cannot update your registration -- delete #{params[:id]} and re-register"
end

#validateObject



92
93
94
95
96
97
98
99
100
101
# File 'app/controllers/openid_register.rb', line 92

def validate
  begin
    r = Chef::OpenIDRegistration.load(params[:id])
  rescue Exception => e
    raise BadRequest, "Cannot find the registration for #{params[:id]}"
  end
  r.validated = r.validated ? false : true
  r.save
  redirect slice_url(:registrations)
end