Class: Solano::ApiConfig
- Inherits:
-
Object
- Object
- Solano::ApiConfig
- Includes:
- SolanoConstant
- Defined in:
- lib/solano/cli/config.rb
Instance Attribute Summary collapse
-
#cli_options ⇒ Object
readonly
Returns the value of attribute cli_options.
-
#config ⇒ Object
readonly
Returns the value of attribute config.
Instance Method Summary collapse
- #delete_suite(branch, account = nil) ⇒ Object
- #get_api_key(options = {}) ⇒ Object
- #get_branch(branch, var, options = {}) ⇒ Object
-
#initialize(scm, tddium_client, host, cli_options) ⇒ ApiConfig
constructor
BOTCH: should be a state object rather than entire CLI object.
- #load_config(options = {}) ⇒ Object
- #logout ⇒ Object
- #populate_branches(branch) ⇒ Object
- #scm_ready_sleep ⇒ Object
-
#set_api(solano_api) ⇒ Object
BOTCH: fugly.
- #set_api_key(api_key, user) ⇒ Object
- #set_suite(suite) ⇒ Object
- #solano_deploy_key_file_name ⇒ Object
- #solano_file_name(scope = :repo, kind = '', root = nil) ⇒ Object
- #write_config ⇒ Object
- #write_scm_ignore ⇒ Object
Constructor Details
#initialize(scm, tddium_client, host, cli_options) ⇒ ApiConfig
BOTCH: should be a state object rather than entire CLI object
81 82 83 84 85 86 87 |
# File 'lib/solano/cli/config.rb', line 81 def initialize(scm, tddium_client, host, ) @scm = scm @tddium_client = tddium_client @host = host @cli_options = @config = Hash.new end |
Instance Attribute Details
#cli_options ⇒ Object (readonly)
Returns the value of attribute cli_options.
78 79 80 |
# File 'lib/solano/cli/config.rb', line 78 def @cli_options end |
#config ⇒ Object (readonly)
Returns the value of attribute config.
78 79 80 |
# File 'lib/solano/cli/config.rb', line 78 def config @config end |
Instance Method Details
#delete_suite(branch, account = nil) ⇒ Object
144 145 146 147 148 149 |
# File 'lib/solano/cli/config.rb', line 144 def delete_suite(branch, account=nil) branches = @config["branches"] || {} branches.delete_if do |k, v| v['branch'] == branch && (account.nil? || v['account'] == account) end end |
#get_api_key(options = {}) ⇒ Object
118 119 120 |
# File 'lib/solano/cli/config.rb', line 118 def get_api_key( = {}) .any? ? load_config()['api_key'] : @config['api_key'] end |
#get_branch(branch, var, options = {}) ⇒ Object
105 106 107 108 109 110 111 112 113 114 115 116 |
# File 'lib/solano/cli/config.rb', line 105 def get_branch(branch, var, ={}) if ['account'].nil? && @cli_options[:account] then ['account'] = @cli_options[:account] end val = fetch_branch(branch, var, ) return val unless val.nil? populate_branches(branch) return fetch_branch(branch, var, ) end |
#load_config(options = {}) ⇒ Object
151 152 153 154 155 156 157 158 159 |
# File 'lib/solano/cli/config.rb', line 151 def load_config( = {}) global_config = load_config_from_file(:global) return global_config if [:global] repo_config = load_config_from_file return repo_config if [:repo] @config = global_config.merge(repo_config) end |
#logout ⇒ Object
94 95 96 |
# File 'lib/solano/cli/config.rb', line 94 def logout remove_solano_files end |
#populate_branches(branch) ⇒ Object
98 99 100 101 102 103 |
# File 'lib/solano/cli/config.rb', line 98 def populate_branches(branch) suites = @solano_api.get_suites(:repo_url => @scm.origin_url, :branch=>branch) suites.each do |ste| set_suite(ste) end end |
#scm_ready_sleep ⇒ Object
126 127 128 129 |
# File 'lib/solano/cli/config.rb', line 126 def scm_ready_sleep s = ENV["SOLANO_SCM_READY_SLEEP"] || Default::SCM_READY_SLEEP s.to_f end |
#set_api(solano_api) ⇒ Object
BOTCH: fugly
90 91 92 |
# File 'lib/solano/cli/config.rb', line 90 def set_api(solano_api) @solano_api = solano_api end |
#set_api_key(api_key, user) ⇒ Object
122 123 124 |
# File 'lib/solano/cli/config.rb', line 122 def set_api_key(api_key, user) @config['api_key'] = api_key end |
#set_suite(suite) ⇒ Object
131 132 133 134 135 136 137 138 139 140 141 142 |
# File 'lib/solano/cli/config.rb', line 131 def set_suite(suite) id = suite['id'] branch = suite['branch'] return if id.nil? || branch.nil? || branch.empty? keys = %w(id branch account repo_id ci_ssh_pubkey) = keys.inject({}) { |h, v| h[v] = suite[v]; h } branches = @config["branches"] || {} branches.merge!({id => }) @config.merge!({"branches" => branches}) end |
#solano_deploy_key_file_name ⇒ Object
213 214 215 |
# File 'lib/solano/cli/config.rb', line 213 def solano_deploy_key_file_name return solano_file_name(:repo, '-deploy-key') end |
#solano_file_name(scope = :repo, kind = '', root = nil) ⇒ Object
199 200 201 202 203 204 205 206 207 208 209 210 211 |
# File 'lib/solano/cli/config.rb', line 199 def solano_file_name(scope=:repo, kind='', root=nil) ext = (@host == 'ci.predix.io') ? '' : ".#{@host}" case scope when :repo root ||= @scm.repo? ? @scm.root : Dir.pwd when :global root = ENV['HOME'] end return File.join(root, ".predix-ci#{kind}#{ext}") end |
#write_config ⇒ Object
161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 |
# File 'lib/solano/cli/config.rb', line 161 def write_config path = solano_file_name(:global) File.open(path, File::CREAT|File::TRUNC|File::RDWR, 0600) do |file| config = Hash.new config['api_key'] = @config['api_key'] if @config.member?('api_key') file.write(config.to_json) end path = solano_file_name(:repo) File.open(path, File::CREAT|File::TRUNC|File::RDWR, 0600) do |file| file.write(@config.to_json) end if @scm.repo? then branch = @scm.current_branch id = get_branch(branch, 'id', {}) suite = @config['branches'][id] rescue nil if suite then path = solano_deploy_key_file_name File.open(path, File::CREAT|File::TRUNC|File::RDWR, 0644) do |file| file.write(suite["ci_ssh_pubkey"]) end end write_scm_ignore # BOTCH: no need to write every time end end |
#write_scm_ignore ⇒ Object
189 190 191 192 193 194 195 196 197 |
# File 'lib/solano/cli/config.rb', line 189 def write_scm_ignore path = @scm.ignore_path content = File.exists?(path) ? File.read(path) : '' unless content.include?(".predix-ci*\n") File.open(path, File::CREAT|File::APPEND|File::RDWR, 0644) do |file| file.write(".predix-ci*\n") end end end |