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