-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1360 from alphagov/fix-engine
Refactor handling of non-managed resources
- Loading branch information
Showing
18 changed files
with
142 additions
and
26 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
# Enhances models with a `#name` method returning their fully qualified Google Cloud Platform | ||
# resource name (like a path). | ||
# | ||
# For example, for a `Control`, this would be: | ||
# projects/{project}/locations/{location}/collections/{collection_id}/engines/ | ||
# {engine_id}/controls/{control_id} | ||
# | ||
# Requires the including class to implement `#remote_resource_id`, and optionally `#parent` if the | ||
# parent resource is not the default collection. | ||
module DiscoveryEngineNameable | ||
# The name (fully qualified path) of this Discovery Engine resource on GCP | ||
def name | ||
[parent_name, resource_path_fragment, remote_resource_id].join("/") | ||
end | ||
|
||
private | ||
|
||
def resource_path_fragment | ||
# For example: `DataStore` -> `dataStores` | ||
self.class.name.downcase_first.pluralize | ||
end | ||
|
||
def parent_name | ||
if respond_to?(:parent) | ||
parent.name | ||
else | ||
# The default collection is the parent of all root-level resources | ||
Rails.configuration.discovery_engine_default_collection_name | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
# Represents a data store on Discovery Engine. | ||
# | ||
# A data store contains the indexed documents that can be searched through an engine. | ||
# | ||
# Our architecture currently only has a single data store, so we do not need the ability to manage | ||
# data stores through Search Admin. | ||
# | ||
# see https://cloud.google.com/ruby/docs/reference/google-cloud-discovery_engine-v1/latest/Google-Cloud-DiscoveryEngine-V1-DataStore | ||
class DataStore | ||
include DiscoveryEngineNameable | ||
|
||
# The ID of the default datastore created through Terraform in `govuk_infrastructure` | ||
DEFAULT_DATA_STORE_ID = "govuk_content".freeze | ||
|
||
attr_reader :remote_resource_id | ||
|
||
def self.default | ||
new(DEFAULT_DATA_STORE_ID) | ||
end | ||
|
||
def initialize(remote_resource_id) | ||
@remote_resource_id = remote_resource_id | ||
end | ||
|
||
def ==(other) | ||
remote_resource_id == other.remote_resource_id | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
# Represents an engine on Discovery Engine. | ||
# | ||
# An engine (called "app" in the Google Cloud UI) is an abstraction over the data stores that | ||
# contain our searchable documents, and is used for querying. It is the parent resource of several | ||
# other resources such as controls and serving configs. | ||
# | ||
# Our architecture currently only has a single engine, so we do not need the ability to manage | ||
# engines through Search Admin. | ||
# | ||
# see https://cloud.google.com/ruby/docs/reference/google-cloud-discovery_engine-v1/latest/Google-Cloud-DiscoveryEngine-V1-Engine | ||
class Engine | ||
include DiscoveryEngineNameable | ||
|
||
# The ID of the default engine created through Terraform in `govuk-infrastructure` | ||
DEFAULT_ENGINE_ID = "govuk".freeze | ||
|
||
attr_reader :remote_resource_id | ||
|
||
def self.default | ||
new(DEFAULT_ENGINE_ID) | ||
end | ||
|
||
def initialize(remote_resource_id) | ||
@remote_resource_id = remote_resource_id | ||
end | ||
|
||
def ==(other) | ||
remote_resource_id == other.remote_resource_id | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
RSpec.describe DataStore do | ||
subject(:data_store) { described_class.new("my-data-store") } | ||
|
||
describe ".default" do | ||
it "returns the default data store" do | ||
expect(described_class.default).to eq(described_class.new("govuk_content")) | ||
end | ||
end | ||
|
||
describe "#name" do | ||
it "returns the fully qualified name of the data store" do | ||
expect(subject.name).to eq("[collection]/dataStores/my-data-store") | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
RSpec.describe Engine do | ||
subject(:engine) { described_class.new("my-engine") } | ||
|
||
describe ".default" do | ||
it "returns the default engine" do | ||
expect(described_class.default).to eq(described_class.new("govuk")) | ||
end | ||
end | ||
|
||
describe "#name" do | ||
it "returns the fully qualified name of the engine" do | ||
expect(subject.name).to eq("[collection]/engines/my-engine") | ||
end | ||
end | ||
end |