Skip to content

Commit

Permalink
chore: simplify Config
Browse files Browse the repository at this point in the history
  • Loading branch information
erickzhao committed Nov 3, 2023
1 parent a5f5f00 commit f760761
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 45 deletions.
30 changes: 4 additions & 26 deletions packages/publisher/gcs/src/Config.ts
Original file line number Diff line number Diff line change
@@ -1,33 +1,11 @@
import { PredefinedAcl } from '@google-cloud/storage';
import { PredefinedAcl, StorageOptions } from '@google-cloud/storage';

export interface PublisherGCSConfig {
/**
* The path to the file that is either:
* - the JSON file that contains your Google service account credentials, or
* - the PEM/PKCS #12-formatted file that contains the private key.
*
* Defaults to the value in the `GOOGLE_APPLICATION_CREDENTIALS` environment variable.
*/
keyFilename?: string;
/**
* The Google Cloud project ID.
*
* Defaults to the value in the `GOOGLE_CLOUD_PROJECT` environment variable.
* */
projectId?: string;
/**
* The email for your Google service account, *required* when using a PEM/PKCS #12-formatted
* file in the [[keyFilename]] option.
*
* Defaults to the value in the `GOOGLE_CLOUD_CLIENT_EMAIL` environment variable.
*/
clientEmail?: string;
/**
* The private key for your Google service account.
*
* Defaults to the value in the `GOOGLE_CLOUD_PRIVATE_KEY` environment variable.
* Options passed into the `Storage` client constructor.
* See https://cloud.google.com/nodejs/docs/reference/storage/latest/storage/storage for full reference.
*/
privateKey?: string;
storageOptions: StorageOptions;
/**
* The name of the Google Cloud Storage bucket where artifacts are uploaded.
*/
Expand Down
20 changes: 1 addition & 19 deletions packages/publisher/gcs/src/PublisherGCS.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ import path from 'path';
import { PublisherBase, PublisherOptions } from '@electron-forge/publisher-base';
import { Storage } from '@google-cloud/storage';
import debug from 'debug';
import { CredentialBody } from 'google-auth-library';

import { PublisherGCSConfig } from './Config';

Expand Down Expand Up @@ -41,11 +40,7 @@ export default class PublisherGCS extends PublisherBase<PublisherGCSConfig> {
);
}

const storage = new Storage({
keyFilename: this.config.keyFilename,
credentials: this.generateCredentials(),
projectId: this.config.projectId,
});
const storage = new Storage(this.config.storageOptions);

const bucket = storage.bucket(this.config.bucket);

Expand Down Expand Up @@ -80,19 +75,6 @@ export default class PublisherGCS extends PublisherBase<PublisherGCSConfig> {

return `${artifact.keyPrefix}/${artifact.platform}/${artifact.arch}/${path.basename(artifact.path)}`;
}

generateCredentials(): CredentialBody | undefined {
const clientEmail = this.config.clientEmail;
const privateKey = this.config.privateKey;

if (clientEmail && privateKey) {
return {
client_email: clientEmail,
private_key: privateKey,
};
}
return undefined;
}
}

export { PublisherGCS, PublisherGCSConfig };

0 comments on commit f760761

Please sign in to comment.