Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use GCS REST API in place of Firebase Storage REST API. #2343

Merged
merged 3 commits into from
Jun 8, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
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
4 changes: 2 additions & 2 deletions src/extensions/extensionsHelper.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import * as _ from "lodash";
import * as ora from "ora";

import { firebaseStorageOrigin } from "../api";
import { storageOrigin } from "../api";
import { archiveDirectory } from "../archiveDirectory";
import { convertOfficialExtensionsToList } from "./utils";
import { getFirebaseConfig } from "../functionsConfig";
Expand Down Expand Up @@ -336,7 +336,7 @@ export async function createSourceFromLocation(
uploadSpinner.start();
objectPath = await archiveAndUploadSource(sourceUri, EXTENSIONS_BUCKET_NAME);
uploadSpinner.succeed(" Uploaded extension source code");
packageUri = firebaseStorageOrigin + objectPath + "?alt=media";
packageUri = storageOrigin + objectPath + "?alt=media";
extensionRoot = "/";
} catch (err) {
uploadSpinner.fail();
Expand Down
8 changes: 4 additions & 4 deletions src/gcp/storage.js
Original file line number Diff line number Diff line change
Expand Up @@ -56,16 +56,16 @@ async function _uploadObject(source, bucketName) {
if (path.extname(source.file) !== ".zip") {
throw new FirebaseError(`Expected a file name ending in .zip, got ${source.file}`);
}
const location = `/v0/b/${bucketName}/o/${path.basename(source.file)}`;
await api.request("POST", location, {
const location = `/${bucketName}/${path.basename(source.file)}`;
await api.request("PUT", location, {
taeold marked this conversation as resolved.
Show resolved Hide resolved
auth: true,
data: source.stream,
headers: {
"Content-Type": "application/zip",
"x-goog-content-length-range": "0,123289600",
},
json: false,
origin: api.firebaseStorageOrigin,
origin: api.storageOrigin,
logOptions: { skipRequestBody: true },
});
return location;
Expand All @@ -78,7 +78,7 @@ async function _uploadObject(source, bucketName) {
function _deleteObject(location) {
return api.request("DELETE", location, {
auth: true,
origin: api.firebaseStorageOrigin,
origin: api.storageOrigin,
});
}

Expand Down
9 changes: 4 additions & 5 deletions src/test/extensions/extensionsHelper.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -648,8 +648,7 @@ describe("extensionsHelper", () => {
let uploadStub: sinon.SinonStub;
let createSourceStub: sinon.SinonStub;
let deleteStub: sinon.SinonStub;
const testUrl =
"https://firebasestorage.googleapis.com/v0/b/firebase-ext-eap-uploads/o/object.zip";
const testUrl = "https://storage.googleapis.com/firebase-ext-eap-uploads/object.zip";
const testSource = {
name: "test",
packageUri: testUrl,
Expand All @@ -665,7 +664,7 @@ describe("extensionsHelper", () => {
archiveStub = sinon.stub(archiveDirectory, "archiveDirectory").resolves({});
uploadStub = sinon
.stub(storage, "uploadObject")
.resolves("/v0/b/firebase-ext-eap-uploads/o/object.zip");
.resolves("/firebase-ext-eap-uploads/object.zip");
createSourceStub = sinon.stub(extensionsApi, "createSource").resolves(testSource);
deleteStub = sinon.stub(storage, "deleteObject").resolves();
});
Expand All @@ -682,7 +681,7 @@ describe("extensionsHelper", () => {
expect(uploadStub).to.have.been.calledWith({}, extensionsHelper.EXTENSIONS_BUCKET_NAME);
expect(createSourceStub).to.have.been.calledWith("test-proj", testUrl + "?alt=media", "/");
expect(deleteStub).to.have.been.calledWith(
`/v0/b/${extensionsHelper.EXTENSIONS_BUCKET_NAME}/o/object.zip`
`/${extensionsHelper.EXTENSIONS_BUCKET_NAME}/object.zip`
);
});

Expand All @@ -696,7 +695,7 @@ describe("extensionsHelper", () => {
expect(uploadStub).to.have.been.calledWith({}, extensionsHelper.EXTENSIONS_BUCKET_NAME);
expect(createSourceStub).to.have.been.calledWith("test-proj", testUrl + "?alt=media", "/");
expect(deleteStub).to.have.been.calledWith(
`/v0/b/${extensionsHelper.EXTENSIONS_BUCKET_NAME}/o/object.zip`
`/${extensionsHelper.EXTENSIONS_BUCKET_NAME}/object.zip`
);
});

Expand Down