@genoacms/adapter-gcp 0.7.1-fix.1 → 0.7.1-fix.3
Sign up to get free protection for your applications and to get access to all the features.
- package/dist/services/authorization/index.js +2 -1
- package/dist/services/database/index.js +2 -1
- package/dist/services/storage/storage.js +8 -3
- package/package.json +1 -1
- package/src/services/authorization/index.ts +2 -1
- package/src/services/database/index.ts +2 -1
- package/src/services/storage/storage.ts +10 -4
@@ -1,6 +1,7 @@
|
|
1
1
|
import config from '../../config.js';
|
2
2
|
import { ProjectsClient } from '@google-cloud/resource-manager';
|
3
|
-
const
|
3
|
+
const PROVIDER_NAME = '@genoacms/adapter-gcp/authorization';
|
4
|
+
const authorizationConfig = config.authorization.providers.find((provider) => provider.name === PROVIDER_NAME);
|
4
5
|
if (!authorizationConfig)
|
5
6
|
throw new Error('authorization-provider-not-found');
|
6
7
|
const projectId = authorizationConfig.projectId;
|
@@ -1,6 +1,7 @@
|
|
1
1
|
import config from '../../config.js';
|
2
2
|
import { Firestore } from '@google-cloud/firestore';
|
3
|
-
const
|
3
|
+
const PROVIDER_NAME = '@genoacms/adapter-gcp/database';
|
4
|
+
const firestoreConfig = config.database.providers.find((provider) => provider.name === PROVIDER_NAME);
|
4
5
|
if (!firestoreConfig)
|
5
6
|
throw new Error('firestore-provider-not-found');
|
6
7
|
const firestore = new Firestore({
|
@@ -1,13 +1,18 @@
|
|
1
1
|
import config from '../../config.js';
|
2
2
|
import { Storage } from '@google-cloud/storage';
|
3
|
-
const
|
3
|
+
const PROVIDER_NAME = '@genoacms/adapter-gcp/storage';
|
4
|
+
const storageConfig = config.storage.providers.find((provider) => provider.name === PROVIDER_NAME);
|
4
5
|
if (!storageConfig)
|
5
6
|
throw new Error('storage-provider-not-found');
|
6
7
|
const storage = new Storage({
|
7
|
-
credentials:
|
8
|
+
credentials: storageConfig.credentials
|
8
9
|
});
|
10
|
+
const hasBucket = (name) => {
|
11
|
+
const has = config.storage.buckets.find((bucket) => bucket.name === name && bucket.providerName === PROVIDER_NAME);
|
12
|
+
return !!has;
|
13
|
+
};
|
9
14
|
const getBucket = (name) => {
|
10
|
-
if (!
|
15
|
+
if (!hasBucket(name))
|
11
16
|
throw new Error('bucket-unregistered');
|
12
17
|
const bucket = storage.bucket(name);
|
13
18
|
return bucket;
|
package/package.json
CHANGED
@@ -2,7 +2,8 @@ import type { Adapter, AuthorizationProvider } from '@genoacms/cloudabstraction/
|
|
2
2
|
import config from '../../config.js'
|
3
3
|
import { ProjectsClient } from '@google-cloud/resource-manager'
|
4
4
|
|
5
|
-
const
|
5
|
+
const PROVIDER_NAME = '@genoacms/adapter-gcp/authorization'
|
6
|
+
const authorizationConfig = config.authorization.providers.find((provider: AuthorizationProvider) => provider.name === PROVIDER_NAME)
|
6
7
|
if (!authorizationConfig) throw new Error('authorization-provider-not-found')
|
7
8
|
const projectId = authorizationConfig.projectId
|
8
9
|
const resourceManager = new ProjectsClient({
|
@@ -10,7 +10,8 @@ import type {
|
|
10
10
|
import config from '../../config.js'
|
11
11
|
import { Firestore } from '@google-cloud/firestore'
|
12
12
|
|
13
|
-
const
|
13
|
+
const PROVIDER_NAME = '@genoacms/adapter-gcp/database'
|
14
|
+
const firestoreConfig = config.database.providers.find((provider: DatabaseProvider) => provider.name === PROVIDER_NAME)
|
14
15
|
if (!firestoreConfig) throw new Error('firestore-provider-not-found')
|
15
16
|
const firestore = new Firestore({
|
16
17
|
credentials: firestoreConfig.credentials,
|
@@ -1,15 +1,21 @@
|
|
1
1
|
import config from '../../config.js'
|
2
2
|
import { type Bucket, Storage } from '@google-cloud/storage'
|
3
|
-
import type { StorageProvider } from '@genoacms/cloudabstraction/storage'
|
3
|
+
import type { StorageProvider, BucketInit } from '@genoacms/cloudabstraction/storage'
|
4
4
|
|
5
|
-
const
|
5
|
+
const PROVIDER_NAME = '@genoacms/adapter-gcp/storage'
|
6
|
+
const storageConfig = config.storage.providers.find((provider: StorageProvider) => provider.name === PROVIDER_NAME)
|
6
7
|
if (!storageConfig) throw new Error('storage-provider-not-found')
|
7
8
|
const storage = new Storage({
|
8
|
-
credentials:
|
9
|
+
credentials: storageConfig.credentials
|
9
10
|
})
|
10
11
|
|
12
|
+
const hasBucket = (name: string): boolean => {
|
13
|
+
const has = config.storage.buckets.find((bucket: BucketInit) => bucket.name === name && bucket.providerName === PROVIDER_NAME)
|
14
|
+
return !!has
|
15
|
+
}
|
16
|
+
|
11
17
|
const getBucket = (name: string): Bucket => {
|
12
|
-
if (!
|
18
|
+
if (!hasBucket(name)) throw new Error('bucket-unregistered')
|
13
19
|
const bucket = storage.bucket(name)
|
14
20
|
return bucket
|
15
21
|
}
|