Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Sign in
Toggle navigation
N
node-bigstream
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
3
Merge Requests
3
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
bs
node-bigstream
Commits
906d93f7
Commit
906d93f7
authored
May 22, 2020
by
Kamron Aroonrua
💬
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
dt pgpcrypt
parent
fd830903
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
195 additions
and
0 deletions
+195
-0
index.js
plugins/dt/dt-pgpcrypt/index.js
+13
-0
package.json
plugins/dt/dt-pgpcrypt/package.json
+14
-0
perform.js
plugins/dt/dt-pgpcrypt/perform.js
+119
-0
pgp.js
plugins/dt/dt-pgpcrypt/pgp.js
+49
-0
No files found.
plugins/dt/dt-pgpcrypt/index.js
0 → 100644
View file @
906d93f7
var
util
=
require
(
'util'
);
var
DTPlugin
=
require
(
'../dt-plugin'
);
function
DTTask
(
context
,
request
){
DTPlugin
.
call
(
this
,
context
,
request
);
this
.
name
=
"pgpcrypt"
;
this
.
output_type
=
""
;
}
util
.
inherits
(
DTTask
,
DTPlugin
);
DTTask
.
prototype
.
perform
=
require
(
'./perform'
);
module
.
exports
=
DTTask
;
\ No newline at end of file
plugins/dt/dt-pgpcrypt/package.json
0 → 100644
View file @
906d93f7
{
"name"
:
"dt-pgpcrypt"
,
"version"
:
"1.0.0"
,
"description"
:
""
,
"main"
:
"index.js"
,
"scripts"
:
{
"test"
:
"echo
\"
Error: no test specified
\"
&& exit 1"
},
"author"
:
""
,
"license"
:
"ISC"
,
"dependencies"
:
{
"openpgp"
:
"^4.10.4"
}
}
plugins/dt/dt-pgpcrypt/perform.js
0 → 100644
View file @
906d93f7
var
ctx
=
require
(
'../../../context'
);
var
Utils
=
ctx
.
getLib
(
'lib/util/plugin-utils'
);
var
request
=
require
(
"request"
).
defaults
({
encoding
:
null
});
function
perform_function
(
context
,
request
,
response
){
var
job_id
=
context
.
jobconfig
.
job_id
;
var
transaction_id
=
context
.
transaction
.
id
;
var
param
=
context
.
task
.
config
.
param
||
{};
var
memstore
=
context
.
task
.
memstore
var
output_type
=
request
.
input_type
;
var
data
=
request
.
data
;
var
meta
=
request
.
meta
||
{};
var
req_url
=
param
.
url
||
""
;
var
req_method
=
param
.
method
||
"GET"
;
var
req_headers
=
param
.
headers
||
{};
var
req_body_type
=
param
.
body_type
||
"json"
;
var
resp_encode
=
param
.
encoding
||
"text"
;
var
env
=
{
'type'
:
output_type
,
'data'
:
data
,
'meta'
:
meta
}
req_url
=
Utils
.
vm_execute_text
(
env
,
req_url
);
//parsing param from meta
if
(
typeof
meta
.
_param
==
'object'
)
{
var
_prm
=
meta
.
_param
;
req_url
=
(
_prm
.
url
)?
_prm
.
url
:
req_url
;
req_method
=
(
_prm
.
method
)?
_prm
.
method
:
req_method
;
req_headers
=
(
_prm
.
headers
)?
_prm
.
headers
:
req_headers
;
req_body_type
=
(
_prm
.
body_type
)?
_prm
.
body_type
:
req_body_type
;
resp_encode
=
(
_prm
.
encoding
)?
_prm
.
encoding
:
resp_encode
;
}
send_request
({
'url'
:
req_url
,
'method'
:
req_method
,
'headers'
:
req_headers
,
'body_type'
:
req_body_type
,
'body'
:
data
,
'resp_encode'
:
resp_encode
},
function
(
err
,
resp
,
body
){
var
respmeta
=
meta
;
Object
.
keys
(
respmeta
).
forEach
((
k
)
=>
{
if
(
k
.
startsWith
(
'_'
)){
delete
respmeta
[
k
];}
});
respmeta
[
'_status_code'
]
=
(
err
)?
0
:
resp
.
statusCode
;
respmeta
[
'_error'
]
=
(
err
)?
true
:
false
;
response
.
meta
=
respmeta
;
if
(
!
err
){
if
(
resp_encode
==
'json'
){
try
{
var
j
=
JSON
.
parse
(
body
);
response
.
success
(
j
,
output_type
);
}
catch
(
err
){
response
.
success
({},
output_type
);
}
}
else
{
response
.
success
(
body
,
output_type
);
}
}
else
{
response
.
success
(
null
,
output_type
);
}
});
//response.success();
//response.reject();
//response.error("error message")
}
function
send_request
(
prm
,
cb
)
{
var
options
=
{
method
:
'GET'
,
url
:
prm
.
url
,
headers
:
{
'cache-control'
:
'no-cache'
}
};
if
(
prm
.
method
.
toLowerCase
()
==
'post'
||
prm
.
method
.
toLowerCase
()
==
'put'
)
{
options
.
method
=
prm
.
method
.
toUpperCase
();
if
(
prm
.
body_type
==
'json'
&&
typeof
prm
.
body
==
'object'
){
options
.
headers
[
'content-type'
]
=
'application/json'
;
options
.
json
=
prm
.
body
;
}
else
if
(
prm
.
body_type
==
'text'
||
typeof
prm
.
body
==
'string'
){
options
.
headers
[
'content-type'
]
=
'text/plain'
;
options
.
body
=
prm
.
body
;
}
else
{
options
.
body
=
prm
.
body
;
}
}
if
(
typeof
prm
.
headers
==
'object'
)
{
options
.
headers
=
Object
.
assign
(
options
.
headers
,
prm
.
headers
)
}
options
.
encoding
=
(
prm
.
resp_encode
==
'binary'
)?
null
:
'utf8'
;
request
(
options
,
function
(
err
,
resp
,
body
)
{
if
(
!
err
)
{
cb
(
err
,
resp
,
body
);
}
else
{
cb
(
new
Error
(
"request error"
));
}
});
}
module
.
exports
=
perform_function
;
plugins/dt/dt-pgpcrypt/pgp.js
0 → 100644
View file @
906d93f7
const
openpgp
=
require
(
'openpgp'
);
async
function
encrypt
(
opt
)
{
var
publicKeyArmored
=
opt
.
public_key
;
var
datain
=
opt
.
data
;
var
armor
=
(
opt
.
armor_out
)?
true
:
false
;
var
enc
=
await
openpgp
.
encrypt
({
message
:
openpgp
.
message
.
fromBinary
(
datain
),
publicKeys
:
(
await
openpgp
.
key
.
readArmored
(
publicKeyArmored
)).
keys
,
armor
:
armor
});
if
(
!
armor
){
enc
=
Buffer
.
from
(
enc
.
message
.
packets
.
write
());
}
return
enc
;
}
async
function
decrypt
(
opt
)
{
var
privateKeyArmored
=
opt
.
private_key
;
var
passphrase
=
opt
.
passphrase
;
var
datain
=
opt
.
data
;
var
armor
=
(
opt
.
armor_in
)?
true
:
false
;
var
{
keys
:
[
privateKey
]
}
=
await
openpgp
.
key
.
readArmored
(
privateKeyArmored
);
await
privateKey
.
decrypt
(
passphrase
);
var
msg
=
null
;
if
(
armor
){
msg
=
await
openpgp
.
message
.
readArmored
(
datain
);
}
else
{
msg
=
await
openpgp
.
message
.
read
(
datain
);
}
const
{
data
:
decrypted
}
=
await
openpgp
.
decrypt
({
message
:
msg
,
privateKeys
:
[
privateKey
],
format
:
'binary'
});
return
Buffer
.
from
(
decrypted
);
}
module
.
exports
.
encrypt
=
encrypt
;
module
.
exports
.
decrypt
=
decrypt
;
\ No newline at end of file
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment