Skip to content

Commit

Permalink
feat: support apiEndpoint override (#229)
Browse files Browse the repository at this point in the history
  • Loading branch information
JustinBeckwith authored and stephenplusplus committed May 31, 2019
1 parent c7d3875 commit a0fa05d
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 3 deletions.
2 changes: 1 addition & 1 deletion packages/google-cloud-resourcemanager/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@
},
"dependencies": {
"@google-cloud/paginator": "^1.0.0",
"@google-cloud/common": "^1.0.0",
"@google-cloud/common": "^2.0.0",
"@google-cloud/promisify": "^1.0.0"
},
"devDependencies": {
Expand Down
10 changes: 9 additions & 1 deletion packages/google-cloud-resourcemanager/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,11 @@ export interface CreateProjectOptions {
export interface ClientConfig extends GoogleAuthOptions {
autoRetry?: boolean;
maxRetries?: boolean;
/**
* The API endpoint of the service used to make requests.
* Defaults to `cloudresourcemanager.googleapis.com`.
*/
apiEndpoint?: string;
}

/**
Expand Down Expand Up @@ -149,8 +154,11 @@ export interface ClientConfig extends GoogleAuthOptions {
class Resource extends Service {
getProjectsStream: Function;
constructor(options: ClientConfig = {}) {
options.apiEndpoint =
options.apiEndpoint || 'cloudresourcemanager.googleapis.com';
const config = {
baseUrl: 'https://cloudresourcemanager.googleapis.com/v1',
apiEndpoint: options.apiEndpoint,
baseUrl: `https://${options.apiEndpoint}/v1`,
scopes: ['https://www.googleapis.com/auth/cloud-platform'],
projectIdRequired: false,
packageJson: require('../../package.json'),
Expand Down
10 changes: 9 additions & 1 deletion packages/google-cloud-resourcemanager/test/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,6 @@ describe('Resource', () => {
assert(resource instanceof FakeService);

const calledWith = resource.calledWith_[0];

const baseUrl = 'https://cloudresourcemanager.googleapis.com/v1';
assert.strictEqual(calledWith.baseUrl, baseUrl);
assert.deepStrictEqual(calledWith.scopes, [
Expand All @@ -151,6 +150,15 @@ describe('Resource', () => {
require('../../package.json')
);
});

it('should allow overriding the apiEndpoint', () => {
const apiEndpoint = 'fake.endpoint';
resource = new Resource({
apiEndpoint,
});
const calledWith = resource.calledWith_[0];
assert.strictEqual(calledWith.baseUrl, `https://${apiEndpoint}/v1`);
});
});

describe('createProject', () => {
Expand Down

0 comments on commit a0fa05d

Please sign in to comment.