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

Use config.token and config.aliases if set #254

Merged
merged 20 commits into from
Apr 9, 2020

Conversation

wasabigeek
Copy link
Contributor

Fixes #240.

I assumed that setting the config in code would take precedence over an ENV variable.

Will do a separate PR for aliases after this!

it 'sets config.token from ENV' do
allow(ENV).to receive(:[]).and_call_original.at_least(:once)
allow(ENV).to receive(:[]).with('SLACK_API_TOKEN').and_return(token)
SlackRubyBot.configure { |config| config.token = nil }
Copy link
Contributor Author

@wasabigeek wasabigeek Apr 7, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This pattern deviates from the existing, but I do feel it makes the tests more isolated from the setup in spec_helper. What do you think @dblock?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I like it.

@dblock
Copy link
Collaborator

dblock commented Apr 7, 2020

Let's also allow passing the token in the constructor for Server in options?

lib/slack-ruby-bot/app.rb Show resolved Hide resolved
@wasabigeek
Copy link
Contributor Author

wasabigeek commented Apr 7, 2020

passing the token in the constructor for Server in options

Stopped short of this, some questions:

  • were there any particular use cases you had in mind for letting each Server instance have it's own token? e.g. different slack bots running on the same server, but for the same team (since team would still be a global config, unless we do something there too)?
  • it seems like the token doesn't actually get used in Server (it gets passed down to Client, but Client doesn't use it, I suppose because Slack requires the config to be set globally), is that intentional? (Though fixing that should probably be a separate PR anyway)

@dblock
Copy link
Collaborator

dblock commented Apr 7, 2020

passing the token in the constructor for Server in options

Stopped short of this, some questions:

  • were there any particular use cases you had in mind for letting each Server instance have it's own token? e.g. different slack bots running on the same server, but for the same team (since team would still be a global config, unless we do something there too)?

It's more of a best practice thing, we can have a singleton, but not globals where it's unnecessary. I don't have a better scenario, but for testing alone it's worth it IMHO.

  • it seems like the token doesn't actually get used in Server (it gets passed down to Client, but Client doesn't use it, I suppose because Slack requires the config to be set globally), is that intentional? (Though fixing that should probably be a separate PR anyway)

We possibly have issues here, but I am not sure. The thing is that most people use this library with slack-ruby-bot-server, that doesn't use any of these globals and creates a bot instance with a token following an OAuth workflow. The globals were a facility to run a single bot for a single team with a token, which is deprecated by slack. Feel free to fix all/some/none! And greatly appreciate it and happy to help.

lib/slack-ruby-bot/app.rb Outdated Show resolved Hide resolved
CHANGELOG.md Outdated Show resolved Hide resolved
lib/slack-ruby-bot/app.rb Outdated Show resolved Hide resolved
Copy link
Collaborator

@dblock dblock left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks great. A few more asks, thanks for hanging in here with me.

lib/slack-ruby-bot/app.rb Outdated Show resolved Hide resolved
lib/slack-ruby-bot/app.rb Outdated Show resolved Hide resolved
lib/slack-ruby-bot/app.rb Outdated Show resolved Hide resolved
lib/slack-ruby-bot/app.rb Outdated Show resolved Hide resolved
@wasabigeek wasabigeek changed the title Use config.token if set Use config.token and config.aliases if set Apr 8, 2020
@wasabigeek wasabigeek requested a review from dblock April 9, 2020 02:01
@dblock dblock merged commit f096855 into slack-ruby:master Apr 9, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

SlackRubyBot.config.token does not work?
2 participants