-
Notifications
You must be signed in to change notification settings - Fork 3
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
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
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()); |
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 | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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()); |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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>', | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Unrelated to Filecoin and this fix is already in dev/prd. |
||
}; | ||
|
||
try { | ||
|
There was a problem hiding this comment.
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.