Class: MrMurano::ServiceConfig

Inherits:
SolutionBase show all
Defined in:
lib/MrMurano/Solution-ServiceConfig.rb

Overview

…/serviceconfig

Constant Summary

Constants included from Verbose

Verbose::TABULARIZE_DATA_FORMAT_ERROR

Constants included from SolutionId

MrMurano::SolutionId::INVALID_API_ID, MrMurano::SolutionId::UNEXPECTED_TYPE_OR_ERROR_MSG

Constants included from AccountBase

AccountBase::LOGIN_ADVICE, AccountBase::LOGIN_NOTICE

Instance Attribute Summary

Attributes included from SolutionId

#api_id, #sid, #valid_api_id

Instance Method Summary collapse

Methods inherited from SolutionBase

#==, #endpoint

Methods included from SyncUpDown

#config_vars_decode, #config_vars_encode, #debug_print_localitems, #diff_download, #diff_item_write, #docmp, #download, #ignore?, #ignoring, #localitems, #locallist, #locallist_add_item, #locallist_complain_missing, #locallist_mark_seen, #location, #match, #remove_or_clear, #removelocal, #resolve_config_var_usage!, #resurrect_undeletables, #searchFor, #syncdown_after, #syncdown_before, #synckey, #syncup_after, #syncup_before, #to_remote_items, #tolocalname, #tolocalpath, #update_mtime, #upload

Methods included from Verbose

ask_yes_no, #ask_yes_no, #assert, assert, cmd_confirm_delete!, #cmd_confirm_delete!, debug, #debug, dump_file_json, dump_file_plain, dump_file_yaml, #dump_output_file, #error, error, #error_file_format!, fancy_ticks, #fancy_ticks, #load_file_json, #load_file_plain, #load_file_yaml, #load_input_file, outf, #outf, #outformat_engine, #pluralize?, pluralize?, #prepare_hash_csv, #read_hashf!, #tabularize, tabularize, verbose, #verbose, warning, #warning, #whirly_interject, whirly_interject, #whirly_linger, whirly_linger, #whirly_msg, whirly_msg, #whirly_pause, whirly_pause, #whirly_start, whirly_start, #whirly_stop, whirly_stop, #whirly_unpause, whirly_unpause

Methods included from SyncCore

#debug_selected, #dodiff, #dodiff_build_cmd, #dodiff_cull_tempfile_paths, #dodiff_do_diff, #dodiff_download_remote, #dodiff_flexible, #dodiff_header_aware, #dodiff_local_to_tempfile, #dodiff_prepare_local_and_diff, #dodiff_resolve_localname, #dodiff_tempfile_paths, #filter_solution, #init_mods_and_chgs_arrs, #item_dirty_set_status, #item_local_there_merged, #item_merged_diff_status, #item_merged_set_status, #item_select_selected!, #items_classify_and_find_duplicates, #items_cull_clashes!, #items_lists, #items_log_duplicates, #items_log_duplicates_there_local, #items_mods_and_chgs!, #items_new_and_old!, #select_selected!, #sort_by_name, #status, #sync_update_progress, #syncable_validate_api_id, #syncdown, #syncdown_item, #syncup, #syncup_item

Methods included from SyncAllowed

#download_item_allowed, #remove_item_allowed, #removelocal_item_allowed, #sync_item_allowed, #upload_item_allowed

Methods included from SolutionId

#affirm_valid, #api_id?, #endpoint, #init_api_id!, #valid_api_id?

Methods included from AccountBase

#add_headers, #ask_for_password!, #ask_for_user!, #cfg_clear_user_and_business, #credentials_reset, #get, #invalidate_token, #login_info, #logout, #must_prompt_if_logged_off!, #token, #token_reset, #verify_cfg_auth!, #verify_cfg_auth_persist, #verify_cfg_auth_scheme!, #verify_cfg_auth_ttl, #verify_set, warn_configfile_env_maybe

Methods included from Http

#add_headers, #curldebug, curldebug_after, curldebug_elapsed, curldebug_log, #delete, #endpoint, #get, #host, #http, #http_reset, #isJSON, #json_opts, #patch, #post, #postf, #put, #showHttpError, #user, #workit, #workit_response

Constructor Details

#initialize(api_id = nil) ⇒ ServiceConfig

Returns a new instance of ServiceConfig.



13
14
15
16
17
# File 'lib/MrMurano/Solution-ServiceConfig.rb', line 13

