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

Add Asset and Organization resources #10

Merged
merged 10 commits into from
Aug 9, 2024

Conversation

jeffgran-dox
Copy link
Contributor

  • Adds some new resources that are newer in the API.
  • Updates StructuredScope to have the program id so that it can construct its URLs.

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.

Thanks for the PR and the added functionality! I have a couple comments below about the implementation, mainly to ensure that calling/ method signatures are consistent across the library.

Are you able to write and record tests for this additional functionality? If you don't have access to a test HackerOne instance, I can help record VCR tests, but would you please mind writing some tests, similar to program_spec.rb and swag_spec.rb?

@@ -4,10 +4,13 @@
require "json"
require "active_support"
require "active_support/core_ext/numeric/time"
require "ostruct"
Copy link
Contributor

Choose a reason for hiding this comment

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

This should not be needed, as Ostruct is bundled with Ruby: https://github.com/ruby/ostruct?tab=readme-ov-file#installation.

I don't see anything inherently wrong with this, so fine with the diff but it in theory it shouldn't be breaking anything currently.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I didn't need this when I was testing this locally but then when I tried to use it in another context it crashed with an "openstruct is not defined" error. I'm not sure what the cause was, maybe a different ruby version that doesn't require it by default any more or something. So I feel like it's worth leaving it in to prevent someone else from running into that, and like you say I think it should be harmless.

lib/hackerone/client/structured_scope.rb Show resolved Hide resolved
Comment on lines 29 to 31
def program_id
@program_id
end
Copy link
Contributor

Choose a reason for hiding this comment

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

I've noted a change to the method signature above to accept program instead. Also, more idiomatically, can we just add a attr_reader :program above? This will match the implementation in places like

attr_reader :program, :updated_at_after, :page_size

lib/hackerone/client/organization.rb Show resolved Hide resolved
]

delegate *DELEGATES, to: :attributes

def initialize(scope)
def initialize(program_id, scope)
Copy link
Contributor

Choose a reason for hiding this comment

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

In keeping with the pattern that was set in the Swag object:

def initialize(swag, program = nil)

Let's set this method signature to scope, program = nil. This will also allow this change to be backwards compatible.

Suggested change
def initialize(program_id, scope)
def initialize(scope, program = nil)

Here's another callsite that accepts program, for example:

def initialize(program, updated_at_after: nil, page_size: 25)
@program = program

type: "structured-scope",
attributes: attributes
}
make_put_request("programs/#{@program_id}/structured_scopes/#{id}", request_body: body)
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
make_put_request("programs/#{@program_id}/structured_scopes/#{id}", request_body: body)
make_put_request("programs/#{@program.id}/structured_scopes/#{id}", request_body: body)

lib/hackerone/client/asset.rb Outdated Show resolved Hide resolved

delegate *DELEGATES, to: :attributes

def initialize(organization_id, asset)
Copy link
Contributor

Choose a reason for hiding this comment

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

The pattern in other objects of this library is currently object, additional_parameter:

Suggested change
def initialize(organization_id, asset)
def initialize(asset, organization)

@jeffgran-dox
Copy link
Contributor Author

@rzhade3 thanks for the review! yes, I'll address your comments and work on adding some specs.

@jeffgran-dox
Copy link
Contributor Author

@rzhade3 Hi, I believe I have addressed your feedback and added some specs. However, I do not have an easy way to record new VCR fixtures so I just mocked the requests with webmock, pulling the example responses from their API docs. If you'd rather have these use VCR would you mind modifying the code and recording them for me? Thanks

rzhade3
rzhade3 previously approved these changes Aug 9, 2024
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.

Thanks for the changes! I'm OK with using Webmock to stub out the request as opposed to re-recording the entire VCR request.

\cc @boveus for final review to see if there's anything more idiomatic we can do with Webmock

boveus
boveus previously approved these changes Aug 9, 2024
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.

There are a few Rubocop errors that still need to be fixed. @jeffgran-dox it doesn't appear as if I have permission to push these directly to your branch, could you please accept these suggested changes?

spec/spec_helper.rb Outdated Show resolved Hide resolved
spec/hackerone/client/asset_spec.rb Outdated Show resolved Hide resolved
lib/hackerone/client/asset.rb Outdated Show resolved Hide resolved
Co-authored-by: Rahul Zhade <[email protected]>
@jeffgran-dox jeffgran-dox dismissed stale reviews from boveus and rzhade3 via f1899cc August 9, 2024 16:06
@rzhade3 rzhade3 merged commit 05dc74d into github:main Aug 9, 2024
7 checks passed
@rzhade3
Copy link
Contributor

rzhade3 commented Aug 9, 2024

@jeffgran-dox Thanks again for the PR, I've released these changes as version 0.23.0 on Rubygems.

@jeffgran-dox
Copy link
Contributor Author

@rzhade3 excellent, thank you!

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.

3 participants