Sha256: 193230cf33a1b14b1ff64f786186879b7121ed4b2770c9351698e9188435b557

Contents?: true

Size: 1.1 KB

Versions: 34

Compression:

Stored size: 1.1 KB

Contents

require_relative 'services_helper'

module Kontena::Cli::Services
  class LinkCommand < Kontena::Command
    include Kontena::Cli::Common
    include Kontena::Cli::GridOptions
    include ServicesHelper

    parameter "NAME", "Service name"
    parameter "TARGET", "Link target service name"

    def execute
      require_api_url
      token = require_token
      target_service = target

      target_service = "null/#{target_service}" unless target_service.include?('/')

      service = client(token).get("services/#{parse_service_id(name)}")
      existing_targets = service['links'].map{ |l| l['id'].split('/', 2)[1] }
      if existing_targets.include?(target_service.to_s)
        exit_with_error("Service is already linked to #{target.to_s}")
      end
      links = service['links'].map{ |l|
        { name: l['id'].split('/', 2)[1], alias: l['alias'] }
      }
      links << {name: target_service.to_s, alias: target.to_s}
      links.compact!
      data = {links: links}
      spinner "Linking #{pastel.cyan(name)} to #{pastel.cyan(target)} " do
        update_service(token, name, data)
      end
    end
  end
end

Version data entries

34 entries across 34 versions & 2 rubygems

Version Path
krates-1.7.11 lib/kontena/cli/services/link_command.rb
krates-1.7.10 lib/kontena/cli/services/link_command.rb
krates-1.7.9 lib/kontena/cli/services/link_command.rb
krates-1.7.8 lib/kontena/cli/services/link_command.rb
krates-1.7.7 lib/kontena/cli/services/link_command.rb
krates-1.7.6 lib/kontena/cli/services/link_command.rb
krates-1.7.5 lib/kontena/cli/services/link_command.rb
krates-1.7.4 lib/kontena/cli/services/link_command.rb
krates-1.7.3 lib/kontena/cli/services/link_command.rb
krates-1.7.2 lib/kontena/cli/services/link_command.rb
krates-1.7.1 lib/kontena/cli/services/link_command.rb
krates-1.7.0 lib/kontena/cli/services/link_command.rb
krates-1.6.9 lib/kontena/cli/services/link_command.rb
krates-1.6.8 lib/kontena/cli/services/link_command.rb
krates-1.6.7 lib/kontena/cli/services/link_command.rb
krates-1.6.6 lib/kontena/cli/services/link_command.rb
krates-1.6.5 lib/kontena/cli/services/link_command.rb
krates-1.6.4 lib/kontena/cli/services/link_command.rb
krates-1.6.3 lib/kontena/cli/services/link_command.rb
krates-1.6.2 lib/kontena/cli/services/link_command.rb