Sha256: ec1207f333c0e5dd6152160167955339cbe03f77b9e28fadd4fff5230246d431

Contents?: true

Size: 1.16 KB

Versions: 3

Compression:

Stored size: 1.16 KB

Contents

require 'ruby_fly'
require 'rake_factory'
require 'concourse'

module RakeFly
  module Tasks
    module Authentication
      class Ensure < RakeFactory::Task
        default_name :ensure
        default_prerequisites RakeFactory::DynamicValue.new { |t|
          [t.fly_ensure_task_name]
        }
        default_description RakeFactory::DynamicValue.new { |t|
          target = t.target || '<derived>'

          "Ensure logged in for target #{target}"
        }

        parameter :target, required: true

        parameter :home_directory,
            default: RakeFactory::DynamicValue.new { |_| ENV['HOME'] }

        parameter :fly_ensure_task_name, :default => :'fly:ensure'

        action do |t, args|
          puts "Ensuring target #{t.target} is logged in..."
          status = RubyFly.status(
              target: t.target,
              environment: {
                  "HOME" => t.home_directory
              })
          if status == :logged_in
            puts "Already logged in. Continuing..."
          else
            puts "Not logged in. Logging in..."
            t.application[:login, t.scope].invoke(*args)
          end
        end
      end
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
rake_fly-2.3.0 lib/rake_fly/tasks/authentication/ensure.rb
rake_fly-2.2.0.pre.8 lib/rake_fly/tasks/authentication/ensure.rb
rake_fly-2.2.0.pre.7 lib/rake_fly/tasks/authentication/ensure.rb