Skip to content

Commit

Permalink
Merge pull request #72 from alphagov/vertex-client
Browse files Browse the repository at this point in the history
Add Discovery Engine API client to application
  • Loading branch information
csutter authored Oct 27, 2023
2 parents 004c786 + c7bdc53 commit a8163f6
Show file tree
Hide file tree
Showing 4 changed files with 107 additions and 4 deletions.
1 change: 1 addition & 0 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ gem "activesupport", RAILS_GEMS_VERSION
gem "railties", RAILS_GEMS_VERSION

gem "bootsnap", require: false
gem "google-cloud-discovery_engine"
gem "govuk_app_config"
gem "loofah"
gem "oj"
Expand Down
64 changes: 64 additions & 0 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ GEM
public_suffix (>= 2.0.2, < 6.0)
amq-protocol (2.3.2)
ast (2.4.2)
base64 (0.1.1)
bootsnap (1.16.0)
msgpack (~> 1.2)
brakeman (6.0.1)
Expand All @@ -49,11 +50,57 @@ GEM
diff-lcs (1.5.0)
docile (1.4.0)
erubi (1.12.0)
faraday (2.7.11)
base64
faraday-net_http (>= 2.0, < 3.1)
ruby2_keywords (>= 0.0.4)
faraday-net_http (3.0.2)
faraday-retry (2.2.0)
faraday (~> 2.0)
gapic-common (0.20.0)
faraday (>= 1.9, < 3.a)
faraday-retry (>= 1.0, < 3.a)
google-protobuf (~> 3.14)
googleapis-common-protos (>= 1.3.12, < 2.a)
googleapis-common-protos-types (>= 1.3.1, < 2.a)
googleauth (~> 1.0)
grpc (~> 1.36)
google-cloud-core (1.6.0)
google-cloud-env (~> 1.0)
google-cloud-errors (~> 1.0)
google-cloud-discovery_engine (0.2.0)
google-cloud-core (~> 1.6)
google-cloud-discovery_engine-v1 (>= 0.0, < 2.a)
google-cloud-discovery_engine-v1beta (>= 0.0, < 2.a)
google-cloud-discovery_engine-v1 (0.3.0)
gapic-common (>= 0.20.0, < 2.a)
google-cloud-errors (~> 1.0)
google-cloud-location (>= 0.4, < 2.a)
google-cloud-discovery_engine-v1beta (0.6.0)
gapic-common (>= 0.20.0, < 2.a)
google-cloud-errors (~> 1.0)
google-cloud-location (>= 0.4, < 2.a)
google-cloud-env (1.6.0)
faraday (>= 0.17.3, < 3.0)
google-cloud-errors (1.3.1)
google-cloud-location (0.6.0)
gapic-common (>= 0.20.0, < 2.a)
google-cloud-errors (~> 1.0)
google-protobuf (3.24.4-aarch64-linux)
google-protobuf (3.24.4-x86_64-darwin)
google-protobuf (3.24.4-x86_64-linux)
googleapis-common-protos (1.4.0)
google-protobuf (~> 3.14)
googleapis-common-protos-types (~> 1.2)
grpc (~> 1.27)
googleapis-common-protos-types (1.9.0)
google-protobuf (~> 3.18)
googleauth (1.8.1)
faraday (>= 0.17.3, < 3.a)
jwt (>= 1.4, < 3.0)
multi_json (~> 1.11)
os (>= 0.9, < 2.0)
signet (>= 0.16, < 2.a)
govuk_app_config (9.5.0)
logstasher (~> 2.1)
opentelemetry-exporter-otlp (>= 0.25, < 0.27)
Expand All @@ -73,6 +120,15 @@ GEM
capybara (>= 3.36)
puma
selenium-webdriver (>= 4.0)
grpc (1.59.0)
google-protobuf (~> 3.24)
googleapis-common-protos-types (~> 1.0)
grpc (1.59.0-x86_64-darwin)
google-protobuf (~> 3.24)
googleapis-common-protos-types (~> 1.0)
grpc (1.59.0-x86_64-linux)
google-protobuf (~> 3.24)
googleapis-common-protos-types (~> 1.0)
hana (1.3.7)
i18n (1.14.1)
concurrent-ruby (~> 1.0)
Expand All @@ -87,6 +143,7 @@ GEM
simpleidn (~> 0.2)
jsonpath (1.1.5)
multi_json
jwt (2.7.1)
language_server-protocol (3.17.0.3)
logstasher (2.1.5)
activesupport (>= 5.2)
Expand Down Expand Up @@ -302,6 +359,7 @@ GEM
opentelemetry-semantic_conventions
opentelemetry-semantic_conventions (1.10.0)
opentelemetry-api (~> 1.0)
os (1.1.4)
parallel (1.23.0)
parser (3.2.2.4)
ast (~> 2.4.1)
Expand Down Expand Up @@ -408,6 +466,11 @@ GEM
sentry-ruby (5.12.0)
concurrent-ruby (~> 1.0, >= 1.0.2)
set (1.0.3)
signet (0.18.0)
addressable (~> 2.8)
faraday (>= 0.17.5, < 3.a)
jwt (>= 1.5, < 3.0)
multi_json (~> 1.10)
simplecov (0.22.0)
docile (~> 1.1)
simplecov-html (~> 0.11)
Expand Down Expand Up @@ -446,6 +509,7 @@ DEPENDENCIES
bootsnap
brakeman
debug
google-cloud-discovery_engine
govuk_app_config
govuk_message_queue_consumer
govuk_test
Expand Down
12 changes: 8 additions & 4 deletions lib/repositories/google_discovery_engine/repository.rb
Original file line number Diff line number Diff line change
@@ -1,10 +1,14 @@
require "google/cloud/discovery_engine"

module Repositories
module GoogleDiscoveryEngine
# A repository integrating with Google Discovery Engine
# TODO: This is just a copy of the Null repository to start off with, but it should be updated
# to integrate with the real product.
class Repository
def initialize(logger: Logger.new($stdout, progname: self.class.name))
def initialize(
client: ::Google::Cloud::DiscoveryEngine.document_service(version: :v1),
logger: Logger.new($stdout, progname: self.class.name)
)
@client = client
@logger = logger
end

Expand All @@ -25,7 +29,7 @@ def delete(content_id, payload_version: nil)

private

attr_reader :logger
attr_reader :client, :logger
end
end
end
34 changes: 34 additions & 0 deletions spec/lib/repositories/google_discovery_engine/repository_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
require "repositories/google_discovery_engine/repository"

# Require v1 specifically to instance_double it (repository itself uses non-versioned API)
require "google/cloud/discovery_engine/v1"

RSpec.describe Repositories::GoogleDiscoveryEngine::Repository do
let(:repository) { described_class.new(client:, logger:) }
let(:client) { instance_double(Google::Cloud::DiscoveryEngine::V1::DocumentService::Client) }
let(:logger) { instance_double(Logger, info: nil) }

describe "#put" do
it "logs the put operation" do
repository.put(
"some_content_id",
{ link: "/some/path" },
content: "Lorem ipsum dolor sit amet, consecutur edipiscing elit",
payload_version: "1",
)

expect(logger).to have_received(:info).with(
"[PUT some_content_id@v1] /some/path: " \
"'Lorem ipsum dolor sit amet, consecutur edipiscing e...'",
)
end
end

describe "#delete" do
it "logs the delete operation" do
repository.delete("some_content_id", payload_version: "1")

expect(logger).to have_received(:info).with("[DELETE some_content_id@v1]")
end
end
end

0 comments on commit a8163f6

Please sign in to comment.