The yata server needs AWS credentials in order to call various AWS services as
part of normal operation. Create an IAM user in your AWS account with
administrative access and then create a profile called "yata" locally with
aws configure --profile yata
. See the "Advanced Configuration" section to
customize the profile name.
The yata server uses Cognito to authenticate requests.
- Create a new Cognito user pool in your AWS account.
- Under the "General settings" navigation select "App clients" and create an app client. Make note of the app client id.
- Under the "App integration" navigation
- Select "App client settings", locate the app client you created
earlier:
- Check "Cognito User Pool" under "Enabled Identity Providers"
- Enter
http://localhost:8888
as the Callback URL(s). - Check "Implicit grant" under "Allowed OAuth Flows".
- Check "openid" under "Allowed OAuth Scopes".
- Click save; the "Launch Hosted UI" link should now be available, click it.
- Select "Domain name" and give your user pool a domain prefix. Make note of the domain name.
- Select "App client settings", locate the app client you created
earlier:
- Copy the file in
env/SampleConfig.json
toenv/CognitoConfig.json
and modify it to suite your setup.
See the "Advanced Configuration" section to customize the filename.
To use meaningfully interact with the server you need to authenticate. To authenticate you need a user to login in with.
- Go back to the "App client settings" page of your Cognito user pool.
- Locate the "Launch Hosted UI" link; click it.
- Click the "Sign Up" link at the bottom of the UI.
- Enter a desired username, email, and password.
- Complete email-based verification.
into Using the domain name you noted earlier go to the following URL to view your Cognito hosted UI to create a user.
https://<your_domain>/login?response_type=token&client_id=<your_app_client_id>&redirect_uri=<your_callback_url>
The server uses DynamoDB tables to store items and lists. You can either create them by deploying https://github.com/TheYeung1/yata-infrastructure or creating them manually:
- Create a table called
ListTable
.- With a partition key called
UserID
that's aString
. - With a sort key called
ListID
that's aString
. - Uncheck
Use default settings
and change the table to useOn-demand
capacity mode. Leave all other settings untouched.
- With a partition key called
- Create a table called
ListTable
.- With a partition key called
UserID
that's aString
. - With a sort key called
ListID-ItemID
that's aString
. - Uncheck
Use default settings
and change the table to useOn-demand
capacity mode. Leave all other settings untouched.
- With a partition key called
See the "Advanced Configuration" section to customize the table names.
- Go back to the "App client settings" page of your Cognito user pool.
- Locate the "Launch Hosted UI" link; click it.
- Login in with the user you created earlier.
- You will be redirected back to the following URL:
http://localhost:8888/#id_token=TOKEN&access_token=TOKEN&expires_in=3600&token_type=Bearer
- Copy the
TOKEN
to your clipboard.
go run main.go
- The server will start and be available at http://localhost:8888.
export TOKEN=<TOKEN>
curl -H "Authorization: Bearer $TOKEN" http://localhost:8888/items
Where the <TOKEN>
is the same TOKEN
you retrieved when getting the JWT token
earlier.
Listing all your items
curl -H "Authorization: Bearer $TOKEN" http://localhost:8888/items
Listing all your lists
curl -H "Authorization: Bearer $TOKEN" http://localhost:8888/lists
Getting a list
curl -H "Authorization: Bearer $TOKEN" http://localhost:8888/lists/<listID>/
Creating a list
curl -X PUT -d '{"ListID":"ID1","Title":"My First List"}' -H "Authorization: Bearer $TOKEN" http://localhost:8888/lists
Adding an item to a list
curl -X PUT -d '{"ItemID":"ID1","Content":"My First Item"}' -H "Authorization: Bearer $TOKEN" http://localhost:8888/lists/<listID>/items
Listing the items on a list
curl -H "Authorization: Bearer $TOKEN" http://localhost:8888/lists/<listID>/items
The yata server uses a series of optional command line flags to configure
itself. Run go run main.go --help
to view these flags and their default
values.
- (one time) Fork this repo.
- Pull down the latest:
git pull origin
. - Checkout a new branch for your change with
git checkout -b <name>
. The<name>
should be prefixed with one of ["feat", "chore", "bugfix", "other"]. Examples:feat-add-logging
.chore-cleanup-feature-gate
.bugfix-handle-malformed-requests
.other-do-something-interesting
.
- Make your change. Reference the Style Guide below to ensure your changes are consistent.
- Add tests (optional but strongly suggested).
- Test your change.
- Run
make
to format, vet, test, and build your changes. Make sure this passes. - Push to your fork.
- Create a pull request.
- Get your changes merged in.
- Checkout the
main
branch (git checkout main
) and pull (git pull origin
) down the latest. - Delete your new branch:
- Locally:
git branch -d <name>
. - Remotely:
git push <fork name> --delete <name>
.
- Locally:
- Update your fork:
git push <fork name>
.
- Code should be formatted with
make fmt
. - Code should be vetted with
make vet
. %q
is preferred over%s
when printing strings.- Imports should be sorted into two groups: standard library and everything else.
- When logging an error use
.WithError(err)
and a helpful error message. Ex:log.WithError(err).Error("failed to foo the bars")
. - Error messages should start with a lowercase letter. Ex:
failed to foo
notFailed to foo
. - Use PascalCase or camelCase over other casings such as snake_case or kebab-case.
Things we need to do. In no real order. Not comprehensive.
- More unit tests.
- Using a request-specific logger.
- How do we deploy this thing?