Class: RedhatAccess::StrataCredentialsController

Inherits:
ApplicationController show all
Defined in:
app/controllers/redhat_access/strata_credentials_controller.rb

Instance Method Summary collapse

Instance Method Details

#createObject



21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
# File 'app/controllers/redhat_access/strata_credentials_controller.rb', line 21

def create
  if TelemetryProxyCredentials.count != 0
    TelemetryProxyCredentials.delete_all
  end

  creds = TelemetryProxyCredentials.new

  data = params[:strata_credential]
  username = data[:username]
  password = data[:password]

  if not username.present? && username.length > 1
    render json: { :status => 'error', :message => 'username missing or too short' }, status: 400
    return
  end

  if not password.present? && password.length > 4
    render json: { :status => 'error', :message => 'password missing or too short' }, status: 400
    return
  end

  creds.attributes = { username: username, password: password }
  creds.save

  render json: { :status => 'success', :message => 'credentials saved' }
end

#destroyObject



16
17
18
19
# File 'app/controllers/redhat_access/strata_credentials_controller.rb', line 16

def destroy
  TelemetryProxyCredentials.delete_all
  render json: { :status => 'success' }
end

#indexObject



6
7
8
9
10
11
12
13
14
# File 'app/controllers/redhat_access/strata_credentials_controller.rb', line 6

def index
  if TelemetryProxyCredentials.count == 0
    render json: { :status => 'not_found' }, status: 404
    return
  end

  creds = TelemetryProxyCredentials.limit(1)[0]
  render json: { :status => 'success', :username => creds.username }
end