Class: Octo::Authorization

Inherits:
Object
  • Object
show all
Includes:
Cequel::Record, Helpers::KongHelper
Defined in:
lib/octocore-cassandra/models/enterprise/authorization.rb

Constant Summary

Constants included from Helpers::KongHelper

Helpers::KongHelper::KONG_URL

Constants included from Cequel::Record

Cequel::Record::DUMP_ATTRS

Instance Method Summary collapse

Methods included from Helpers::KongHelper

#add_ratelimiting_plugin, #apislist, #consumerlist, #create_keyauth, #delete_api, #delete_consumer, #kong_url, #process_kong_request

Methods included from Cequel::Record

#marshal_dump, #marshal_load, redis, update_cache_config

Instance Method Details

#check_api_keyObject

Check or Generate client apikey



28
29
30
31
32
# File 'lib/octocore-cassandra/models/enterprise/authorization.rb', line 28

def check_api_key
  if(self.apikey.nil?)
    self.apikey = SecureRandom.hex
  end
end

#generate_passwordObject

Check or Generate client password



35
36
37
38
39
40
41
# File 'lib/octocore-cassandra/models/enterprise/authorization.rb', line 35

def generate_password
  if(self.password.nil?)
    self.password = Digest::SHA1.hexdigest(self.username + self.enterprise_id)
  else
    self.password = Digest::SHA1.hexdigest(self.password + self.enterprise_id)
  end
end

#kong_deleteObject

Delete Kong Records



59
60
61
62
63
64
# File 'lib/octocore-cassandra/models/enterprise/authorization.rb', line 59

def kong_delete
  kong_config = Octo.get_config :kong
  if kong_config[:enabled]
    delete_consumer(self.username)
  end
end

#kong_requestsObject

Perform Kong Operations after creating client



44
45
46
47
48
49
50
51
52
53
54
55
56
# File 'lib/octocore-cassandra/models/enterprise/authorization.rb', line 44

def kong_requests
  kong_config = Octo.get_config :kong
  if kong_config[:enabled]
    url = '/consumers/'
    payload = {
      username: self.username,
      custom_id: self.enterprise_id
    }

    process_kong_request(url, :PUT, payload)
    create_keyauth( self.username, self.apikey)
  end
end