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

Interceptors #137

Merged
merged 15 commits into from
Jul 11, 2023
Merged

Interceptors #137

merged 15 commits into from
Jul 11, 2023

Conversation

alextwoods
Copy link
Contributor

@alextwoods alextwoods commented Jun 26, 2023

Description of changes:

Adds Interceptors to Hearth:

  • Add interceptor context (and utilities for creating it from request context)
  • Add Interceptor::List - similar to PluginList. Also has an apply method for calling an interceptor hook (previously the interceptor_hook method).
  • Add Initialize middleware (provide first/last hooks)
  • Moved validate to a new middleware step (VALIDATE). Updated host_prefix to to use Relative to (before) Build.
  • Codegen
    • Add Initialize middleware
    • Add interceptors to generated Configs
    • resolution during client initialization and operation invocation.

Future PRs:

  • Convenience utilities for writing interceptors (TBD, needs some interface work) - will be done as separate PR.
  • Remove middleware from public api (requires updates to protocol tests) - will be done as separate PR.

By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.

@alextwoods alextwoods requested a review from mullermp July 6, 2023 23:26
Copy link
Contributor

@mullermp mullermp left a comment

Choose a reason for hiding this comment

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

Nice. Looks good so far.

hearth/lib/hearth/interceptor.rb Outdated Show resolved Hide resolved
hearth/lib/hearth/interceptor/context.rb Outdated Show resolved Hide resolved
hearth/lib/hearth/context.rb Show resolved Hide resolved
hearth/lib/hearth/interceptor/list.rb Outdated Show resolved Hide resolved
hearth/lib/hearth/middleware/initialize.rb Outdated Show resolved Hide resolved
hearth/lib/hearth/middleware/initialize.rb Outdated Show resolved Hide resolved
hearth/lib/hearth/interceptor.rb Outdated Show resolved Hide resolved
hearth/lib/hearth/interceptor/hooks.rb Outdated Show resolved Hide resolved
hearth/lib/hearth/interceptor_context.rb Show resolved Hide resolved
@alextwoods alextwoods marked this pull request as ready for review July 10, 2023 23:31
Copy link
Contributor

@mullermp mullermp left a comment

Choose a reason for hiding this comment

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

LGTM. Just minor nit picky stuff

let(:client) { Client.new(config) }

it 'applies interceptors in expected order' do
expect(Plugins::TestPlugin::TEST_CLASS_INTERCEPTOR).to receive(hook).ordered
Copy link
Contributor

Choose a reason for hiding this comment

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

I think you can use any_instance_of with the above change.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Wanted to be specific rather than use any_instance_of.

let(:operation_interceptor) { interceptor_class.new('op') }

let(:config_plugin) do
proc { |cfg| cfg.interceptors << config_plugin_interceptor}
Copy link
Contributor

Choose a reason for hiding this comment

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

Space before } on this and below - we should enable rubocop styling/auto correct on spec files.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

ran rubocop on all of these. But we should long term find a way to run it on all of these integration specs, but not on generated gems....

hearth/lib/hearth/context.rb Show resolved Hide resolved
hearth/lib/hearth/interceptor_context.rb Show resolved Hide resolved
last_error
end

def dup
Copy link
Contributor

Choose a reason for hiding this comment

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

minimal @return docs for these

@alextwoods alextwoods merged commit e33b3b0 into main Jul 11, 2023
12 checks passed
@alextwoods alextwoods deleted the interceptors branch July 11, 2023 20:03
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.

2 participants