Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Setting client_id and api_key as environment variables in shell #176

Closed
stalluri opened this issue Sep 5, 2015 · 13 comments
Closed

Setting client_id and api_key as environment variables in shell #176

stalluri opened this issue Sep 5, 2015 · 13 comments

Comments

@stalluri
Copy link

stalluri commented Sep 5, 2015

Usually most CLIs like aws, heroku etc support setting API keys as environment variable for shell scripting purposes. Does tugboat support such model ? If not, can some one help me how can I quickly fork and modify specific ruby files?

@petems
Copy link
Owner

petems commented Oct 19, 2015

Good idea, would be fairly easy to implement (just need to add something like

    def access_token
      ENV['DIGITAL_OCEAN_ACCESS_TOKEN'] || @data['authentication']['access_token'] || 
    end

To the config code, I'll see if I can get that working after I've completed the API 2.0 stuff! 😄

@stalluri
Copy link
Author

Thanks Peter. If you can incorporate it as part of your API 2.0 release, it would be great.

@petems
Copy link
Owner

petems commented Oct 20, 2015

@stalluri PR for you here: #184

Would that be good for your use-case?

@stalluri
Copy link
Author

stalluri commented Nov 2, 2015

Peter, I tried it by setting DO_API_TOKEN as an environment variable and I'm getting the error below.

/usr/local/share/ruby/gems/2.0/gems/tugboat-2.0.0.RC1/lib/tugboat/middleware/list_droplets.rb:10:in `call': undefined method `empty?' for nil:NilClass (NoMethodError)
    from /usr/local/share/ruby/gems/2.0/gems/tugboat-2.0.0.RC1/lib/tugboat/middleware/inject_client.rb:27:in `call'
    from /usr/local/share/ruby/gems/2.0/gems/tugboat-2.0.0.RC1/lib/tugboat/middleware/check_configuration.rb:19:in `call'
    from /usr/local/share/ruby/gems/2.0/gems/tugboat-2.0.0.RC1/lib/tugboat/middleware/inject_configuration.rb:10:in `call'
    from /home/neptuneioagent/.gem/ruby/2.0/gems/middleware-0.1.0/lib/middleware/runner.rb:31:in `call'
    from /home/neptuneioagent/.gem/ruby/2.0/gems/middleware-0.1.0/lib/middleware/builder.rb:102:in `call'
    from /usr/local/share/ruby/gems/2.0/gems/tugboat-2.0.0.RC1/lib/tugboat/cli.rb:71:in `droplets'
    from /home/neptuneioagent/.gem/ruby/2.0/gems/thor-0.18.1/lib/thor/command.rb:27:in `run'
    from /home/neptuneioagent/.gem/ruby/2.0/gems/thor-0.18.1/lib/thor/invocation.rb:120:in `invoke_command'
    from /home/neptuneioagent/.gem/ruby/2.0/gems/thor-0.18.1/lib/thor.rb:363:in `dispatch'
    from /home/neptuneioagent/.gem/ruby/2.0/gems/thor-0.18.1/lib/thor/base.rb:439:in `start'
    from /usr/local/share/ruby/gems/2.0/gems/tugboat-2.0.0.RC1/bin/tugboat:10:in `<top (required)>'
    from /usr/local/bin/tugboat:23:in `load'
    from /usr/local/bin/tugboat:23:in `<main>'

@petems petems reopened this Nov 2, 2015
@petems
Copy link
Owner

petems commented Nov 2, 2015

@stalluri Strange, I tested it and worked fine for me:

$ DO_API_TOKEN='REDACTED' bundle exec tugboat droplets
redacted (ip: redacted, status: active, region: lon1, id: redacted)

What version of the gem are you using? Are you using the repo itself or building the gem?

@stalluri
Copy link
Author

stalluri commented Nov 2, 2015

Just to add more context, I tried the following as well :

  1. With no ~/.tugboat file, as I was setting DO_API_TOKEN environment variable
  2. With ~/.tugboat file, with an empty access token , and set DO_API_TOKEN env variable
  3. With ~/.tugboat file, with a "junk_token", and then set DO_API_TOKEN with right token as env variable..

I used the following to install tugboat
gem install tugboat -v 2.0.0.RC1

@petems
Copy link
Owner

petems commented Nov 2, 2015

Ah ok, yes this won't work until I release the gem, so it won't work with 2.0.0.RC1, it'll have to wait until 2.0.0 gets officially released, which I'll probably do tomorrow or the day after.

Or you can build it yourself in the mean time to test:

git clone https://github.com/pearkes/tugboat
cd tugboat
git checkout master
git pull
bundle install
bundle exec rake build
gem install pkg/tugboat-2.0.0.RC1.gem

@stalluri
Copy link
Author

stalluri commented Nov 2, 2015

I will wait for official 2.0 release.
I understand v1 is being deprecated in a week on Nov 9th by digital ocean.

@petems
Copy link
Owner

petems commented Nov 2, 2015

Yep, I'm releasing before the 9th, just trying to get the user-data feature working first 😄

@petems
Copy link
Owner

petems commented Nov 3, 2015

Fixed by #183 release

@petems petems closed this as completed Nov 3, 2015
@stalluri
Copy link
Author

stalluri commented Feb 1, 2016

Peter, I was trying set the api token using environment variable, and it's not working.

DO_API_TOKEN=234lk23j42k3jadkjflkdjflsadjf
tugboat droplets
You must run tugboat authorize in order to connect to DigitalOcean

@petems
Copy link
Owner

petems commented Feb 2, 2016

Which version of tugboat are you using? That works for me:

DO_API_TOKEN=REDACTED tugboat droplets
petersouter-docker-compose (ip: REDACTED, status: active, region: lon1, id: REDACTED)
08:19:41 ~ $ tugboat --version
Tugboat 2.1.0

@stalluri
Copy link
Author

stalluri commented Feb 2, 2016

Thanks Peter for your quick response. Much appreciated.
Here is the output :

[neptune@ip-10-0-0-120 ~]$ which tugboat
/usr/local/bin/tugboat
[neptune@ip-10-0-0-120 ~]$ DO_API_TOKEN=REDACTED tugboat droplets
You must run tugboat authorize in order to connect to DigitalOcean
[neptune@ip-10-0-0-120 ~]$ tugboat version
Tugboat 2.2.0

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants