forked from leopardslab/nodecloud-gcp-plugin
-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
78 lines (74 loc) · 2.04 KB
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
const googleSDK = require('google-cloud');
const GoogleCompute = require('./compute/google');
const GoogleStorage = require('./storage/google-compute');
const GoogleStorageBucket = require('./storage/google-storage');
const GoogleDNS = require('./network/google-dns');
const GoogleDatastore = require('./database/google-datastore');
class Google {
/**
* Expose GCP/Google APIs
* @constructor
*/
constructor(config) {
this._googleSDK = googleSDK;
this._googleSDK._config = config;
if (!config.projectId && config.keyFilename) {
throw new Error('Provide parameters <link to docs> i.e: projectId, keyFilename');
}
return {
getSDK: () => this._googleSDK,
compute: this.googleCompute,
storage: this.googleStorage,
bucket: this.googleStorageBucket,
dns: this.googleDNS,
nosql: this.googleDatastore,
};
}
/**
* GCP compute Wrapper
* @googleCompute
* @param {object} params - { apiVersion }
*/
googleCompute(params) {
return new GoogleCompute(this.getSDK(), this._config);
}
/**
* GCP storage Wrapper
* @googleCompute
* @param {object} params - { apiVersion }
*/
googleStorage(params) {
return new GoogleStorage(this.getSDK(), this._config);
}
/**
* GCP storage bucket Wrapper
* @googleStorageBucket
* @param {object} params - { apiVersion }
*/
googleStorageBucket(params) {
if (params === undefined) {
return new GoogleStorageBucket(this.getSDK(), this._config);
}
return new GoogleStorageBucket(this.getSDK(), this._config, params.bucketName);
}
/**
* GCP DNS wrapper
* @googleDNS
* @param {object} params - { apiVersion }
*/
googleDNS(params) {
if (params === undefined) {
return new GoogleDNS(this.getSDK(), this._config);
}
return new GoogleDNS(this.getSDK(), this._config);
}
/**
* GCP Datastore wrapper
* @googleDatastore
* @param {object} params - { apiVersion }
*/
googleDatastore(params) {
return new GoogleDatastore(this.getSDK());
}
}
module.exports = Google;