Sha256: 4400b46446e28841e2fa556752821f46ab65d01560a04c55208f889475bcf636

Contents?: true

Size: 896 Bytes

Versions: 32

Compression:

Stored size: 896 Bytes

Contents

require_relative '../grid_options'
require_relative 'services_helper'

module Kontena::Cli::Services
  class LinkCommand < Clamp::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

      service = client(token).get("services/#{parse_service_id(name)}")
      existing_targets = service['links'].map{|l| l['grid_service_id'].split('/')[1]}
      abort("Service is already linked to #{target.to_s}") if existing_targets.include?(target.to_s)
      links = service['links'].map{|l| {name: l['grid_service_id'].split('/')[1], alias: l['alias']} }
      links << {name: target.to_s, alias: target.to_s}
      data = {links: links}
      update_service(token, name, data)
    end
  end
end

Version data entries

32 entries across 32 versions & 1 rubygems

Version Path
kontena-cli-0.15.5 lib/kontena/cli/services/link_command.rb
kontena-cli-0.15.5.rc2 lib/kontena/cli/services/link_command.rb
kontena-cli-0.15.5.rc1 lib/kontena/cli/services/link_command.rb
kontena-cli-0.15.4 lib/kontena/cli/services/link_command.rb
kontena-cli-0.15.4.rc2 lib/kontena/cli/services/link_command.rb
kontena-cli-0.15.4.rc1 lib/kontena/cli/services/link_command.rb
kontena-cli-0.15.4.pre1 lib/kontena/cli/services/link_command.rb
kontena-cli-0.15.3 lib/kontena/cli/services/link_command.rb
kontena-cli-0.15.2 lib/kontena/cli/services/link_command.rb
kontena-cli-0.15.1 lib/kontena/cli/services/link_command.rb
kontena-cli-0.15.0 lib/kontena/cli/services/link_command.rb
kontena-cli-0.15.0.rc3 lib/kontena/cli/services/link_command.rb
kontena-cli-0.15.0.rc2 lib/kontena/cli/services/link_command.rb
kontena-cli-0.15.0.rc1 lib/kontena/cli/services/link_command.rb
kontena-cli-0.14.7 lib/kontena/cli/services/link_command.rb
kontena-cli-0.14.6 lib/kontena/cli/services/link_command.rb
kontena-cli-0.14.5 lib/kontena/cli/services/link_command.rb
kontena-cli-0.14.4 lib/kontena/cli/services/link_command.rb
kontena-cli-0.14.3 lib/kontena/cli/services/link_command.rb
kontena-cli-0.14.2 lib/kontena/cli/services/link_command.rb