Sha256: 0e100edc91c8117d61338714c19ed1450ade62614d9c2a67bb23505379cea2d5

Contents?: true

Size: 1.38 KB

Versions: 4

Compression:

Stored size: 1.38 KB

Contents

# frozen_string_literal: true

require 'rake_factory'

require_relative '../../client'

module RakeCircleCI
  module Tasks
    module SSHKeys
      class Provision < RakeFactory::Task
        default_name :provision
        default_description(RakeFactory::DynamicValue.new do |t|
          "Provision SSH keys on the #{t.project_slug} project"
        end)

        parameter :project_slug, required: true
        parameter :api_token, required: true
        parameter :base_url, default: 'https://circleci.com/api'
        parameter :ssh_keys, default: {}

        action do |t|
          client = Client.new(
            base_url: t.base_url,
            api_token: t.api_token,
            project_slug: t.project_slug
          )

          puts "Provisioning all SSH keys to the '#{t.project_slug}' " \
               'project... '

          t.ssh_keys.each do |ssh_key|
            private_key = ssh_key[:private_key]
            hostname = ssh_key[:hostname]
            fingerprint = SSHKey.new(private_key).sha1_fingerprint

            print "Adding SSH key with fingerprint: '#{fingerprint}'"
            print " for hostname: '#{hostname}'" if hostname
            print '...'
            options = hostname && { hostname: }
            args = [private_key, options].compact
            client.create_ssh_key(*args)
            puts 'Done.'
          end
        end
      end
    end
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
rake_circle_ci-0.14.0.pre.2 lib/rake_circle_ci/tasks/ssh_keys/provision.rb
rake_circle_ci-0.14.0.pre.1 lib/rake_circle_ci/tasks/ssh_keys/provision.rb
rake_circle_ci-0.13.0 lib/rake_circle_ci/tasks/ssh_keys/provision.rb
rake_circle_ci-0.12.0.pre.5 lib/rake_circle_ci/tasks/ssh_keys/provision.rb