Class: RubyConcourse::Fly
- Inherits:
-
Object
- Object
- RubyConcourse::Fly
- Defined in:
- lib/ruby_concourse.rb
Instance Method Summary collapse
-
#initialize(env_directory_path) ⇒ Fly
constructor
A new instance of Fly.
- #load_variables(env) ⇒ Object
- #login(env, team) ⇒ Object
- #pause_job(env, team, pipeline, target) ⇒ Object
- #show_environments ⇒ Object
- #show_pipelines(env, team) ⇒ Object
- #sync_concourse(target) ⇒ Object
- #unpause_job(env, team, pipeline, target) ⇒ Object
- #update_pipeline(env, team, pipeline, credentials_file, pipeline_configuration_file) ⇒ Object
- #web_login(env, concourse_login_url) ⇒ Object
Constructor Details
#initialize(env_directory_path) ⇒ Fly
Returns a new instance of Fly.
10 11 12 |
# File 'lib/ruby_concourse.rb', line 10 def initialize(env_directory_path) @env_directory_path = env_directory_path end |
Instance Method Details
#load_variables(env) ⇒ Object
25 26 27 |
# File 'lib/ruby_concourse.rb', line 25 def load_variables(env) return JSON.parse(File.read("#{@env_directory_path}/#{env}.json")) end |
#login(env, team) ⇒ Object
93 94 95 96 97 98 99 100 101 102 103 104 105 |
# File 'lib/ruby_concourse.rb', line 93 def login(env, team) var = load_variables(env) target = "#{env}-#{team}" command = "fly -t #{target} login -n #{team} -c #{var['url']}" IO.popen(command, "r+") do |pipe| pipe.gets pipe.gets concourse_login_url = pipe.gets.gsub(/\s+/, "") print "Attempting login to #{concourse_login_url}: " web_login(env, concourse_login_url) sync_concourse(target) end end |
#pause_job(env, team, pipeline, target) ⇒ Object
34 35 36 37 |
# File 'lib/ruby_concourse.rb', line 34 def pause_job(env, team, pipeline, target) command = `fly -t #{env}-#{team} pause-job -j #{pipeline}/#{target}` puts command end |
#show_environments ⇒ Object
14 15 16 17 18 19 20 21 22 23 |
# File 'lib/ruby_concourse.rb', line 14 def show_environments puts 'Available Environments:' puts '-----------------------' files = Dir.glob("#{@env_directory_path}/*.json").each files.each do |file| filename = File.basename(file).sub('.json', '') puts filename end puts '' end |
#show_pipelines(env, team) ⇒ Object
44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 |
# File 'lib/ruby_concourse.rb', line 44 def show_pipelines(env, team) var = load_variables(env) target = "#{env}-#{team}" pipelines = `fly -t #{target} pipelines`.split(pattern="\n") puts '' puts 'Available Pipelines' puts '-------------------' pipelines.each do |pipeline| info = pipeline.split(pattern=" ") puts "Name: #{info[0]}" puts "Paused: #{info[1]}" puts "Public: #{info[2]}" puts '' end end |
#sync_concourse(target) ⇒ Object
29 30 31 32 |
# File 'lib/ruby_concourse.rb', line 29 def sync_concourse(target) print "Updating Concourse: " print `fly -t #{target} sync` end |
#unpause_job(env, team, pipeline, target) ⇒ Object
39 40 41 42 |
# File 'lib/ruby_concourse.rb', line 39 def unpause_job(env, team, pipeline, target) command = `fly -t #{env}-#{team} unpause-job -j #{pipeline}/#{target}` puts command end |
#update_pipeline(env, team, pipeline, credentials_file, pipeline_configuration_file) ⇒ Object
60 61 62 63 64 65 66 67 68 69 70 71 72 73 |
# File 'lib/ruby_concourse.rb', line 60 def update_pipeline(env, team, pipeline, credentials_file, pipeline_configuration_file) login(env, team) command = `fly -t #{env}-#{team} validate-pipeline --config #{pipeline_configuration_file}` if command == "looks good\n" command = `echo y | fly -t #{env}-#{team} set-pipeline --config #{pipeline_configuration_file} --pipeline #{pipeline} --load-vars-from #{credentials_file}` if command.is_a?(String) && command.empty? puts "Updating Pipeline failed - some of the credentials might be missing" else puts "Pipeline updated!" end else puts "Updating Pipeline failed - the #{pipeline_configuration_file} is invalid" end end |
#web_login(env, concourse_login_url) ⇒ Object
76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 |
# File 'lib/ruby_concourse.rb', line 76 def web_login(env, concourse_login_url) var = load_variables(env) username = var['username'] password = var['password'] agent = Mechanize.new page = agent.get(concourse_login_url) login_form = page.form login_form.field_with(:name => 'username').value = username login_form.field_with(:name => 'password' ).value = password output = login_form..body if output.include?('success') puts 'login successful.' else puts 'login failed.' end end |