class Magellan::Cli::Resources::Authority

Public Instance Methods

create(project_role, stage_role, stage_type) click to toggle source
# File lib/magellan/cli/resources/authority.rb, line 35
def create(project_role, stage_role, stage_type)
  team = load_selection!(Team)
  project = load_selection!(Project)
  unless %w{ owner admin reader }.include?(project_role)
    raise Magellan::Cli::Error, "PROJECT_ROLE must be owner/admin/reader"
  end
  unless %w{ read read_write }.include?(stage_role)
    raise Magellan::Cli::Error, "STAGE_ROLE must be read/read_write"
  end
  unless %w{ development staging production }.include?(stage_type) or /\A\d\z/ =~ stage_type
    raise Magellan::Cli::Error, "STAGE_TYPE must be development/staging/production or 0-9 (single digit)"
  end
  stage_type_map = {
    "development" => 1,
    "staging" => 2,
    "production" => 3,
  }
  (1..9).each do |i| stage_type_map[i.to_s] = i end
  params = {
    parameter_name => {
      "auth_id" => project["id"],
      "auth_type" => "Project",
      "team_id" => team["id"],
      "project_role" => project_role,
      "stage_role" => stage_role,
      "stage_type" => stage_type_map[stage_type],
    }
  }
  ret = post_json("/admin/#{resource_key}/new.js", params)
  if ret and ret["id"]
    select ret["id"]
  end
end
delete(id) click to toggle source
Calls superclass method Magellan::Cli::Base#delete
# File lib/magellan/cli/resources/authority.rb, line 79
def delete(id)
  q = build_query("id" => id).update(default_query)
  r = get_first_result!(self.class.resource_name, id, "/admin/#{resource_key}.json", q)
  super("/admin/#{resource_key}/#{r['id']}/delete.json")
  log_success("OK")
end
select(id) click to toggle source
# File lib/magellan/cli/resources/authority.rb, line 70
def select(id)
  q = build_query("id" => id)
  update_first_result(self.class.parameter_name, id, "/admin/#{resource_key}.json", q)
  update_selections! do |s|
    self.class.deselect_dependants(s)
  end
end
update(attrs) click to toggle source
# File lib/magellan/cli/resources/authority.rb, line 28
def update(attrs)
  s = load_selection!(self.class)
  attrs = JSON.parse(File.readable?(attrs) ? File.read(attrs) : attrs)
  put_json("/admin/#{resource_key}/#{s['id']}/edit.js", {"magellan_auth_authority" => attrs})
end