Sha256: 46a164cdcb1c09e61e87ce58f5bcada73865747ddf13ece517cacf0542df548d
Contents?: true
Size: 1.14 KB
Versions: 17
Compression:
Stored size: 1.14 KB
Contents
require_relative '../grid_options' 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 #{name.colorize(:cyan)} to #{target.colorize(:cyan)} " do update_service(token, name, data) end end end end
Version data entries
17 entries across 17 versions & 1 rubygems