Skip to content

Commit

Permalink
feat: aptible config:get cmd (#330)
Browse files Browse the repository at this point in the history
  • Loading branch information
neurosnap authored May 28, 2024
1 parent cd35e61 commit 349f348
Show file tree
Hide file tree
Showing 5 changed files with 60 additions and 0 deletions.
10 changes: 10 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
FROM ruby:2.7.8

WORKDIR /app
COPY . /app

RUN ./cleanup_bundler
RUN gem install bundler -v '< 2'
RUN bundle install

CMD ["/app/bin/aptible"]
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ Commands:
aptible backup:restore BACKUP_ID [--environment ENVIRONMENT_HANDLE] [--handle HANDLE] [--container-size SIZE_MB] [--disk-size SIZE_GB] [--key-arn KEY_ARN] # Restore a backup
aptible config # Print an app's current configuration
aptible config:add [VAR1=VAL1] [VAR2=VAL2] [...] # Add an ENV variable to an app
aptible config:get [VAR1] # Print a specific key within an app's current configuration
aptible config:rm [VAR1] [VAR2] [...] # Remove an ENV variable from an app
aptible config:set [VAR1=VAL1] [VAR2=VAL2] [...] # Add an ENV variable to an app
aptible config:unset [VAR1] [VAR2] [...] # Remove an ENV variable from an app
Expand Down
10 changes: 10 additions & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
services:
# docker compose run cli bash
# export APTIBLE_ACCESS_TOKEN=xxx
# bundle exec ./bin/aptible help
cli:
build: .
volumes:
- type: bind
source: .
target: /app
17 changes: 17 additions & 0 deletions lib/aptible/cli/subcommands/config.rb
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,23 @@ def config
end
end

desc 'config:get [VAR1]',
"Print a specific key within an app's current configuration"
app_options
define_method 'config:get' do |*args|
app = ensure_app(options)
config = app.current_configuration
env = config ? config.env : {}

Formatter.render(Renderer.current) do |root|
key = args[0]
value = env
.select { |k| k == key }
.map { |_, v| v }
root.value(value)
end
end

desc 'config:add [VAR1=VAL1] [VAR2=VAL2] [...]',
'Add an ENV variable to an app'
app_options
Expand Down
22 changes: 22 additions & 0 deletions spec/aptible/cli/subcommands/config_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,28 @@
end
end

describe '#config:get' do
it 'should show single environment variable specified' do
app.current_configuration = Fabricate(
:configuration, app: app, env: { 'FOO' => 'BAR', 'QUX' => 'two words' }
)
subject.send('config:get', 'FOO')

expect(captured_output_text).to match(/BAR/)
expect(captured_output_text).not_to match(/two\\ words/)
expect(captured_output_json).to match_array(['BAR'])
end

it 'should show empty line when env var not found' do
app.current_configuration = Fabricate(
:configuration, app: app, env: { 'FOO' => 'BAR', 'QUX' => 'two words' }
)
subject.send('config:get', 'MIZ')

expect(captured_output_text).to eq('')
end
end

describe '#config:set' do
it 'sets environment variables' do
expect(app).to receive(:create_operation!)
Expand Down

0 comments on commit 349f348

Please sign in to comment.