s3: integrated with store and reducers

This commit is contained in:
Logan Allen 2020-04-23 19:49:14 -04:00
parent bec650957c
commit 285f0bd5e3
3 changed files with 94 additions and 9 deletions

View File

@ -23,27 +23,27 @@
%+ frond:enjs %s3-update
%- pairs:enjs
:~ ?- -.upd
%set-current-bucket [%set-current-bucket s+bucket.upd]
%add-bucket [%add-bucket s+bucket.upd]
%remove-bucket [%remove-bucket s+bucket.upd]
%set-endpoint [%set-endpoint s+endpoint.upd]
%set-access-key-id [%set-access-key-id s+access-key-id.upd]
%set-current-bucket [%'setCurrentBucket' s+bucket.upd]
%add-bucket [%'addBucket' s+bucket.upd]
%remove-bucket [%'removeBucket' s+bucket.upd]
%set-endpoint [%'setEndpoint' s+endpoint.upd]
%set-access-key-id [%'setAccessKeyId' s+access-key-id.upd]
%set-secret-access-key
[%set-secret-access-key s+secret-access-key.upd]
[%'setSecretAccessKey' s+secret-access-key.upd]
::
%credentials
:- %credentials
%- pairs:enjs
:~ [%endpoint s+endpoint.credentials.upd]
[%access-key-id s+access-key-id.credentials.upd]
[%secret-access-key s+secret-access-key.credentials.upd]
[%'accessKeyId' s+access-key-id.credentials.upd]
[%'secretAccessKey' s+secret-access-key.credentials.upd]
==
::
%configuration
:- %configuration
%- pairs:enjs
:~ [%buckets a+(turn ~(tap in buckets.configuration.upd) |=(a=@t s+a))]
[%current-bucket s+current-bucket.configuration.upd]
[%'currentBucket' s+current-bucket.configuration.upd]
==
==
==

View File

@ -0,0 +1,81 @@
import _ from 'lodash';
export class S3Reducer {
reduce(json, state) {
let data = _.get(json, 's3-update', false);
if (data) {
this.credentials(data, state);
this.configuration(data, state);
this.currentBucket(data, state);
this.addBucket(data, state);
this.removeBucket(data, state);
this.endpoint(data, state);
this.accessKeyId(data, state);
this.secretAccessKey(data, state);
}
}
credentials(json, state) {
let data = _.get(json, 'credentials', false);
if (data) {
state.s3.credentials = data;
}
}
configuration(json, state) {
let data = _.get(json, 'configuration', false);
if (data) {
state.s3.configuration = {
buckets: new Set(data.buckets),
currentBucket: data.currentBucket
};
}
}
currentBucket(json, state) {
let data = _.get(json, 'setCurrentBucket', false);
if (data) {
state.s3.configuration.currentBucket = data;
}
}
addBucket(json, state) {
let data = _.get(json, 'addBucket', false);
if (data) {
state.s3.configuration.buckets =
state.s3.configuration.buckets.add(data);
}
}
removeBucket(json, state) {
let data = _.get(json, 'removeBucket', false);
if (data) {
state.s3.configuration.buckets =
state.s3.configuration.buckets.delete(data);
}
}
endpoint(json, state) {
let data = _.get(json, 'setEndpoint', false);
if (data) {
state.s3.credentials.endpoint = data;
}
}
accessKeyId(json, state) {
let data = _.get(json, 'setAccessKeyId', false);
if (data) {
state.s3.credentials.accessKeyId = data;
}
}
secretAccessKey(json, state) {
let data = _.get(json, 'setSecretAccessKey', false);
if (data) {
state.s3.credentials.secretAccessKey = data;
}
}
}

View File

@ -4,6 +4,7 @@ import { GroupUpdateReducer } from '/reducers/group-update';
import { InviteUpdateReducer } from '/reducers/invite-update';
import { PermissionUpdateReducer } from '/reducers/permission-update';
import { MetadataReducer } from '/reducers/metadata-update.js';
import { S3Reducer } from '/reducers/s3.js';
import { LocalReducer } from '/reducers/local.js';
@ -17,6 +18,7 @@ class Store {
this.contactUpdateReducer = new ContactUpdateReducer();
this.inviteUpdateReducer = new InviteUpdateReducer();
this.metadataReducer = new MetadataReducer();
this.s3Reducer = new S3Reducer();
this.localReducer = new LocalReducer();
this.setState = () => {};
}
@ -28,6 +30,7 @@ class Store {
associations: {},
permissions: {},
invites: {},
s3: {},
selectedGroups: []
};
}
@ -51,6 +54,7 @@ class Store {
this.contactUpdateReducer.reduce(json, this.state);
this.inviteUpdateReducer.reduce(json, this.state);
this.metadataReducer.reduce(json, this.state);
this.s3Reducer.reduce(json, this.state);
this.localReducer.reduce(json, this.state);
this.setState(this.state);