Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature/ch21518/filecoin #45

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions packages/models/src/identity/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,8 @@ export class IdentityModel extends BaseModel {

const result = await this.query(params);

console.log('getIdentitiesByDisplayName: ', result);
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added these logs to troubleshoot another issue. Will clean up once that is fixed.


return result.Items.map(parseDbObjectToIdentity);
}

Expand Down Expand Up @@ -376,6 +378,8 @@ export class IdentityModel extends BaseModel {
const results = await Promise.all(ps);
const dpResults = await Promise.all(dpp);

console.log('dpResults: ', dpResults);

if (dpResults.length > 0) {
dpResults.forEach(a => {
results.concat(a);
Expand Down
6 changes: 5 additions & 1 deletion services/rest/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,12 @@
"@packages/apitools": "^0.0.1",
"@packages/crypto": "^0.0.1",
"@packages/models": "^0.0.1",
"aws-appsync": "^4.0.3",
"aws-lambda": "^1.0.6",
"aws-sdk": "^2.829.0",
"aws-sdk": "^2.852.0",
"cids": "^1.1.5",
"cross-fetch": "^3.0.6",
"graphql-tag": "^2.11.0",
"ipfs-http-client": "^46.0.1",
"jsonwebtoken": "^8.5.1",
"shelljs": "^0.8.4",
Expand Down
57 changes: 54 additions & 3 deletions services/rest/serverless.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,29 @@ provider:
- SES:SendEmail
- SES:SendRawEmail
Resource: '*'
- Effect: Allow
Action:
- "appsync:Graphql"
Resource:
- "arn:aws:appsync:us-west-2:768127979193:apis/${self:provider.appSyncId.${self:provider.stage}}/types/*/fields/*"
- Effect: Allow
Action:
- kinesis:PutRecord
- kinesis:PutRecords
Resource:
- "arn:aws:kinesis:us-west-2:768127979193:stream/filecoin-archive-${self:provider.stage}"
domain:
dev: api-dev.space.storage
stg: api-stg.space.storage
prd: api.space.storage
appsyncUrl:
dev: https://7w65cjs2fnbwzdsltmxj427wfu.appsync-api.us-west-2.amazonaws.com/graphql
stg: https://h6qbvxquqjg5direndhm7ugaj4.appsync-api.us-west-2.amazonaws.com/graphql
prd: https://b6756lokszgovfg2lkge3t4kai.appsync-api.us-west-2.amazonaws.com/graphql
appSyncId:
dev: 5hfpy7azrrbwzfqlworbze5cqm
stg: eqz6jpndcvg27fhrcmzzdb7byi
prd: tbnqabijsrasxp6sokt4y3avxu

plugins:
- serverless-jetpack
Expand Down Expand Up @@ -164,9 +183,41 @@ functions:
identitySource: method.request.header.Authorization
type: token
resultTtlInSeconds: 0
# request:
# schema:
# application/json: ${file(schemas/addEthAddress.json)}

archiveHash:
memorySize: 128
handler: dist/archiveHash.handler
environment:
REGION: ${self:provider.region}
ENV: ${opt:stage}
events:
- http:
path: /archiveHash
method: POST
cors: true
authorizer:
name: authorizer
identitySource: method.request.header.Authorization
type: token
resultTtlInSeconds: 0

dealStatus:
memorySize: 128
handler: dist/getDealStatus.handler
environment:
REGION: ${self:provider.region}
ENV: ${opt:stage}
APPSYNC_URL: ${self:provider.appsyncUrl.${self:provider.stage}}
events:
- http:
path: /dealStatus
method: GET
cors: true
authorizer:
name: authorizer
identitySource: method.request.header.Authorization
type: token
resultTtlInSeconds: 0

uploadAvatar:
memorySize: 128
Expand Down
72 changes: 72 additions & 0 deletions services/rest/src/archiveHash.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
import { APIGatewayProxyEventBase, APIGatewayProxyResult } from 'aws-lambda';
import middy from '@middy/core';
import cors from '@middy/http-cors';
import CID from 'cids';

import AWS from 'aws-sdk';
import { AuthContext } from './authorizer';

require('cross-fetch/polyfill');

AWS.config.update({
region: 'us-west-2',
});

const kinesis = new AWS.Kinesis({
apiVersion: '2013-12-02',
});

const STAGE = process.env.ENV;

const streamName = `filecoin-archive-${STAGE}`;

const formatIpfsHash = (cid: string): string => {
const cidObj = new CID(cid);
return cidObj.toV1().toString();
};

// eslint-disable-next-line
export const handler = middy(async function(
event: APIGatewayProxyEventBase<AuthContext>
): Promise<APIGatewayProxyResult> {
const { hash, publicKey, size } = JSON.parse(event.body);

try {
const payload = {
e: {
size,
hash: formatIpfsHash(hash),
spacePublicKey: publicKey,
requestedAt: Date.now(),
},
};

const params = {
Data: JSON.stringify(payload),
StreamName: streamName,
PartitionKey: payload.e.hash.substr(-6),
};
kinesis.putRecord(params, function(err, data) {
if (err) {
console.log(err, err.stack);
throw err;
}
// an error occurred
else console.log(data); // successful response
});
} catch (e) {
return {
statusCode: 500,
body: JSON.stringify({
error: `Unable to stage for archiving: ${e.toString()}`,
}),
};
}

const response = {
statusCode: 201,
body: 'Success',
};

return response;
}).use(cors());
64 changes: 64 additions & 0 deletions services/rest/src/getDealStatus.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
import { APIGatewayProxyEventBase, APIGatewayProxyResult } from 'aws-lambda';
import middy from '@middy/core';
import cors from '@middy/http-cors';

import Appsync from 'aws-appsync';
import gql from 'graphql-tag';
import { AuthContext } from './authorizer';

require('cross-fetch/polyfill');

const graphqlClient = new Appsync({
url: process.env.APPSYNC_URL,
region: process.env.AWS_REGION,
auth: {
type: 'AWS_IAM',
credentials: {
// is there a way to get these from the lambda role
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This piece I am not hundred percent on. Will these env vars get populated or maybe there is a way to set this auth to use the default lambda execution role? That's what it should be because the permissions in serverless.yml are set for that.

accessKeyId: process.env.AWS_ACCESS_KEY_ID,
secretAccessKey: process.env.AWS_SECRET_ACCESS_KEY,
// is this needed?
// sessionToken: process.env.AWS_SESSION_TOKEN,
},
},
disableOffline: true,
});

// eslint-disable-next-line
export const handler = middy(async function(
event: APIGatewayProxyEventBase<AuthContext>
): Promise<APIGatewayProxyResult> {
const { hash } = JSON.parse(event.body);

let res;
try {
const query = gql(`query getDealStatus($hash: String!) {
getDealStatus(hash: $hash) {
proposalCid
state
duration
dealId
creationTime
}
}`);

res = await graphqlClient.query({
query,
variables: {
hash,
},
});
} catch (e) {
return {
statusCode: 500,
body: JSON.stringify({ error: `Unable to fetch deal: ${e.toString()}` }),
};
}

const response = {
statusCode: 201,
body: JSON.stringify(res),
};

return response;
}).use(cors());
2 changes: 1 addition & 1 deletion services/rest/src/sendShareEmail.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ export const handler = middy(async function(
},
Subject: { Data: emailBody.subject },
},
Source: emailBody.from || 'Space <hi@space.storage>',
Source: emailBody.from || 'Space <hey@space.storage>',
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Unrelated to Filecoin and this fix is already in dev/prd.

};

try {
Expand Down
Loading