Skip to content

Commit

Permalink
fix: Add endpoint override for Document AI Warehouse samples (#3585)
Browse files Browse the repository at this point in the history
* fix: Add endpoint override for Document AI Warehouse samples

- Reported in:
  - GoogleCloudPlatform/document-ai-samples#676
  - https://www.googlecloudcommunity.com/gc/AI-ML/Document-AI-Warehouse-API-Sample-Python-Code-location-eu-Issue/td-p/677608
  - https://stackoverflow.com/a/77648118/6216983

## Description

Fixes GoogleCloudPlatform/document-ai-samples#676

* Try changing endpoint to default for us

* Change default endpoint to us

* Fix formatting error

---------

Co-authored-by: Patti Shin <[email protected]>
  • Loading branch information
holtskinner and pattishin authored Dec 13, 2023
1 parent e6153a9 commit a7ed03c
Show file tree
Hide file tree
Showing 8 changed files with 77 additions and 27 deletions.
45 changes: 26 additions & 19 deletions document-warehouse/create-document-schema.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,31 +31,38 @@ async function main(
const {DocumentSchemaServiceClient} =
require('@google-cloud/contentwarehouse').v1;

const apiEndpoint =
location === 'us'
? 'contentwarehouse.googleapis.com'
: `${location}-contentwarehouse.googleapis.com`;

// Create service client
const serviceClient = new DocumentSchemaServiceClient();
const serviceClient = new DocumentSchemaServiceClient({
apiEndpoint: apiEndpoint,
});

// Create Document Schema
async function createDocumentSchema() {
// Initialize request argument(s)
const request = {};

// Property Definition
const propertyDefinition = {};
propertyDefinition.name = 'testPropertyDefinitionName'; // Must be unique within a document schema (case insensitive)
propertyDefinition.displayName = 'searchable text';
propertyDefinition.isSearchable = true;
propertyDefinition.textTypeOptions = {};

// Document Schema
const documentSchema = {};
documentSchema.displayName = 'My Test Schema';
documentSchema.propertyDefinitions = [propertyDefinition];

request.documentSchema = documentSchema;

// The full resource name of the location, e.g.:
// projects/{project_number}/locations/{location}
request.parent = `projects/${projectNumber}/locations/${location}`;
const parent = `projects/${projectNumber}/locations/${location}`;
// Initialize request argument(s)
const request = {
parent: parent,
// Document Schema
documentSchema: {
displayName: 'My Test Schema',
// Property Definition
propertyDefinitions: [
{
name: 'testPropertyDefinitionName', // Must be unique within a document schema (case insensitive)
displayName: 'searchable text',
isSearchable: true,
textTypeOptions: {},
},
],
},
};

// Make Request
const response = serviceClient.createDocumentSchema(request);
Expand Down
9 changes: 8 additions & 1 deletion document-warehouse/delete-document-schema.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,15 @@ async function main(
const {DocumentSchemaServiceClient} =
require('@google-cloud/contentwarehouse').v1;

const apiEndpoint =
location === 'us'
? 'contentwarehouse.googleapis.com'
: `${location}-contentwarehouse.googleapis.com`;

// Create service client
const serviceClient = new DocumentSchemaServiceClient();
const serviceClient = new DocumentSchemaServiceClient({
apiEndpoint: apiEndpoint,
});

// Delete Document Schema
async function deleteDocumentSchema() {
Expand Down
7 changes: 6 additions & 1 deletion document-warehouse/fetch-acl.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,13 @@ async function main(
// Import from google cloud
const {DocumentServiceClient} = require('@google-cloud/contentwarehouse').v1;

const apiEndpoint =
location === 'us'
? 'contentwarehouse.googleapis.com'
: `${location}-contentwarehouse.googleapis.com`;

// Create service client
const serviceClient = new DocumentServiceClient();
const serviceClient = new DocumentServiceClient({apiEndpoint: apiEndpoint});

// Fetches access control policies on project or document level.
async function fetchACL() {
Expand Down
9 changes: 8 additions & 1 deletion document-warehouse/get-document-schema.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,15 @@ async function main(
const {DocumentSchemaServiceClient} =
require('@google-cloud/contentwarehouse').v1;

const apiEndpoint =
location === 'us'
? 'contentwarehouse.googleapis.com'
: `${location}-contentwarehouse.googleapis.com`;

// Create service client
const serviceClient = new DocumentSchemaServiceClient();
const serviceClient = new DocumentSchemaServiceClient({
apiEndpoint: apiEndpoint,
});

// Get Document Schema
async function getDocumentSchema() {
Expand Down
9 changes: 8 additions & 1 deletion document-warehouse/get-document.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,15 @@ async function main(
// Import from google cloud
const {DocumentServiceClient} = require('@google-cloud/contentwarehouse').v1;

const apiEndpoint =
location === 'us'
? 'contentwarehouse.googleapis.com'
: `${location}-contentwarehouse.googleapis.com`;

// Create service client
const serviceClient = new DocumentServiceClient();
const serviceClient = new DocumentServiceClient({
apiEndpoint: apiEndpoint,
});

// Get Document Schema
async function getDocument() {
Expand Down
11 changes: 9 additions & 2 deletions document-warehouse/quickstart.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,16 @@ async function main(
const {DocumentSchemaServiceClient, DocumentServiceClient} =
require('@google-cloud/contentwarehouse').v1;

const apiEndpoint =
location === 'us'
? 'contentwarehouse.googleapis.com'
: `${location}-contentwarehouse.googleapis.com`;

// Create service client
const schemaClient = new DocumentSchemaServiceClient();
const serviceClient = new DocumentServiceClient();
const schemaClient = new DocumentSchemaServiceClient({
apiEndpoint: apiEndpoint,
});
const serviceClient = new DocumentServiceClient({apiEndpoint: apiEndpoint});

// Get Document Schema
async function quickstart() {
Expand Down
7 changes: 6 additions & 1 deletion document-warehouse/search-document.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,13 @@ async function main(
// Import from google cloud
const {DocumentServiceClient} = require('@google-cloud/contentwarehouse').v1;

const apiEndpoint =
location === 'us'
? 'contentwarehouse.googleapis.com'
: `${location}-contentwarehouse.googleapis.com`;

// Create service client
const serviceClient = new DocumentServiceClient();
const serviceClient = new DocumentServiceClient({apiEndpoint: apiEndpoint});

// Get Document Schema
async function searchDocuments() {
Expand Down
7 changes: 6 additions & 1 deletion document-warehouse/set-acl.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,13 @@ async function main(
//Import service client from google cloud
const {DocumentServiceClient} = require('@google-cloud/contentwarehouse').v1;

const apiEndpoint =
location === 'us'
? 'contentwarehouse.googleapis.com'
: `${location}-contentwarehouse.googleapis.com`;

// Create client
const serviceClient = new DocumentServiceClient();
const serviceClient = new DocumentServiceClient({apiEndpoint: apiEndpoint});

// Set access control policies on project or document level.
async function setACL() {
Expand Down

0 comments on commit a7ed03c

Please sign in to comment.