Class: Travis::CLI::Encrypt

Inherits:
RepoCommand show all
Defined in:
lib/travis/cli/encrypt.rb

Constant Summary

Constants inherited from RepoCommand

RepoCommand::GIT_REGEX, RepoCommand::TRAVIS

Constants inherited from Command

Command::DAY, Command::HOUR, Command::MINUTE, Command::WEEK

Constants included from Tools::Assets

Tools::Assets::BASE

Instance Attribute Summary collapse

Attributes inherited from RepoCommand

#slug

Attributes inherited from ApiCommand

#enterprise_name, #session

Attributes inherited from Command

#arguments, #config, #debug, #force_interactive, #formatter, #input, #output

Instance Method Summary collapse

Methods inherited from RepoCommand

#repository, #setup

Methods inherited from ApiCommand

#authenticate, #detected_endpoint?, #endpoint_config, #enterprise?, #initialize, #org?, #pro?, #setup, #sync

Methods included from Travis::Client::Methods

#access_token, #access_token=, #account, #accounts, #api_endpoint, #api_endpoint=, #artifact, #broadcasts, #build, #cancel, #explicit_api_endpoint?, #github_auth, #hooks, #job, #lint, #listen, #repo, #repos, #restart, #user

Methods inherited from Command

abstract, abstract?, #check_completion, #check_ruby, #check_version, command_name, #command_name, #debug?, description, #execute, #help, #info, #initialize, #last_check, #on_signal, #parse, #say, #setup, skip, subcommands, #terminal, #time, #usage, #usage_for, #write_to

Methods included from Tools::Assets

#asset, #asset_path

Methods included from Parser

#new, #on, #on_initialize

Constructor Details

This class inherits a constructor from Travis::CLI::ApiCommand

Instance Attribute Details

#config_keyObject

Returns the value of attribute config_key.



8
9
10
# File 'lib/travis/cli/encrypt.rb', line 8

def config_key
  @config_key
end

Instance Method Details

#run(*args) ⇒ Object



18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
# File 'lib/travis/cli/encrypt.rb', line 18

def run(*args)
  error "cannot combine --override and --append"   if append?   and override?
  error "--append without --add makes no sense"    if append?   and not add?
  error "--override without --add makes no sense"  if override? and not add?
  self.override |= !config_key.start_with?('env.') if add?      and not append?

  if args.first =~ %r{\w+/\w+} && !args.first.include?("=")
    warn "WARNING: The name of the repository is now passed to the command with the -r option:"
    warn "    #{command("encrypt [...] -r #{args.first}")}"
    warn "  If you tried to pass the name of the repository as the first argument, you"
    warn "  probably won't get the results you wanted.\n"
  end

  data = args.join(" ")

  if data.empty?
    say color("Reading from stdin, press Ctrl+D when done", :info) if $stdin.tty?
    data = $stdin.read
  end

  data = split? ? data.split("\n") : [data.strip]
  encrypted = data.map { |data| repository.encrypt(data) }

  if config_key
    set_config encrypted.map { |e| { 'secure' => e } }
    save_travis_config
  else
    list = encrypted.map { |data| format(data.inspect, "  secure: %s") }
    say(list.join("\n"), template(__FILE__), :none)
  end
rescue OpenSSL::PKey::RSAError => error
  error "#{error.message.sub(" for key size", "")} - consider using "    <<
    color("travis encrypt-file", [:red, :bold]) <<
    color(" or ", :red)                         <<
    color("travis env set", [:red, :bold])
end