Skip to content

Remove Storage AuthWrapper layer #3399

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

Merged
merged 3 commits into from
Jul 20, 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
25 changes: 25 additions & 0 deletions packages/storage/.eslintrc.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,22 @@
/**
* @license
* Copyright 2020 Google LLC
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

const path = require('path');

module.exports = {
extends: '../../config/.eslintrc.js',
parserOptions: {
Expand All @@ -14,6 +33,12 @@ module.exports = {
varsIgnorePattern: '^_',
args: 'none'
}
],
'import/no-extraneous-dependencies': [
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Are we using some devDependencies declared in the root package.json? What package was the offender? Should it be a dependency of @firebase/storage?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We're not, accidental copy-paste artifact. I only put this here because vscode for some reason doesn't process the top-level packageDir path correctly, only if it's in the package's local eslintrc.js file.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do you mean we need it here to make the eslint plugin happy?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes.

'error',
{
'packageDir': [path.resolve(__dirname, '../../'), __dirname]
}
]
}
};
6 changes: 3 additions & 3 deletions packages/storage/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ import { TaskEvent, TaskState } from './src/implementation/taskenums';

import { XhrIoPool } from './src/implementation/xhriopool';
import { Reference } from './src/reference';
import { Service } from './src/service';
import { StorageService } from './src/service';
import * as types from '@firebase/storage-types';
import {
Component,
Expand All @@ -45,7 +45,7 @@ function factory(
const app = container.getProvider('app').getImmediate();
const authProvider = container.getProvider('auth-internal');

return (new Service(
return (new StorageService(
app,
authProvider,
new XhrIoPool(),
Expand All @@ -59,7 +59,7 @@ export function registerStorage(instance: _FirebaseNamespace): void {
TaskState,
TaskEvent,
StringFormat,
Storage: Service,
Storage: StorageService,
Reference
};
instance.INTERNAL.registerComponent(
Expand Down
180 changes: 0 additions & 180 deletions packages/storage/src/implementation/authwrapper.ts

This file was deleted.

12 changes: 6 additions & 6 deletions packages/storage/src/implementation/list.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,11 @@
/**
* @fileoverview Documentation for the listOptions and listResult format
*/
import { AuthWrapper } from './authwrapper';
import { Location } from './location';
import * as json from './json';
import * as type from './type';
import { ListResult } from '../list';
import { StorageService } from '../service';

/**
* Represents the simplified object metadata returned by List API.
Expand Down Expand Up @@ -50,7 +50,7 @@ const PREFIXES_KEY = 'prefixes';
const ITEMS_KEY = 'items';

function fromBackendResponse(
authWrapper: AuthWrapper,
service: StorageService,
bucket: string,
resource: ListResultResponse
): ListResult {
Expand All @@ -62,7 +62,7 @@ function fromBackendResponse(
if (resource[PREFIXES_KEY]) {
for (const path of resource[PREFIXES_KEY]) {
const pathWithoutTrailingSlash = path.replace(/\/$/, '');
const reference = authWrapper.makeStorageReference(
const reference = service.makeStorageReference(
new Location(bucket, pathWithoutTrailingSlash)
);
listResult.prefixes.push(reference);
Expand All @@ -71,7 +71,7 @@ function fromBackendResponse(

if (resource[ITEMS_KEY]) {
for (const item of resource[ITEMS_KEY]) {
const reference = authWrapper.makeStorageReference(
const reference = service.makeStorageReference(
new Location(bucket, item['name'])
);
listResult.items.push(reference);
Expand All @@ -81,7 +81,7 @@ function fromBackendResponse(
}

export function fromResponseString(
authWrapper: AuthWrapper,
service: StorageService,
bucket: string,
resourceString: string
): ListResult | null {
Expand All @@ -90,7 +90,7 @@ export function fromResponseString(
return null;
}
const resource = (obj as unknown) as ListResultResponse;
return fromBackendResponse(authWrapper, bucket, resource);
return fromBackendResponse(service, bucket, resource);
}

export function listOptionsValidator(p: unknown): void {
Expand Down
14 changes: 7 additions & 7 deletions packages/storage/src/implementation/metadata.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,13 @@
*/
import { Metadata } from '../metadata';

import { AuthWrapper } from './authwrapper';
import * as json from './json';
import { Location } from './location';
import * as path from './path';
import * as type from './type';
import * as UrlUtils from './url';
import { Reference } from '../reference';
import { StorageService } from '../service';

export function noXform_<T>(metadata: Metadata, value: T): T {
return value;
Expand Down Expand Up @@ -114,18 +114,18 @@ export function getMappings(): Mappings {
return mappings_;
}

export function addRef(metadata: Metadata, authWrapper: AuthWrapper): void {
export function addRef(metadata: Metadata, service: StorageService): void {
function generateRef(): Reference {
const bucket: string = metadata['bucket'] as string;
const path: string = metadata['fullPath'] as string;
const loc = new Location(bucket, path);
return authWrapper.makeStorageReference(loc);
return service.makeStorageReference(loc);
}
Object.defineProperty(metadata, 'ref', { get: generateRef });
}

export function fromResource(
authWrapper: AuthWrapper,
service: StorageService,
resource: { [name: string]: unknown },
mappings: Mappings
): Metadata {
Expand All @@ -139,12 +139,12 @@ export function fromResource(
resource[mapping.server]
);
}
addRef(metadata, authWrapper);
addRef(metadata, service);
return metadata;
}

export function fromResourceString(
authWrapper: AuthWrapper,
service: StorageService,
resourceString: string,
mappings: Mappings
): Metadata | null {
Expand All @@ -153,7 +153,7 @@ export function fromResourceString(
return null;
}
const resource = obj as Metadata;
return fromResource(authWrapper, resource, mappings);
return fromResource(service, resource, mappings);
}

export function downloadUrlFromResourceString(
Expand Down
Loading