1 |
|
2 |
|
3 | import * as http from 'http';
|
4 | import { Storage } from './storage.js';
|
5 | import { GoogleAuth } from 'google-auth-library';
|
6 | type GoogleAuthLike = Pick<GoogleAuth, 'getCredentials' | 'sign'>;
|
7 |
|
8 |
|
9 |
|
10 | export interface AuthClient {
|
11 | sign(blobToSign: string): Promise<string>;
|
12 | getCredentials(): Promise<{
|
13 | client_email?: string;
|
14 | }>;
|
15 | }
|
16 | export interface BucketI {
|
17 | name: string;
|
18 | }
|
19 | export interface FileI {
|
20 | name: string;
|
21 | }
|
22 | export interface Query {
|
23 | [key: string]: string;
|
24 | }
|
25 | export interface GetSignedUrlConfigInternal {
|
26 | expiration: number;
|
27 | accessibleAt?: Date;
|
28 | method: string;
|
29 | extensionHeaders?: http.OutgoingHttpHeaders;
|
30 | queryParams?: Query;
|
31 | cname?: string;
|
32 | contentMd5?: string;
|
33 | contentType?: string;
|
34 | bucket: string;
|
35 | file?: string;
|
36 | |
37 |
|
38 |
|
39 |
|
40 |
|
41 |
|
42 | host?: string | URL;
|
43 | |
44 |
|
45 |
|
46 |
|
47 |
|
48 |
|
49 | signingEndpoint?: string | URL;
|
50 | }
|
51 | export interface SignerGetSignedUrlConfig {
|
52 | method: 'GET' | 'PUT' | 'DELETE' | 'POST';
|
53 | expires: string | number | Date;
|
54 | accessibleAt?: string | number | Date;
|
55 | virtualHostedStyle?: boolean;
|
56 | version?: 'v2' | 'v4';
|
57 | cname?: string;
|
58 | extensionHeaders?: http.OutgoingHttpHeaders;
|
59 | queryParams?: Query;
|
60 | contentMd5?: string;
|
61 | contentType?: string;
|
62 | |
63 |
|
64 |
|
65 |
|
66 |
|
67 |
|
68 | host?: string | URL;
|
69 | |
70 |
|
71 |
|
72 |
|
73 |
|
74 |
|
75 | signingEndpoint?: string | URL;
|
76 | }
|
77 | export type SignerGetSignedUrlResponse = string;
|
78 | export type GetSignedUrlResponse = [SignerGetSignedUrlResponse];
|
79 | export interface GetSignedUrlCallback {
|
80 | (err: Error | null, url?: string): void;
|
81 | }
|
82 | export declare enum SignerExceptionMessages {
|
83 | ACCESSIBLE_DATE_INVALID = "The accessible at date provided was invalid.",
|
84 | EXPIRATION_BEFORE_ACCESSIBLE_DATE = "An expiration date cannot be before accessible date.",
|
85 | X_GOOG_CONTENT_SHA256 = "The header X-Goog-Content-SHA256 must be a hexadecimal string."
|
86 | }
|
87 |
|
88 |
|
89 |
|
90 |
|
91 | export declare const PATH_STYLED_HOST = "https://storage.googleapis.com";
|
92 | export declare class URLSigner {
|
93 | private auth;
|
94 | private bucket;
|
95 | private file?;
|
96 | |
97 |
|
98 |
|
99 |
|
100 |
|
101 |
|
102 |
|
103 |
|
104 |
|
105 | private storage;
|
106 | constructor(auth: AuthClient | GoogleAuthLike, bucket: BucketI, file?: FileI | undefined,
|
107 | |
108 |
|
109 |
|
110 |
|
111 |
|
112 |
|
113 |
|
114 |
|
115 |
|
116 | storage?: Storage);
|
117 | getSignedUrl(cfg: SignerGetSignedUrlConfig): Promise<SignerGetSignedUrlResponse>;
|
118 | private getSignedUrlV2;
|
119 | private getSignedUrlV4;
|
120 | /**
|
121 | * Create canonical headers for signing v4 url.
|
122 | *
|
123 | * The canonical headers for v4-signing a request demands header names are
|
124 | * first lowercased, followed by sorting the header names.
|
125 | * Then, construct the canonical headers part of the request:
|
126 | * <lowercasedHeaderName> + ":" + Trim(<value>) + "\n"
|
127 | * ..
|
128 | * <lowercasedHeaderName> + ":" + Trim(<value>) + "\n"
|
129 | *
|
130 | * @param headers
|
131 | * @private
|
132 | */
|
133 | getCanonicalHeaders(headers: http.OutgoingHttpHeaders): string;
|
134 | getCanonicalRequest(method: string, path: string, query: string, headers: string, signedHeaders: string, contentSha256?: string): string;
|
135 | getCanonicalQueryParams(query: Query): string;
|
136 | getResourcePath(cname: boolean, bucket: string, file?: string): string;
|
137 | parseExpires(expires: string | number | Date, current?: Date): number;
|
138 | parseAccessibleAt(accessibleAt?: string | number | Date): number;
|
139 | }
|
140 | /**
|
141 | * Custom error type for errors related to getting signed errors and policies.
|
142 | *
|
143 | * @private
|
144 | */
|
145 | export declare class SigningError extends Error {
|
146 | name: string;
|
147 | }
|
148 | export {};
|