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

Plugin examples portal app reg #8417

Merged
merged 3 commits into from
Feb 11, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ dbless_compatible: 'no'
free: false
enterprise: true
konnect: false
terraform_examples: false
network_config_opts: Self-managed traditional, DB-less, and hybrid
notes: Application registration <b>is</b> available in Konnect, but doesn't require this plugin. <br>Learn how to <a href="/konnect/dev-portal/applications/enable-app-reg/">Enable Application Registration</a> in Konnect.
categories:
Expand Down
2 changes: 1 addition & 1 deletion app/_plugins/blocks/inline_plugin_example/config.rb
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ def formats

def examples
::Jekyll::Drops::Plugins::HubExamples
.new(schema:, example:, targets:, formats:)
.new(schema:, metadata: {}, example:, targets:, formats:)
end

def schema
Expand Down
12 changes: 10 additions & 2 deletions app/_plugins/drops/plugins/hub_examples.rb
Original file line number Diff line number Diff line change
Expand Up @@ -88,8 +88,9 @@ def auth_next_steps_url
class HubExamples < Liquid::Drop
attr_reader :schema, :example, :formats

def initialize(schema:, example:, targets:, formats:) # rubocop:disable Lint/MissingSuper
def initialize(schema:, metadata:, example:, targets:, formats:) # rubocop:disable Lint/MissingSuper
@schema = schema
@metadata = metadata
@example = example
@targets = targets
@formats = formats
Expand Down Expand Up @@ -120,7 +121,12 @@ def enable_on_service?
end

def enable_globally?
@targets.include?(:global)
global = @metadata['global']

# Default to true if the key is not present
global = true unless @metadata.key?('global')

@targets.include?(:global) && global
end

def consumer
Expand All @@ -130,6 +136,8 @@ def consumer
end

def global
return unless enable_globally?

@global ||= Example.new(schema:, type: 'global', example:, formats:)
end

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ def hub_examples

::Jekyll::Drops::Plugins::HubExamples.new(
schema: @release.schema,
metadata: metadata,
example: @release.schema.example,
targets: ::Jekyll::InlinePluginExample::Config::TARGETS,
formats: %i[curl konnect yaml kubernetes terraform]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ def empty?

def field_no_def?(key, field, no_def)
no_def[key].all? do |k, v|
field[key][k] == v
field[key].key?(k) && field[key][k] == v
end
end
end
Expand Down
18 changes: 16 additions & 2 deletions spec/app/_plugins/drops/plugins/hub_examples_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,11 @@
)
end
let(:example) { schema.example }
let(:metadata) { {} }
let(:targets) { [:consumer, :route, :global, :service, :consumer_group] }
let(:formats) { [:curl, :yaml, :kubernetes] }

subject { described_class.new(schema:, example:, formats:, targets:) }
subject { described_class.new(schema:, metadata:, example:, formats:, targets:) }

describe '#render?' do
context 'when there is an example for the plugin' do
Expand Down Expand Up @@ -67,7 +68,20 @@
end

describe '#global' do
it { expect(subject.global).to be_an_instance_of(Jekyll::Drops::Plugins::Example) }
context 'when the plugin does not have an explicit global config' do
let(:metadata) { {} }
it { expect(subject.global).to be_an_instance_of(Jekyll::Drops::Plugins::Example) }
end

context 'when the plugin can be enabled globally' do
let(:metadata) { { 'global' => true } }
it { expect(subject.global).to be_an_instance_of(Jekyll::Drops::Plugins::Example) }
end

context 'when the plugin can not be enabled globally' do
let(:metadata) { { 'global' => false } }
it { expect(subject.global).to be_nil }
end
end

describe '#route' do
Expand Down