k2hr3-api 1.0.41 → 2.0.0
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/config/k2hr3-init.sh.templ +2 -2
- package/dist/.gitkeep +0 -0
- package/dist/src/app.js +262 -0
- package/{bin → dist/src/bin}/run.sh +1 -1
- package/dist/src/bin/watcher.js +113 -0
- package/dist/src/bin/www.js +217 -0
- package/dist/src/lib/basicipcheck.js +392 -0
- package/dist/src/lib/cacerts.js +106 -0
- package/dist/src/lib/dbglogging.js +190 -0
- package/dist/src/lib/dummyuserapi.js +719 -0
- package/dist/src/lib/ipwatch.js +354 -0
- package/dist/src/lib/k2hr3acrutil.js +532 -0
- package/dist/src/lib/k2hr3apiutil.js +1444 -0
- package/dist/src/lib/k2hr3cliutil.js +183 -0
- package/dist/src/lib/k2hr3config.js +832 -0
- package/dist/src/lib/k2hr3cryptutil.js +258 -0
- package/dist/src/lib/k2hr3dkc.js +12121 -0
- package/dist/src/lib/k2hr3extdata.js +198 -0
- package/dist/src/lib/k2hr3keys.js +207 -0
- package/dist/src/lib/k2hr3resutil.js +111 -0
- package/dist/src/lib/k2hr3template.js +6546 -0
- package/dist/src/lib/k2hr3tokens.js +2643 -0
- package/dist/src/lib/k2hr3userdata.js +296 -0
- package/dist/src/lib/k8soidc.js +1000 -0
- package/dist/src/lib/openstackapiv2.js +695 -0
- package/dist/src/lib/openstackapiv3.js +932 -0
- package/dist/src/lib/openstackep.js +667 -0
- package/{tests/auto_common.js → dist/src/lib/types.js} +4 -38
- package/dist/src/routes/acr.js +704 -0
- package/dist/src/routes/debugVerify.js +294 -0
- package/dist/src/routes/extdata.js +219 -0
- package/dist/src/routes/list.js +264 -0
- package/dist/src/routes/policy.js +840 -0
- package/dist/src/routes/resource.js +1489 -0
- package/dist/src/routes/role.js +2627 -0
- package/dist/src/routes/service.js +908 -0
- package/dist/src/routes/tenant.js +1141 -0
- package/dist/src/routes/userTokens.js +482 -0
- package/dist/src/routes/userdata.js +212 -0
- package/dist/src/routes/version.js +103 -0
- package/package.json +152 -121
- package/ChangeLog +0 -372
- package/app.js +0 -292
- package/bin/watcher +0 -122
- package/bin/www +0 -180
- package/eslint.config.mjs +0 -68
- package/lib/basicipcheck.js +0 -376
- package/lib/cacerts.js +0 -71
- package/lib/dbglogging.js +0 -151
- package/lib/dummyuserapi.js +0 -766
- package/lib/ipwatch.js +0 -379
- package/lib/k2hr3acrutil.js +0 -516
- package/lib/k2hr3apiutil.js +0 -1494
- package/lib/k2hr3cliutil.js +0 -191
- package/lib/k2hr3config.js +0 -826
- package/lib/k2hr3cryptutil.js +0 -254
- package/lib/k2hr3dkc.js +0 -12632
- package/lib/k2hr3extdata.js +0 -198
- package/lib/k2hr3keys.js +0 -234
- package/lib/k2hr3resutil.js +0 -100
- package/lib/k2hr3template.js +0 -6925
- package/lib/k2hr3tokens.js +0 -2799
- package/lib/k2hr3userdata.js +0 -312
- package/lib/k8soidc.js +0 -1012
- package/lib/openstackapiv2.js +0 -764
- package/lib/openstackapiv3.js +0 -1032
- package/lib/openstackep.js +0 -553
- package/routes/acr.js +0 -738
- package/routes/debugVerify.js +0 -263
- package/routes/extdata.js +0 -232
- package/routes/list.js +0 -270
- package/routes/policy.js +0 -869
- package/routes/resource.js +0 -1441
- package/routes/role.js +0 -2664
- package/routes/service.js +0 -894
- package/routes/tenant.js +0 -1095
- package/routes/userTokens.js +0 -511
- package/routes/userdata.js +0 -218
- package/routes/version.js +0 -108
- package/templ/Dockerfile.templ +0 -71
- package/tests/auto_acr.js +0 -1101
- package/tests/auto_acr_spec.js +0 -79
- package/tests/auto_all_spec.js +0 -142
- package/tests/auto_control_subprocess.sh +0 -243
- package/tests/auto_extdata.js +0 -220
- package/tests/auto_extdata_spec.js +0 -79
- package/tests/auto_init_config_json.sh +0 -275
- package/tests/auto_k2hdkc_server.ini +0 -109
- package/tests/auto_k2hdkc_slave.ini +0 -83
- package/tests/auto_list.js +0 -439
- package/tests/auto_list_spec.js +0 -79
- package/tests/auto_policy.js +0 -1579
- package/tests/auto_policy_spec.js +0 -79
- package/tests/auto_resource.js +0 -10956
- package/tests/auto_resource_spec.js +0 -79
- package/tests/auto_role.js +0 -6150
- package/tests/auto_role_spec.js +0 -79
- package/tests/auto_service.js +0 -770
- package/tests/auto_service_spec.js +0 -79
- package/tests/auto_subprocesses.js +0 -114
- package/tests/auto_template.sh +0 -126
- package/tests/auto_tenant.js +0 -1100
- package/tests/auto_tenant_spec.js +0 -79
- package/tests/auto_token_util.js +0 -219
- package/tests/auto_userdata.js +0 -292
- package/tests/auto_userdata_spec.js +0 -79
- package/tests/auto_usertokens.js +0 -565
- package/tests/auto_usertokens_spec.js +0 -79
- package/tests/auto_version.js +0 -127
- package/tests/auto_version_spec.js +0 -79
- package/tests/auto_watcher.js +0 -157
- package/tests/auto_watcher_spec.js +0 -79
- package/tests/k2hdkc_test.data +0 -986
- package/tests/k2hdkc_test_load.sh +0 -255
- package/tests/k2hr3template_test.js +0 -187
- package/tests/k2hr3template_test.sh +0 -339
- package/tests/k2hr3template_test_async.js +0 -216
- package/tests/k2hr3template_test_template.result +0 -7117
- package/tests/k2hr3template_test_template.txt +0 -3608
- package/tests/k2hr3template_test_vars.js +0 -194
- package/tests/manual_acr_delete.js +0 -143
- package/tests/manual_acr_get.js +0 -297
- package/tests/manual_acr_postput.js +0 -215
- package/tests/manual_allusertenant_get.js +0 -113
- package/tests/manual_extdata_get.js +0 -191
- package/tests/manual_k2hr3keys_get.js +0 -84
- package/tests/manual_list_gethead.js +0 -230
- package/tests/manual_policy_delete.js +0 -132
- package/tests/manual_policy_gethead.js +0 -275
- package/tests/manual_policy_postput.js +0 -297
- package/tests/manual_resource_delete.js +0 -433
- package/tests/manual_resource_gethead.js +0 -423
- package/tests/manual_resource_postput.js +0 -487
- package/tests/manual_role_delete.js +0 -404
- package/tests/manual_role_gethead.js +0 -547
- package/tests/manual_role_postput.js +0 -544
- package/tests/manual_service_delete.js +0 -153
- package/tests/manual_service_gethead.js +0 -178
- package/tests/manual_service_postput.js +0 -348
- package/tests/manual_tenant_delete.js +0 -186
- package/tests/manual_tenant_gethead.js +0 -268
- package/tests/manual_tenant_postput.js +0 -293
- package/tests/manual_test.sh +0 -352
- package/tests/manual_userdata_get.js +0 -173
- package/tests/manual_usertoken_gethead.js +0 -136
- package/tests/manual_usertoken_postput.js +0 -310
- package/tests/manual_version_get.js +0 -127
- package/tests/run_local_test_k2hdkc.sh +0 -174
- package/tests/test.sh +0 -333
|
@@ -0,0 +1,296 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/*
|
|
3
|
+
* K2HR3 REST API
|
|
4
|
+
*
|
|
5
|
+
* Copyright 2018 Yahoo Japan Corporation.
|
|
6
|
+
*
|
|
7
|
+
* K2HR3 is K2hdkc based Resource and Roles and policy Rules, gathers
|
|
8
|
+
* common management information for the cloud.
|
|
9
|
+
* K2HR3 can dynamically manage information as "who", "what", "operate".
|
|
10
|
+
* These are stored as roles, resources, policies in K2hdkc, and the
|
|
11
|
+
* client system can dynamically read and modify these information.
|
|
12
|
+
*
|
|
13
|
+
* For the full copyright and license information, please view
|
|
14
|
+
* the license file that was distributed with this source code.
|
|
15
|
+
*
|
|
16
|
+
* AUTHOR: Takeshi Nakatani
|
|
17
|
+
* CREATE: Tue Oct 2 2018
|
|
18
|
+
* REVISION:
|
|
19
|
+
*
|
|
20
|
+
*/
|
|
21
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
22
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
23
|
+
};
|
|
24
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
25
|
+
exports.userdataProcess = void 0;
|
|
26
|
+
const k2hr3apiutil_1 = __importDefault(require("./k2hr3apiutil"));
|
|
27
|
+
const k2hr3cryptutil_1 = __importDefault(require("./k2hr3cryptutil"));
|
|
28
|
+
const dbglogging_1 = __importDefault(require("./dbglogging"));
|
|
29
|
+
const k2hr3keys_1 = require("./k2hr3keys");
|
|
30
|
+
const k2hr3config_1 = require("./k2hr3config");
|
|
31
|
+
const apiConf = new k2hr3config_1.r3ApiConfig();
|
|
32
|
+
//---------------------------------------------------------
|
|
33
|
+
// Empty script for error
|
|
34
|
+
//---------------------------------------------------------
|
|
35
|
+
const EmptyScriptContents = [
|
|
36
|
+
'#!/bin/sh',
|
|
37
|
+
'#',
|
|
38
|
+
'# K2HR3 Frontend Web Application',
|
|
39
|
+
'#',
|
|
40
|
+
'# Copyright(C) 2018 Yahoo Japan Corporation.',
|
|
41
|
+
'#',
|
|
42
|
+
'# K2HR3 is K2hdkc based Resource and Roles and policy Rules, gathers',
|
|
43
|
+
'# common management information for the cloud.',
|
|
44
|
+
'# K2HR3 can dynamically manage information as "who", "what", "operate".',
|
|
45
|
+
'# These are stored as roles, resources, policies in K2hdkc, and the',
|
|
46
|
+
'# client system can dynamically read and modify these information.',
|
|
47
|
+
'#',
|
|
48
|
+
'# For the full copyright and license information, please view',
|
|
49
|
+
'# the license file that was distributed with this source code.',
|
|
50
|
+
'#',
|
|
51
|
+
'# AUTHOR: Takeshi Nakatani',
|
|
52
|
+
'# CREATE: Tue Oct 2 2018',
|
|
53
|
+
'# REVISION:',
|
|
54
|
+
'#',
|
|
55
|
+
'',
|
|
56
|
+
'SCRIPTNAME="k2hr3-init"',
|
|
57
|
+
'LOGFILE="/var/log/${SCRIPTNAME}.log"',
|
|
58
|
+
'',
|
|
59
|
+
'echo "`date "+%Y-%m-%d %H:%M:%S,%3N"` - ${SCRIPTNAME}[ERROR]: Invalid userdata for creating k2hr3-init script was specified(detail error = {{= %K2HR3_ERROR_MSG% }})" | tee -a ${LOGFILE}',
|
|
60
|
+
'exit 1',
|
|
61
|
+
'',
|
|
62
|
+
'#',
|
|
63
|
+
'# VIM modelines',
|
|
64
|
+
'#',
|
|
65
|
+
'# vim:set ts=4 fenc=utf-8:',
|
|
66
|
+
'#'
|
|
67
|
+
].join('\n');
|
|
68
|
+
//---------------------------------------------------------
|
|
69
|
+
// load userdata templates from config directory
|
|
70
|
+
//---------------------------------------------------------
|
|
71
|
+
const LoadedUserdataTemplates = (() => {
|
|
72
|
+
const templates = {
|
|
73
|
+
cloud_config: null,
|
|
74
|
+
init_script: null,
|
|
75
|
+
init_err_script: null,
|
|
76
|
+
kw_role_name: /{{= %K2HR3_ROLE_NAME% }}/g, // Role YRN full path
|
|
77
|
+
kw_role_tenant: /{{= %K2HR3_ROLE_TENANT% }}/g, // Tenant YRN full path
|
|
78
|
+
kw_role_token: /{{= %K2HR3_ROLE_TOKEN% }}/g, // Role Token
|
|
79
|
+
kw_api_uri: /{{= %K2HR3_API_HOST_URI% }}/g, // K2HR3 API server URI(ex. https://localhost:3000)
|
|
80
|
+
kw_err_msg: /{{= %K2HR3_ERROR_MSG% }}/g, // Error message string when something error occured
|
|
81
|
+
default_script: EmptyScriptContents,
|
|
82
|
+
};
|
|
83
|
+
const userdatacfgobj = apiConf.getUserdataConfig();
|
|
84
|
+
if (k2hr3apiutil_1.default.isSafeEntity(userdatacfgobj)) {
|
|
85
|
+
templates.baseuri = k2hr3apiutil_1.default.getSafeString(userdatacfgobj.baseuri);
|
|
86
|
+
templates.algorithm = k2hr3apiutil_1.default.getSafeString(userdatacfgobj.algorithm);
|
|
87
|
+
templates.passphrase = k2hr3apiutil_1.default.getSafeString(userdatacfgobj.passphrase);
|
|
88
|
+
templates.cloud_config = k2hr3apiutil_1.default.readFileContents(userdatacfgobj.cc_templ);
|
|
89
|
+
templates.init_script = k2hr3apiutil_1.default.readFileContents(userdatacfgobj.script_templ);
|
|
90
|
+
templates.init_err_script = k2hr3apiutil_1.default.readFileContents(userdatacfgobj.errscript_templ);
|
|
91
|
+
}
|
|
92
|
+
else {
|
|
93
|
+
templates.baseuri = '';
|
|
94
|
+
templates.algorithm = '';
|
|
95
|
+
templates.passphrase = '';
|
|
96
|
+
templates.cloud_config = null;
|
|
97
|
+
templates.init_script = null;
|
|
98
|
+
templates.init_err_script = null;
|
|
99
|
+
}
|
|
100
|
+
return templates;
|
|
101
|
+
})();
|
|
102
|
+
//---------------------------------------------------------
|
|
103
|
+
// Userdata Processing Class
|
|
104
|
+
//---------------------------------------------------------
|
|
105
|
+
class UserdataProcess {
|
|
106
|
+
_userdataTemplates;
|
|
107
|
+
//
|
|
108
|
+
// Constructor
|
|
109
|
+
//
|
|
110
|
+
constructor() {
|
|
111
|
+
this._userdataTemplates = LoadedUserdataTemplates;
|
|
112
|
+
}
|
|
113
|
+
;
|
|
114
|
+
//
|
|
115
|
+
// Methods
|
|
116
|
+
//
|
|
117
|
+
encryptRoleInfo = (obj) => {
|
|
118
|
+
if (!k2hr3apiutil_1.default.isSafeEntity(obj)) {
|
|
119
|
+
dbglogging_1.default.elog('role information object parameter is empty.');
|
|
120
|
+
return null;
|
|
121
|
+
}
|
|
122
|
+
return k2hr3cryptutil_1.default.r3EncryptJSON(obj, (k2hr3apiutil_1.default.isSafeString(this._userdataTemplates.passphrase) ? this._userdataTemplates.passphrase : null), (k2hr3apiutil_1.default.isSafeString(this._userdataTemplates.algorithm) ? this._userdataTemplates.algorithm : null));
|
|
123
|
+
};
|
|
124
|
+
decryptRoleInfo = (str) => {
|
|
125
|
+
if (!k2hr3apiutil_1.default.isSafeString(str)) {
|
|
126
|
+
dbglogging_1.default.elog('string parameter is empty.');
|
|
127
|
+
return null;
|
|
128
|
+
}
|
|
129
|
+
const rawData = k2hr3cryptutil_1.default.r3DecryptJSON(str, this._userdataTemplates.passphrase, this._userdataTemplates.algorithm);
|
|
130
|
+
if (!k2hr3apiutil_1.default.isValTypeRoleInfo(rawData)) {
|
|
131
|
+
return null;
|
|
132
|
+
}
|
|
133
|
+
return rawData;
|
|
134
|
+
};
|
|
135
|
+
getMultipartUserdata = (roleobj, errorMsg) => {
|
|
136
|
+
let rolename = '';
|
|
137
|
+
let roletenant = '';
|
|
138
|
+
let roletoken = '';
|
|
139
|
+
if (!k2hr3apiutil_1.default.isSafeString(errorMsg)) {
|
|
140
|
+
errorMsg = null;
|
|
141
|
+
}
|
|
142
|
+
if (!k2hr3apiutil_1.default.isPlainObject(roleobj)) {
|
|
143
|
+
dbglogging_1.default.elog('role object(role name, role token) parameter is empty.');
|
|
144
|
+
if (!errorMsg) {
|
|
145
|
+
errorMsg = 'k2hr3 role information is wrong';
|
|
146
|
+
}
|
|
147
|
+
}
|
|
148
|
+
else if (!k2hr3apiutil_1.default.isSafeString(roleobj.role)) {
|
|
149
|
+
dbglogging_1.default.elog('role name parameter is empty.');
|
|
150
|
+
if (!errorMsg) {
|
|
151
|
+
errorMsg = 'k2hr3 role name is empty';
|
|
152
|
+
}
|
|
153
|
+
}
|
|
154
|
+
else if (!k2hr3apiutil_1.default.isSafeString(roleobj.token)) {
|
|
155
|
+
dbglogging_1.default.elog('role token parameter is empty.');
|
|
156
|
+
if (!errorMsg) {
|
|
157
|
+
errorMsg = 'k2hr3 role token is empty';
|
|
158
|
+
}
|
|
159
|
+
}
|
|
160
|
+
else {
|
|
161
|
+
rolename = k2hr3apiutil_1.default.getSafeString(roleobj.role);
|
|
162
|
+
roletoken = k2hr3apiutil_1.default.getSafeString(roleobj.token);
|
|
163
|
+
// Extract tenant yrn full path from role yrn full path
|
|
164
|
+
const keys = (0, k2hr3keys_1.getK2hr3Keys)();
|
|
165
|
+
const roleptn = new RegExp('^' + keys.MATCH_ANY_TENANT_ROLE); // regex = /^yrn:yahoo:(.*)::(.*):role:(.*)/
|
|
166
|
+
const matches = rolename.match(roleptn);
|
|
167
|
+
if (k2hr3apiutil_1.default.isNotEmptyArray(matches) && 4 <= matches.length && k2hr3apiutil_1.default.isSafeString(matches[2])) {
|
|
168
|
+
roletenant = keys.NO_SERVICE_KEY + k2hr3apiutil_1.default.getSafeString(matches[1]) + '::' + k2hr3apiutil_1.default.getSafeString(matches[2]);
|
|
169
|
+
}
|
|
170
|
+
}
|
|
171
|
+
//-----------------
|
|
172
|
+
// expands templates
|
|
173
|
+
//-----------------
|
|
174
|
+
const config = this._userdataTemplates.cloud_config; // cloud-config does not have keywords, then no-replacing.
|
|
175
|
+
let script = null;
|
|
176
|
+
let errscript = null;
|
|
177
|
+
let defscript = this._userdataTemplates.default_script;
|
|
178
|
+
if (this._userdataTemplates.init_script) {
|
|
179
|
+
script = this._userdataTemplates.init_script.replace(this._userdataTemplates.kw_role_name, rolename);
|
|
180
|
+
script = script.replace(this._userdataTemplates.kw_role_tenant, roletenant);
|
|
181
|
+
script = script.replace(this._userdataTemplates.kw_role_token, roletoken);
|
|
182
|
+
script = script.replace(this._userdataTemplates.kw_api_uri, k2hr3apiutil_1.default.getSafeString(this._userdataTemplates.baseuri));
|
|
183
|
+
if (errorMsg) {
|
|
184
|
+
// [NOTE]
|
|
185
|
+
// Normally, you'll use a script for error, so this process will be wasted.
|
|
186
|
+
// However, there are cases where this keyword is specified in the template,
|
|
187
|
+
// so we will replace it.
|
|
188
|
+
//
|
|
189
|
+
script = script.replace(this._userdataTemplates.kw_err_msg, errorMsg);
|
|
190
|
+
}
|
|
191
|
+
else {
|
|
192
|
+
script = script.replace(this._userdataTemplates.kw_err_msg, '');
|
|
193
|
+
}
|
|
194
|
+
}
|
|
195
|
+
if (this._userdataTemplates.init_err_script) {
|
|
196
|
+
errscript = this._userdataTemplates.init_err_script.replace(this._userdataTemplates.kw_role_name, rolename);
|
|
197
|
+
errscript = errscript.replace(this._userdataTemplates.kw_role_token, roletoken);
|
|
198
|
+
errscript = errscript.replace(this._userdataTemplates.kw_role_tenant, roletenant);
|
|
199
|
+
errscript = errscript.replace(this._userdataTemplates.kw_api_uri, k2hr3apiutil_1.default.getSafeString(this._userdataTemplates.baseuri));
|
|
200
|
+
if (errorMsg) {
|
|
201
|
+
errscript = errscript.replace(this._userdataTemplates.kw_err_msg, errorMsg);
|
|
202
|
+
}
|
|
203
|
+
else {
|
|
204
|
+
errscript = errscript.replace(this._userdataTemplates.kw_err_msg, '');
|
|
205
|
+
}
|
|
206
|
+
}
|
|
207
|
+
if (!config && !script) {
|
|
208
|
+
dbglogging_1.default.wlog('k2hr3-init and error script template is not specified.');
|
|
209
|
+
if (!errorMsg) {
|
|
210
|
+
errorMsg = 'no script is set';
|
|
211
|
+
}
|
|
212
|
+
}
|
|
213
|
+
if (errorMsg) {
|
|
214
|
+
defscript = defscript.replace(this._userdataTemplates.kw_err_msg, errorMsg);
|
|
215
|
+
}
|
|
216
|
+
//-----------------
|
|
217
|
+
// make part type array
|
|
218
|
+
//-----------------
|
|
219
|
+
const parts = []; // member object is {type: 'contents-type string', filename: 'filename', contents: '...'}
|
|
220
|
+
if (errorMsg) {
|
|
221
|
+
if (!errscript) {
|
|
222
|
+
parts.push({ type: 'text/x-shellscript', filename: 'k2hr3-init-empty.sh', contents: defscript });
|
|
223
|
+
}
|
|
224
|
+
else {
|
|
225
|
+
parts.push({ type: 'text/x-shellscript', filename: 'k2hr3-init-error.sh', contents: errscript });
|
|
226
|
+
}
|
|
227
|
+
}
|
|
228
|
+
else if (config && script) {
|
|
229
|
+
parts.push({ type: 'text/cloud-config', filename: 'k2hr3-cloud-config.txt', contents: config });
|
|
230
|
+
parts.push({ type: 'text/x-shellscript', filename: 'k2hr3-init.sh', contents: script });
|
|
231
|
+
}
|
|
232
|
+
else if (config && !script) {
|
|
233
|
+
parts.push({ type: 'text/cloud-config', filename: 'k2hr3-cloud-config.txt', contents: config });
|
|
234
|
+
}
|
|
235
|
+
else if (!config && script) {
|
|
236
|
+
parts.push({ type: 'text/x-shellscript', filename: 'k2hr3-init.sh', contents: script });
|
|
237
|
+
}
|
|
238
|
+
else { // !config && !script
|
|
239
|
+
parts.push({ type: 'text/x-shellscript', filename: 'k2hr3-init-empty.sh', contents: defscript });
|
|
240
|
+
}
|
|
241
|
+
//-----------------
|
|
242
|
+
// make multipart
|
|
243
|
+
//-----------------
|
|
244
|
+
const boundary = '================K2HR3INIT' + Date.now().toString() + '==';
|
|
245
|
+
const result = {
|
|
246
|
+
body: '',
|
|
247
|
+
type: 'multipart/mixed; boundary="' + boundary + '"',
|
|
248
|
+
mimeverkey: 'MIME-Version',
|
|
249
|
+
mimeverval: '1.0',
|
|
250
|
+
partcntkey: 'Number-Attachments',
|
|
251
|
+
partcntval: parts.length
|
|
252
|
+
};
|
|
253
|
+
// fill parts
|
|
254
|
+
for (let cnt = 0; cnt < parts.length; ++cnt) {
|
|
255
|
+
// part header
|
|
256
|
+
result.body += '--' + boundary + '\r\n';
|
|
257
|
+
result.body += 'MIME-Version: 1.0\r\n';
|
|
258
|
+
result.body += 'Content-Type: ' + parts[cnt].type + '; charset="us-ascii"\r\n';
|
|
259
|
+
result.body += 'Content-Transfer-Encoding: 7bit\r\n';
|
|
260
|
+
result.body += 'Content-Disposition: attachment; filename="' + parts[cnt].filename + '"\r\n\r\n';
|
|
261
|
+
// part contents
|
|
262
|
+
result.body += parts[cnt].contents;
|
|
263
|
+
result.body += '\r\n';
|
|
264
|
+
}
|
|
265
|
+
// make footer
|
|
266
|
+
result.body += '--' + boundary + '--\r\n';
|
|
267
|
+
return result;
|
|
268
|
+
};
|
|
269
|
+
getGzipMultipartUserdata = (roleobj, errorMsg, callback) => {
|
|
270
|
+
// get multipart headers and body
|
|
271
|
+
const multipartobj = this.getMultipartUserdata(roleobj, errorMsg);
|
|
272
|
+
// make one string
|
|
273
|
+
let multipart = '';
|
|
274
|
+
multipart += 'Content-Type: ' + multipartobj.type + '\r\n';
|
|
275
|
+
multipart += multipartobj.mimeverkey + ': ' + multipartobj.mimeverval + '\r\n';
|
|
276
|
+
multipart += multipartobj.partcntkey + ': ' + multipartobj.partcntval + '\r\n\r\n';
|
|
277
|
+
multipart += multipartobj.body;
|
|
278
|
+
return k2hr3cryptutil_1.default.r3Gzip(multipart, callback);
|
|
279
|
+
};
|
|
280
|
+
}
|
|
281
|
+
//---------------------------------------------------------
|
|
282
|
+
// Exports
|
|
283
|
+
//---------------------------------------------------------
|
|
284
|
+
//
|
|
285
|
+
// Class
|
|
286
|
+
//
|
|
287
|
+
exports.userdataProcess = UserdataProcess;
|
|
288
|
+
exports.default = exports.userdataProcess;
|
|
289
|
+
/*
|
|
290
|
+
* Local variables:
|
|
291
|
+
* tab-width: 4
|
|
292
|
+
* c-basic-offset: 4
|
|
293
|
+
* End:
|
|
294
|
+
* vim600: noexpandtab sw=4 ts=4 fdm=marker
|
|
295
|
+
* vim<600: noexpandtab sw=4 ts=4
|
|
296
|
+
*/
|