Skip to content
This repository has been archived by the owner on Dec 23, 2024. It is now read-only.

fix(typescript): address bug with GoogleAuth types #336

Merged
merged 3 commits into from
Apr 13, 2022
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@
"license": "MIT",
"dependencies": {
"arrify": "^2.0.0",
"google-auth-library": "^7.0.0"
"google-auth-library": "^7.14.1"
},
"devDependencies": {
"@compodoc/compodoc": "^1.1.10",
Expand Down
16 changes: 12 additions & 4 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,14 @@
import arrify = require('arrify');
import {GoogleAuth, GoogleAuthOptions} from 'google-auth-library';

export interface GCEImagesConfig extends GoogleAuthOptions {
export type GCEImagesConfig = Omit<GoogleAuthOptions, 'authClient'> & {
authClient?: GoogleAuth;
/**
* The host name used to access the compute API.
* Defaults to `compute.googleapis.com`.
*/
apiEndpoint?: string;
}
};

export interface GetOptions {
deprecated?: boolean;
Expand Down Expand Up @@ -94,15 +94,23 @@ export interface OSUrls {
windows: string;
}

function isGoogleAuthOptions(
config: GoogleAuthOptions | GCEImagesConfig
): config is GoogleAuthOptions {
return !config.authClient;
}

export class GCEImages {
private _auth: GoogleAuth;
private apiEndpoint: string;
OS_URLS: OSUrls;
OS_TO_URL: {[index: string]: string};
constructor(config: GCEImagesConfig = {}) {
constructor(config: GCEImagesConfig | GoogleAuthOptions = {}) {
this.apiEndpoint = config.apiEndpoint || 'compute.googleapis.com';
config.scopes = ['https://www.googleapis.com/auth/compute'];
this._auth = config.authClient || new GoogleAuth(config);
this._auth = isGoogleAuthOptions(config)
? new GoogleAuth(config)
: config.authClient!;
const projectsPath = `https://${this.apiEndpoint}/compute/v1/projects`;
this.OS_URLS = {
centos: `${projectsPath}/centos-cloud/global/images`,
Expand Down