Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 7 additions & 2 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -504,8 +504,13 @@ class Datastore extends DatastoreRequest {
},
options
);
if (this.customEndpoint_) {
this.options.sslCreds = grpc.credentials.createInsecure();
const isUsingEmulator =
this.baseUrl_ &&
(this.baseUrl_.includes('localhost') ||
this.baseUrl_.includes('127.0.0.1') ||
this.baseUrl_.includes('::1'));
if (this.customEndpoint_ && isUsingEmulator) {
this.options.sslCreds ??= grpc.credentials.createInsecure();
}

this.auth = new GoogleAuth(this.options);
Expand Down
12 changes: 12 additions & 0 deletions system-test/datastore.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1360,4 +1360,16 @@ describe('Datastore', () => {
await importOperation.cancel();
});
});

describe('using a custom endpoint', () => {
it('should complete a request when using the default endpoint as a custom endpoint', async () => {
const customDatastore = new Datastore({
namespace: `${Date.now()}`,
apiEndpoint: 'datastore.googleapis.com',
});
const query = customDatastore.createQuery('Kind').select('__key__');
const [entities] = await customDatastore.runQuery(query);
assert.strictEqual(entities.length, 0);
});
});
});
11 changes: 2 additions & 9 deletions test/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@ describe('Datastore', () => {

const OPTIONS = {
projectId: PROJECT_ID,
apiEndpoint: 'http://endpoint',
apiEndpoint: 'http://localhost',
credentials: {},
keyFilename: 'key/file',
email: 'email',
Expand Down Expand Up @@ -289,14 +289,7 @@ describe('Datastore', () => {
assert.strictEqual((datastore.options as any).port, port);
});

it('should set grpc ssl credentials if custom endpoint', () => {
const determineBaseUrl_ = Datastore.prototype.determineBaseUrl_;

Datastore.prototype.determineBaseUrl_ = function () {
Datastore.prototype.determineBaseUrl_ = determineBaseUrl_;
this.customEndpoint_ = true;
};

it('should set grpc ssl credentials if localhost custom endpoint', () => {
const fakeInsecureCreds = {};
createInsecureOverride = () => {
return fakeInsecureCreds;
Expand Down