Skip to content

Conversation

@misfir3
Copy link

@misfir3 misfir3 commented Feb 12, 2025

Adding ability to explicitly (but optional, falling back to ENV) set token and token_name when initializing the client. Some issues with testing. WIP for now.

@misfir3
Copy link
Author

misfir3 commented Feb 12, 2025

Not sure, but guessing we need to record new cassettes for testing here.

unless ENV["HACKERONE_TOKEN_NAME"] && ENV["HACKERONE_TOKEN"]
raise NotConfiguredError, "HACKERONE_TOKEN_NAME HACKERONE_TOKEN environment variables must be set"

unless client_token_name && client_token
Copy link

Choose a reason for hiding this comment

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

there may also be a VCR issue but I think a lot of the these test failures are related to client_token_name not being defined, should this be token_name as defined on line 73?

Copy link
Author

Choose a reason for hiding this comment

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

Ooooh ... did I miss one of those instances (I thought I had cleaned up)? Good catch and thanks for the 👀

Copy link
Author

@misfir3 misfir3 Feb 12, 2025

Choose a reason for hiding this comment

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

Updated that (which needed updating all the same) and still getting all those failures ... 🤔 @rzhade3 can you take a peek when you have a moment. You're closer to this (historically at least) than I am.

@misfir3 misfir3 marked this pull request as ready for review February 15, 2025 02:13
Copy link
Contributor

@rzhade3 rzhade3 left a comment

Choose a reason for hiding this comment

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

Some thoughts; for context the reason I never picked up this issue to work on was the insufficient encapsulation in the HackerOne::Client object which makes it difficult to pass instance level variables to it 🙃

end

def token_name
@token_name || ENV["HACKERONE_TOKEN_NAME"]
Copy link
Contributor

Choose a reason for hiding this comment

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

When would this be needed? As far as I can tell, this conditional would only ever evaluate if the value of the HACKERONE_TOKEN_NAME token wasn't set when the client was initialized?

I suppose it would help from a backwards compatibility perspective, but just want to make sure this line earns its place in the code.

@program = program
@token = token || ENV["HACKERONE_TOKEN"]
@token_name = token_name || ENV["HACKERONE_TOKEN_NAME"]
# Set class-level token and token_name if provided
Copy link
Contributor

Choose a reason for hiding this comment

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

Ehhhhh, if we're setting this token at a class level then this is no better logically than if we just continue to use environment variables; part of the impetus to use tokens as variables is such that there is instance level encapsulation. This adds side effects across entire classes which defeats the purpose of this in the first place. This would clobber any calls to HackerOne::Client methods anytime after a new API object is created, which doesn't seem ideal. I think 🤔

It is also tough because that class is designed to operate as a class, which makes encapsulation really tough.

Some alternatives:

  • Accept this as tech debt, and accept that you can only have one instance of HackerOne::Client running
  • Put an instance of the HackerOne::Cient inside the HackerOne::Api object, and operate on that object. This would certainly not be backwards compatible.
  • Do not add this side effect, in which case HackerOne::Client and all subclasses would only be able to respond to the environment variable
  • Deprecate the HackerOne::Client class. I would prefer this, but this is also certainly not backwards compatible
  • Rewrite the HackerOne::Client object such that it becomes a class instead of an object

Copy link
Author

Choose a reason for hiding this comment

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

Appreciate the feedback ...

Deprecate the HackerOne::Client class. I would prefer this, but this is also certainly not backwards compatible

I think I prefer this too, but timeline changes with that. Gonna have to think on it a little more 🙇🏼

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.

4 participants