def initialize(api_id=nil)
  super
  @uriparts << :serviceconfig
  @scid = nil
end

Instance Method Details

#call(opid, meth = :get, data = nil, id = scid, &block) ⇒ Object



96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
# File 'lib/MrMurano/Solution-ServiceConfig.rb', line 96

def call(opid, meth=:get, data=nil, id=scid, &block)
  must_id! id
  call = "/#{id}/call/#{opid}"
  debug "Will call: #{call}"
  case meth
  when :get
    get(call, data, &block)
  when :post
    data = {} if data.nil?
    post(call, data, &block)
  when :put
    data = {} if data.nil?
    put(call, data, &block)
  when :delete
    delete(call, &block)
  else
    raise "Unknown method: #{meth}"
  end
end

#create(pid, name = nil, &block) ⇒ Object



60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
# File 'lib/MrMurano/Solution-ServiceConfig.rb', line 60

def create(pid, name=nil, &block)
  name = pid if name.to_s.empty?
  raise 'Missing name/script_key?' if name.to_s.empty?
  # See pegasus_registry PostServiceConfig for the POST properties.
  #   pegasus_registry/api/swagger/paths/serviceconfig.yaml
  #   pegasus_registry/api/swagger/definitions/serviceconfig.yaml
  post(
    '/',
    {
      solution_id: @api_id,
      service: pid,
      # 2017-06-26: "name" seems to work, but "script_key" is what web UI uses.
      #   See yeti-ui/bridge/src/js/api/services.js::linkApplicationService
      #name: name,
      script_key: name,
    },
    &block
  )
end

#fetch(id, _untainted = false, &block) ⇒ Object



34
35
36
37
# File 'lib/MrMurano/Solution-ServiceConfig.rb', line 34

def fetch(id, _untainted=false, &block)
  must_id! id
  get('/' + id.to_s, &block)
end

#info(id = scid, &block) ⇒ Object



86
87
88
89
# File 'lib/MrMurano/Solution-ServiceConfig.rb', line 86

def info(id=scid, &block)
  must_id! id
  get("/#{id}/info", &block)
end

#list(call = nil, data = nil, &block) ⇒ Object



19
20
21
22
23
24
# File 'lib/MrMurano/Solution-ServiceConfig.rb', line 19

def list(call=nil, data=nil, &block)
  ret = get(call, data, &block)
  return [] unless ret.is_a?(Hash) && !ret.key?(:error)
  return [] unless ret.key?(:items)
  ret[:items]
end

#logs(id = scid, &block) ⇒ Object



91
92
93
94
# File 'lib/MrMurano/Solution-ServiceConfig.rb', line 91

def logs(id=scid, &block)
  must_id! id
  get("/#{id}/logs", &block)
end

#must_id!(id) ⇒ Object



39
40
41
42
43
44
45
46
# File 'lib/MrMurano/Solution-ServiceConfig.rb', line 39

def must_id!(id)
  return unless id.nil?
  service_missing_msg = %(
    The #{fancy_ticks(@service_name)} service is not enabled for this Solution
  ).strip
  warning "#{service_missing_msg}, or the Solution ID is missing."
  exit 1
end

#remove(id, &block) ⇒ Object



80
81
82
83
84
# File 'lib/MrMurano/Solution-ServiceConfig.rb', line 80

def remove(id, &block)
  must_id! id
  return unless remove_item_allowed(id)
  delete("/#{id}", &block)
end

#scidObject



55
56
57
58
# File 'lib/MrMurano/Solution-ServiceConfig.rb', line 55

def scid
  return @scid unless @scid.nil?
  @scid = scid_for_name(@service_name)
end

#scid_for_name(name) ⇒ Object



48
49
50
51
52
53
# File 'lib/MrMurano/Solution-ServiceConfig.rb', line 48

def scid_for_name(name)
  name = name.to_s unless name.is_a? String
  scr = list.select { |i| i[:service] == name }.first
  return nil if scr.nil?
  scr[:id]
end

#search(svc_name) ⇒ Object



26
27
28
29
30
31
32
# File 'lib/MrMurano/Solution-ServiceConfig.rb', line 26

def search(svc_name)
  #path = nil
  path = '?select=id,service,script_key'
  # 2017-07-02: This is what yeti-ui queries on:
  #path = '?select=service,id,solution_id,script_key,alias'
  super(svc_name, path)
end