@rytass/secret-adapter-vault-nestjs 0.1.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.md +30 -0
- package/index.cjs.js +134 -0
- package/index.d.ts +2 -0
- package/index.js +2 -0
- package/module.d.ts +2 -0
- package/module.js +33 -0
- package/package.json +38 -0
- package/service.d.ts +8 -0
- package/service.js +99 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2022 Rytass Co. Ltd.
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
# Rytass Utils - Secret Manager Nestjs Module (Vault)
|
|
2
|
+
|
|
3
|
+
### Getting Started
|
|
4
|
+
|
|
5
|
+
This module will get vault config from env with @nestjs/common, please set following env before use.
|
|
6
|
+
|
|
7
|
+
- VAULT_HOST (Vault service base url)
|
|
8
|
+
- VAULT_ACCOUNT
|
|
9
|
+
- VAULT_PASSWORD
|
|
10
|
+
- VAULT_PATH (Vault secret path from root)
|
|
11
|
+
|
|
12
|
+
```typescript
|
|
13
|
+
import { Module } from '@nestjs/common';
|
|
14
|
+
import { VaultService, VaultModule } from '@rytass/secret-adapter-vault-nestjs';
|
|
15
|
+
|
|
16
|
+
@Injectable()
|
|
17
|
+
class TestService {
|
|
18
|
+
constructor(private readonly vault: VaultService) {}
|
|
19
|
+
|
|
20
|
+
async getValue() {
|
|
21
|
+
return vault.get<string>('key');
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
@Module({
|
|
26
|
+
imports: [VaultModule],
|
|
27
|
+
providers: [TestService],
|
|
28
|
+
})
|
|
29
|
+
class TestModule {};
|
|
30
|
+
```
|
package/index.cjs.js
ADDED
|
@@ -0,0 +1,134 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
|
+
|
|
5
|
+
var common = require('@nestjs/common');
|
|
6
|
+
var config = require('@nestjs/config');
|
|
7
|
+
var regeneratorRuntime = require('regenerator-runtime');
|
|
8
|
+
var secretAdapterVault = require('@rytass/secret-adapter-vault');
|
|
9
|
+
|
|
10
|
+
function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e["default"] : e; }
|
|
11
|
+
|
|
12
|
+
var regeneratorRuntime__default = /*#__PURE__*/_interopDefaultLegacy(regeneratorRuntime);
|
|
13
|
+
|
|
14
|
+
function asyncGeneratorStep(gen, resolve, reject, _next, _throw, key, arg) {
|
|
15
|
+
try {
|
|
16
|
+
var info = gen[key](arg);
|
|
17
|
+
var value = info.value;
|
|
18
|
+
} catch (error) {
|
|
19
|
+
reject(error);
|
|
20
|
+
return;
|
|
21
|
+
}
|
|
22
|
+
if (info.done) {
|
|
23
|
+
resolve(value);
|
|
24
|
+
} else {
|
|
25
|
+
Promise.resolve(value).then(_next, _throw);
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
function _asyncToGenerator(fn) {
|
|
29
|
+
return function() {
|
|
30
|
+
var self = this, args = arguments;
|
|
31
|
+
return new Promise(function(resolve, reject) {
|
|
32
|
+
var gen = fn.apply(self, args);
|
|
33
|
+
function _next(value) {
|
|
34
|
+
asyncGeneratorStep(gen, resolve, reject, _next, _throw, "next", value);
|
|
35
|
+
}
|
|
36
|
+
function _throw(err) {
|
|
37
|
+
asyncGeneratorStep(gen, resolve, reject, _next, _throw, "throw", err);
|
|
38
|
+
}
|
|
39
|
+
_next(undefined);
|
|
40
|
+
});
|
|
41
|
+
};
|
|
42
|
+
}
|
|
43
|
+
function _classCallCheck$1(instance, Constructor) {
|
|
44
|
+
if (!(instance instanceof Constructor)) {
|
|
45
|
+
throw new TypeError("Cannot call a class as a function");
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
var __decorate$1 = undefined && undefined.__decorate || function(decorators, target, key, desc) {
|
|
49
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
50
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
51
|
+
else for(var i = decorators.length - 1; i >= 0; i--)if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
52
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
53
|
+
};
|
|
54
|
+
exports.VaultService = /*#__PURE__*/ function() {
|
|
55
|
+
function VaultService(config) {
|
|
56
|
+
var _this = this;
|
|
57
|
+
_classCallCheck$1(this, VaultService);
|
|
58
|
+
this.config = config;
|
|
59
|
+
this.onReadyCallbacks = [];
|
|
60
|
+
var host = config.get("VAULT_HOST");
|
|
61
|
+
var user = config.get("VAULT_ACCOUNT");
|
|
62
|
+
var pass = config.get("VAULT_PASSWORD");
|
|
63
|
+
var path = config.get("VAULT_PATH");
|
|
64
|
+
this.manager = new secretAdapterVault.VaultSecret(path, {
|
|
65
|
+
host: host,
|
|
66
|
+
auth: {
|
|
67
|
+
account: user,
|
|
68
|
+
password: pass
|
|
69
|
+
},
|
|
70
|
+
onReady: function() {
|
|
71
|
+
_this.onReadyCallbacks.forEach(function(done) {
|
|
72
|
+
return done();
|
|
73
|
+
});
|
|
74
|
+
}
|
|
75
|
+
});
|
|
76
|
+
}
|
|
77
|
+
var _proto = VaultService.prototype;
|
|
78
|
+
_proto.get = function get(key) {
|
|
79
|
+
var _this = this;
|
|
80
|
+
return _asyncToGenerator(regeneratorRuntime__default.mark(function _callee() {
|
|
81
|
+
return regeneratorRuntime__default.wrap(function _callee$(_ctx) {
|
|
82
|
+
while(1)switch(_ctx.prev = _ctx.next){
|
|
83
|
+
case 0:
|
|
84
|
+
if (!(_this.manager.state === secretAdapterVault.VaultSecretState.READY)) {
|
|
85
|
+
_ctx.next = 2;
|
|
86
|
+
break;
|
|
87
|
+
}
|
|
88
|
+
return _ctx.abrupt("return", _this.manager.get(key));
|
|
89
|
+
case 2:
|
|
90
|
+
return _ctx.abrupt("return", new Promise(function(resolve) {
|
|
91
|
+
_this.onReadyCallbacks.push(function() {
|
|
92
|
+
resolve(_this.manager.get(key));
|
|
93
|
+
});
|
|
94
|
+
}));
|
|
95
|
+
case 3:
|
|
96
|
+
case "end":
|
|
97
|
+
return _ctx.stop();
|
|
98
|
+
}
|
|
99
|
+
}, _callee);
|
|
100
|
+
}))();
|
|
101
|
+
};
|
|
102
|
+
return VaultService;
|
|
103
|
+
}();
|
|
104
|
+
exports.VaultService = __decorate$1([
|
|
105
|
+
common.Injectable()
|
|
106
|
+
], exports.VaultService);
|
|
107
|
+
|
|
108
|
+
function _classCallCheck(instance, Constructor) {
|
|
109
|
+
if (!(instance instanceof Constructor)) {
|
|
110
|
+
throw new TypeError("Cannot call a class as a function");
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
var __decorate = undefined && undefined.__decorate || function(decorators, target, key, desc) {
|
|
114
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
115
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
116
|
+
else for(var i = decorators.length - 1; i >= 0; i--)if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
117
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
118
|
+
};
|
|
119
|
+
exports.VaultModule = function VaultModule() {
|
|
120
|
+
_classCallCheck(this, VaultModule);
|
|
121
|
+
};
|
|
122
|
+
exports.VaultModule = __decorate([
|
|
123
|
+
common.Module({
|
|
124
|
+
imports: [
|
|
125
|
+
config.ConfigModule.forRoot()
|
|
126
|
+
],
|
|
127
|
+
providers: [
|
|
128
|
+
exports.VaultService
|
|
129
|
+
],
|
|
130
|
+
exports: [
|
|
131
|
+
exports.VaultService
|
|
132
|
+
]
|
|
133
|
+
})
|
|
134
|
+
], exports.VaultModule);
|
package/index.d.ts
ADDED
package/index.js
ADDED
package/module.d.ts
ADDED
package/module.js
ADDED
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import { Module } from '@nestjs/common';
|
|
2
|
+
import { ConfigModule } from '@nestjs/config';
|
|
3
|
+
import { VaultService } from './service.js';
|
|
4
|
+
|
|
5
|
+
function _classCallCheck(instance, Constructor) {
|
|
6
|
+
if (!(instance instanceof Constructor)) {
|
|
7
|
+
throw new TypeError("Cannot call a class as a function");
|
|
8
|
+
}
|
|
9
|
+
}
|
|
10
|
+
var __decorate = undefined && undefined.__decorate || function(decorators, target, key, desc) {
|
|
11
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
12
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
13
|
+
else for(var i = decorators.length - 1; i >= 0; i--)if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
14
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
15
|
+
};
|
|
16
|
+
var VaultModule = function VaultModule() {
|
|
17
|
+
_classCallCheck(this, VaultModule);
|
|
18
|
+
};
|
|
19
|
+
VaultModule = __decorate([
|
|
20
|
+
Module({
|
|
21
|
+
imports: [
|
|
22
|
+
ConfigModule.forRoot()
|
|
23
|
+
],
|
|
24
|
+
providers: [
|
|
25
|
+
VaultService
|
|
26
|
+
],
|
|
27
|
+
exports: [
|
|
28
|
+
VaultService
|
|
29
|
+
]
|
|
30
|
+
})
|
|
31
|
+
], VaultModule);
|
|
32
|
+
|
|
33
|
+
export { VaultModule };
|
package/package.json
ADDED
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@rytass/secret-adapter-vault-nestjs",
|
|
3
|
+
"version": "0.1.3",
|
|
4
|
+
"description": "Rytass Sceret Vault nestjs adapter",
|
|
5
|
+
"keywords": [
|
|
6
|
+
"rytass",
|
|
7
|
+
"secret",
|
|
8
|
+
"vault",
|
|
9
|
+
"nestjs"
|
|
10
|
+
],
|
|
11
|
+
"author": "Chia Yu Pai <fantasyatelier@gmail.com>",
|
|
12
|
+
"homepage": "https://github.com/Rytass/Utils#readme",
|
|
13
|
+
"license": "MIT",
|
|
14
|
+
"repository": {
|
|
15
|
+
"type": "git",
|
|
16
|
+
"url": "git+https://github.com/Rytass/Utils.git"
|
|
17
|
+
},
|
|
18
|
+
"bugs": {
|
|
19
|
+
"url": "https://github.com/Rytass/Utils/issues"
|
|
20
|
+
},
|
|
21
|
+
"peerDependencies": {
|
|
22
|
+
"@nestjs/common": "^9.0.11",
|
|
23
|
+
"@nestjs/config": "^2.2.0",
|
|
24
|
+
"reflect-metadata": "^0.1.13"
|
|
25
|
+
},
|
|
26
|
+
"dependencies": {
|
|
27
|
+
"@rytass/secret-adapter-vault": "^0.1.2"
|
|
28
|
+
},
|
|
29
|
+
"devDependencies": {
|
|
30
|
+
"@nestjs/common": "^9.0.11",
|
|
31
|
+
"@nestjs/config": "^2.2.0",
|
|
32
|
+
"axios": "^0.27.2",
|
|
33
|
+
"reflect-metadata": "^0.1.13"
|
|
34
|
+
},
|
|
35
|
+
"main": "./index.cjs.js",
|
|
36
|
+
"module": "./index.js",
|
|
37
|
+
"typings": "./index.d.ts"
|
|
38
|
+
}
|
package/service.d.ts
ADDED
package/service.js
ADDED
|
@@ -0,0 +1,99 @@
|
|
|
1
|
+
import regeneratorRuntime from 'regenerator-runtime';
|
|
2
|
+
import { Injectable } from '@nestjs/common';
|
|
3
|
+
import { VaultSecretState, VaultSecret } from '@rytass/secret-adapter-vault';
|
|
4
|
+
|
|
5
|
+
function asyncGeneratorStep(gen, resolve, reject, _next, _throw, key, arg) {
|
|
6
|
+
try {
|
|
7
|
+
var info = gen[key](arg);
|
|
8
|
+
var value = info.value;
|
|
9
|
+
} catch (error) {
|
|
10
|
+
reject(error);
|
|
11
|
+
return;
|
|
12
|
+
}
|
|
13
|
+
if (info.done) {
|
|
14
|
+
resolve(value);
|
|
15
|
+
} else {
|
|
16
|
+
Promise.resolve(value).then(_next, _throw);
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
function _asyncToGenerator(fn) {
|
|
20
|
+
return function() {
|
|
21
|
+
var self = this, args = arguments;
|
|
22
|
+
return new Promise(function(resolve, reject) {
|
|
23
|
+
var gen = fn.apply(self, args);
|
|
24
|
+
function _next(value) {
|
|
25
|
+
asyncGeneratorStep(gen, resolve, reject, _next, _throw, "next", value);
|
|
26
|
+
}
|
|
27
|
+
function _throw(err) {
|
|
28
|
+
asyncGeneratorStep(gen, resolve, reject, _next, _throw, "throw", err);
|
|
29
|
+
}
|
|
30
|
+
_next(undefined);
|
|
31
|
+
});
|
|
32
|
+
};
|
|
33
|
+
}
|
|
34
|
+
function _classCallCheck(instance, Constructor) {
|
|
35
|
+
if (!(instance instanceof Constructor)) {
|
|
36
|
+
throw new TypeError("Cannot call a class as a function");
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
var __decorate = undefined && undefined.__decorate || function(decorators, target, key, desc) {
|
|
40
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
41
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
42
|
+
else for(var i = decorators.length - 1; i >= 0; i--)if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
43
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
44
|
+
};
|
|
45
|
+
var VaultService = /*#__PURE__*/ function() {
|
|
46
|
+
function VaultService(config) {
|
|
47
|
+
var _this = this;
|
|
48
|
+
_classCallCheck(this, VaultService);
|
|
49
|
+
this.config = config;
|
|
50
|
+
this.onReadyCallbacks = [];
|
|
51
|
+
var host = config.get("VAULT_HOST");
|
|
52
|
+
var user = config.get("VAULT_ACCOUNT");
|
|
53
|
+
var pass = config.get("VAULT_PASSWORD");
|
|
54
|
+
var path = config.get("VAULT_PATH");
|
|
55
|
+
this.manager = new VaultSecret(path, {
|
|
56
|
+
host: host,
|
|
57
|
+
auth: {
|
|
58
|
+
account: user,
|
|
59
|
+
password: pass
|
|
60
|
+
},
|
|
61
|
+
onReady: function() {
|
|
62
|
+
_this.onReadyCallbacks.forEach(function(done) {
|
|
63
|
+
return done();
|
|
64
|
+
});
|
|
65
|
+
}
|
|
66
|
+
});
|
|
67
|
+
}
|
|
68
|
+
var _proto = VaultService.prototype;
|
|
69
|
+
_proto.get = function get(key) {
|
|
70
|
+
var _this = this;
|
|
71
|
+
return _asyncToGenerator(regeneratorRuntime.mark(function _callee() {
|
|
72
|
+
return regeneratorRuntime.wrap(function _callee$(_ctx) {
|
|
73
|
+
while(1)switch(_ctx.prev = _ctx.next){
|
|
74
|
+
case 0:
|
|
75
|
+
if (!(_this.manager.state === VaultSecretState.READY)) {
|
|
76
|
+
_ctx.next = 2;
|
|
77
|
+
break;
|
|
78
|
+
}
|
|
79
|
+
return _ctx.abrupt("return", _this.manager.get(key));
|
|
80
|
+
case 2:
|
|
81
|
+
return _ctx.abrupt("return", new Promise(function(resolve) {
|
|
82
|
+
_this.onReadyCallbacks.push(function() {
|
|
83
|
+
resolve(_this.manager.get(key));
|
|
84
|
+
});
|
|
85
|
+
}));
|
|
86
|
+
case 3:
|
|
87
|
+
case "end":
|
|
88
|
+
return _ctx.stop();
|
|
89
|
+
}
|
|
90
|
+
}, _callee);
|
|
91
|
+
}))();
|
|
92
|
+
};
|
|
93
|
+
return VaultService;
|
|
94
|
+
}();
|
|
95
|
+
VaultService = __decorate([
|
|
96
|
+
Injectable()
|
|
97
|
+
], VaultService);
|
|
98
|
+
|
|
99
|
+
export { VaultService };
|