Skip to content

Commit c8f3f54

Browse files
authored
Merge pull request #13 from emmaLP/docs
Docs
2 parents 4f1b487 + f576021 commit c8f3f54

File tree

2 files changed

+41
-5
lines changed

2 files changed

+41
-5
lines changed

README.md

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,3 +20,40 @@ go build .
2020
go test .
2121
```
2222

23+
## Deploy
24+
The deployment is handled through terraform scripts.
25+
26+
Terraform scripts configure the following:
27+
1. Go Lambda with the pack calc deployed
28+
1. Node Lambda used as an authoriser for the API Gateway
29+
1. API Gateway integrated with the pack calc lambda
30+
1. A randomly generated token stored as a secure string in `ParamterStore` which is used as the auth token
31+
32+
### API
33+
The API only supports on endpoint as a POST request.
34+
35+
The API body is JSON and should look like this example:
36+
```json
37+
{
38+
"items":501,
39+
"packSizes": [250,500,1000,2000,5000]
40+
}
41+
```
42+
43+
Example Request:
44+
45+
```bash
46+
curl -X POST --data '{"items":501, "packSizes": [250,500,1000,2000,5000]}' \
47+
https://jcwz2ki77i.execute-api.eu-west-2.amazonaws.com/calculate-packs -H "Authorization: qD449xM9k0nvK@_f"
48+
```
49+
**The auth token is just an example**
50+
51+
52+
## Notes/ Considerations
53+
1. Unfortunately, I did not have enough time to implement a frontend as I was learning golang while implementing the backend
54+
1. GitHub Actions have been used to do the following:
55+
1. Build and Test the Go Lang Code
56+
1. Terraform script validation (`fmt`, `init` and `validate`)
57+
1. On a PR merge, a GitHub release is created with the compiled Go code attached
58+
1. Once a GitHub release is published, a deployment workflow is triggered.
59+
1. This workflow will handle the deployment of the resources

deploy/files/token_authoriser.js

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -39,21 +39,20 @@ exports.handler = async (event) => {
3939
}
4040
};
4141
let authHeader = event.headers['authorization']
42-
console.log("Auth Header", authHeader)
4342
await getSecret(process.env.SECRET_KEY)
4443
.then(secret => {
45-
if (!authHeader === secret) {
44+
if (authHeader === secret) {
4645
response = {
47-
"isAuthorized": false,
46+
"isAuthorized": true,
4847
"context": {
4948
"booleanKey": true,
5049
}
5150
}
5251
} else {
5352
response = {
54-
"isAuthorized": true,
53+
"isAuthorized": false,
5554
"context": {
56-
"booleanKey": true,
55+
"booleanKey": false,
5756
}
5857
}
5958
}

0 commit comments

Comments
 (0)