s3-store: poke functionality, updated credentials, added generators

This commit is contained in:
Logan Allen 2020-04-23 17:30:59 -04:00
parent daf32fd0f9
commit ab3a759ce2
8 changed files with 125 additions and 7 deletions

View File

@ -42,7 +42,17 @@
++ poke-action
|= act=action
^- (quip card _state)
[~ state]
:- [%give %fact [/all]~ %s3-update !>(act)]~
?- -.act
%set-endpoint
state(endpoint.credentials endpoint.act)
::
%set-access-key-id
state(access-key-id.credentials access-key-id.act)
::
%set-secret-access-key
state(secret-access-key.credentials secret-access-key.act)
==
--
::
++ on-watch

View File

@ -0,0 +1,10 @@
:: s3-store|set-access-key-id: set S3 access key ID
::
/- *s3
:- %say
|= $: [now=@da eny=@uvJ =beak]
[[access-key-id=@t ~] ~]
==
:- %s3-action
^- action
[%set-access-key-id access-key-id]

View File

@ -0,0 +1,10 @@
:: s3-store|set-api-key: set S3 bucket api-key
::
/- *s3
:- %say
|= $: [now=@da eny=@uvJ =beak]
[[api-key=@t ~] ~]
==
:- %s3-action
^- action
[%set-api-key api-key]

View File

@ -0,0 +1,10 @@
:: s3-store|set-endpoint: set S3 endpoint
::
/- *s3
:- %say
|= $: [now=@da eny=@uvJ =beak]
[[endpoint=@t ~] ~]
==
:- %s3-action
^- action
[%set-endpoint endpoint]

View File

@ -0,0 +1,10 @@
:: s3-store|set-secret-access-key: set S3 secret access key
::
/- *s3
:- %say
|= $: [now=@da eny=@uvJ =beak]
[[secret-access-key=@t ~] ~]
==
:- %s3-action
^- action
[%set-secret-access-key secret-access-key]

View File

@ -4,7 +4,12 @@
|= =json
^- action
|^ (parse-json json)
++ parse-json (of:dejs:format [%set-api-key so:dejs:format]~)
++ parse-json
%- of:dejs:format
:~ [%set-endoint so:dejs:format]
[%set-access-key-id so:dejs:format]
[%set-secret-access-key so:dejs:format]
==
--
::
++ update-to-json
@ -13,10 +18,18 @@
%+ frond:enjs:format %s3-update
%- pairs:enjs:format
:~ ?- -.upd
%set-endpoint [%set-endpoint s+endpoint.upd]
%set-access-key-id [%set-access-key-id s+access-key-id.upd]
%set-secret-access-key
[%set-secret-access-key s+secret-access-key.upd]
::
%credentials
[%credentials (pairs:enjs:format [%api-key s+api-key.credentials.upd]~)]
%set-api-key
[%set-api-key (pairs:enjs:format [%api-key s+api-key.upd]~)]
:- %credentials
%- pairs:enjs:format
:~ [%endpoint s+endpoint.credentials.upd]
[%access-key-id s+access-key-id.credentials.upd]
[%secret-access-key s+secret-access-key.credentials.upd]
==
==
==
--

View File

@ -1,10 +1,14 @@
|%
+$ credentials
$: api-key=@t
$: endpoint=@t
access-key-id=@t
secret-access-key=@t
==
::
+$ action
$% [%set-api-key api-key=@t]
$% [%set-endpoint endpoint=@t]
[%set-access-key-id access-key-id=@t]
[%set-secret-access-key secret-access-key=@t]
==
::
+$ update

View File

@ -0,0 +1,51 @@
const AWS = require('aws-sdk')
export function configureClient() {
// Configure client for use with Spaces
const spacesEndpoint = new AWS.Endpoint('nyc3.digitaloceanspaces.com');
return new AWS.S3({
endpoint: spacesEndpoint,
credentials: new AWS.Credentials({
accessKeyId: 'ACCESS_KEY',
secretAccessKey: 'SECRET_KEY'
})
});
}
export function createBucket() {
// Create a new Space
var params = {
Bucket: "my-new-space-with-a-unique-name"
};
s3.createBucket(params, function(err, data) {
if (err) console.log(err, err.stack);
else console.log(data);
});
}
export function listBuckets() {
// List all Spaces in the region
s3.listBuckets({}, function(err, data) {
if (err) console.log(err, err.stack);
else {
data['Buckets'].forEach(function(space) {
console.log(space['Name']);
})};
});
}
export function putObject(body, bucket, key) {
// Add a file to a Space
var params = {
Body: "The contents of the file",
Bucket: "my-new-space-with-a-unique-name",
Key: "file.ext",
};
s3.putObject(params, function(err, data) {
if (err) console.log(err, err.stack);
else console.log(data);
});
}