Class: Sem::CLI::Secrets::Files

Inherits:
Dracula
  • Object
show all
Defined in:
lib/sem/cli/secrets.rb

Instance Method Summary collapse

Instance Method Details

#add(secrets_name) ⇒ Object



127
128
129
130
131
132
133
134
135
136
137
138
139
140
# File 'lib/sem/cli/secrets.rb', line 127

def add(secrets_name)
  secret = Sem::API::Secret.find!(secrets_name)

  local_path = options["local-path"]

  abort "File #{local_path} not found" unless File.exist?(local_path)

  path = options["path-on-semaphore"]
  content = File.read(local_path)

  secret.add_config_file(:path => path, :content => content, :encrypted => true)

  puts "Added /home/runner/#{path} to #{secrets_name}."
end

#list(secret_name) ⇒ Object



107
108
109
110
111
112
113
114
115
116
# File 'lib/sem/cli/secrets.rb', line 107

def list(secret_name)
  secret = Sem::API::Secret.find!(secret_name)
  files = secret.files

  if !files.empty?
    Sem::Views::Files.list(files)
  else
    Sem::Views::Secrets.add_first_file(secret)
  end
end

#remove(secrets_name) ⇒ Object



150
151
152
153
154
155
156
# File 'lib/sem/cli/secrets.rb', line 150

def remove(secrets_name)
  secret = Sem::API::Secret.find!(secrets_name)

  secret.remove_config_file(options[:path])

  puts "Removed /home/runner/#{options[:path]} from #{secrets_name}."
end