Class: Magellan::Cli::Resources::Authority

Inherits:
Base
  • Object
show all
Defined in:
lib/magellan/cli/resources/authority.rb

Constant Summary

Constants included from FileAccess

FileAccess::DEFAULT_SELECTION_FILENAME

Instance Method Summary collapse

Methods included from FileAccess

ensure_config_dir, load_selection, load_selections, remove_selection_file, selection_filename, update_selections

Methods inherited from Base

command_help, help, log_error, log_info, log_success, log_verbose, log_warning, puts_with_color, sorted_commands, sorted_printable_commands, update_common_help_message

Instance Method Details

#create(project_role, stage_role, stage_type) ⇒ Object



36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
# File 'lib/magellan/cli/resources/authority.rb', line 36

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) ⇒ Object



80
81
82
83
84
85
# File 'lib/magellan/cli/resources/authority.rb', line 80

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) ⇒ Object



71
72
73
74
75
76
77
# File 'lib/magellan/cli/resources/authority.rb', line 71

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) ⇒ Object



29
30
31
32
33
# File 'lib/magellan/cli/resources/authority.rb', line 29

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