class DeisWorkflow::Client

Public Class Methods

login(username, password, uri) click to toggle source

returns an api_key for that user

# File lib/deis-workflow.rb, line 16
def self.login(username, password, uri)
  HTTParty.post(
    "#{uri}/v2/auth/login/",
    :body => JSON.dump({
      :username => username,
      :password => password
    }),
    :headers => { 'Content-Type' => 'application/json' }
  ).parsed_response['token']
end
new(uri, api_key) click to toggle source
# File lib/deis-workflow.rb, line 9
def initialize(uri, api_key)
  @api_key = api_key
  @controller_uri = uri
  @headers = { 'Authorization' => 'token %s' % @api_key, 'Content-Type' => 'application/json' }
end

Public Instance Methods

app_create(app_name) click to toggle source
# File lib/deis-workflow.rb, line 60
def app_create(app_name)
  post("/v2/apps", {
    :id => app_name
  }).success?
end
app_exists?(app_name) click to toggle source
# File lib/deis-workflow.rb, line 56
def app_exists?(app_name)
  get("#{app_path(app_name)}").success?
end
app_limit_set(app_name, limit_type, pod_type, limit) click to toggle source
# File lib/deis-workflow.rb, line 120
def app_limit_set(app_name, limit_type, pod_type, limit)
  return false unless %w(memory cpu).include?(limit_type)
  post("#{app_path(app_name)}/config/", {
    limit_type => { pod_type => limit }
  }).success?
end
app_limit_unset(app_name, limit_type, pod_type) click to toggle source
# File lib/deis-workflow.rb, line 127
def app_limit_unset(app_name, limit_type, pod_type)
  return false unless %w(memory cpu).include?(limit_type)
  post("#{app_path(app_name)}/config/", {
    limit_type => { pod_type => nil }
  }).success?
end
app_list_pods(app_name) click to toggle source
# File lib/deis-workflow.rb, line 82
def app_list_pods(app_name)
  get("#{app_path(app_name)}/pods/").parsed_response
end
app_logs(app_name) click to toggle source
# File lib/deis-workflow.rb, line 66
def app_logs(app_name)
  get("#{app_path(app_name)}/logs/").parsed_response
end
app_releases(app_name) click to toggle source
# File lib/deis-workflow.rb, line 70
def app_releases(app_name)
  get("#{app_path(app_name)}/releases").parsed_response
end
app_restart(app_name) click to toggle source
# File lib/deis-workflow.rb, line 86
def app_restart(app_name)
  post("#{app_path(app_name)}/pods/restart/").success?
end
app_scale(app_name, pod_type, desired_pod_count) click to toggle source

App pod related methods

# File lib/deis-workflow.rb, line 76
def app_scale(app_name, pod_type, desired_pod_count)
  post("#{app_path(app_name)}/scale/", {
    pod_type.to_sym => desired_pod_count
  }).success?
end
apps_list_all() click to toggle source

App level methods

# File lib/deis-workflow.rb, line 52
def apps_list_all
  get("/v2/apps").parsed_response
end
config_list(app_name) click to toggle source

App config methods

# File lib/deis-workflow.rb, line 108
def config_list(app_name)
  get("#{app_path(app_name)}/config/").parsed_response['values']
end
config_set(app_name, values) click to toggle source

values should be a hash unset by assigning values to nil

# File lib/deis-workflow.rb, line 114
def config_set(app_name, values)
  post("#{app_path(app_name)}/config/", {
    :values => values
  }).success?
end
perms_create(app_name, username) click to toggle source

App permissions methods

# File lib/deis-workflow.rb, line 92
def perms_create(app_name, username)
  post("#{app_path(app_name)}/perms/", {
    :username => username
  }).success?
end
perms_delete(app_name, username) click to toggle source
# File lib/deis-workflow.rb, line 98
def perms_delete(app_name, username)
  delete("#{app_path(app_name)}/perms/#{username}/").success?
end
perms_list(app_name) click to toggle source
# File lib/deis-workflow.rb, line 102
def perms_list(app_name)
  get("#{app_path(app_name)}/perms/").parsed_response['users']
end
register(username, email) click to toggle source

registers a new user to the cluster returns a generated password

# File lib/deis-workflow.rb, line 39
def register(username, email)
  password = SecureRandom.urlsafe_base64
  post('/v2/auth/register/', {
    :username => username,
    :password => password,
    :email    => email
  })
  # TODO handle the same user registering twice
  password
end
users_list() click to toggle source
# File lib/deis-workflow.rb, line 33
def users_list
  get('/v2/users').parsed_response['results']
end
whoami() click to toggle source

Cluster level methods

# File lib/deis-workflow.rb, line 29
def whoami
  get('/v2/auth/whoami').parsed_response['username']
end

Private Instance Methods

app_path(app_name) click to toggle source
# File lib/deis-workflow.rb, line 137
def app_path(app_name)
  "/v2/apps/#{app_name}"
end
delete(path) click to toggle source
# File lib/deis-workflow.rb, line 156
def delete(path)
  HTTParty.post(
    "#{@controller_uri}#{path}",
    :headers => @headers
  )
end
get(path) click to toggle source
# File lib/deis-workflow.rb, line 141
def get(path)
  HTTParty.get(
    "#{@controller_uri}#{path}",
    :headers => @headers
  )
end
post(path, body = nil) click to toggle source
# File lib/deis-workflow.rb, line 148
def post(path, body = nil)
  HTTParty.post(
    "#{@controller_uri}#{path}",
    :body => JSON.dump(body),
    :headers => @headers
  )
end