https://github.com/alphagov/paas-accounts
https://github.com/alphagov/paas-accounts
cloud-foundry paas reliability-engineering
Last synced: 12 months ago
JSON representation
- Host: GitHub
- URL: https://github.com/alphagov/paas-accounts
- Owner: alphagov
- License: mit
- Created: 2018-05-02T14:08:24.000Z (about 8 years ago)
- Default Branch: main
- Last Pushed: 2025-07-02T12:08:21.000Z (12 months ago)
- Last Synced: 2025-07-02T13:25:45.631Z (12 months ago)
- Topics: cloud-foundry, paas, reliability-engineering
- Language: Go
- Size: 15.7 MB
- Stars: 1
- Watchers: 9
- Forks: 3
- Open Issues: 5
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# paas-accounts
API for storing information about PaaS users.
## Build
```
go build -o paas-accounts .
```
## Test
```
make start_postgres_docker
make test
make stop_postgres_docker
```
## Run
```
BASIC_AUTH_USERNAME="some-user" \
BASIC_AUTH_PASSWORD="some-pass" \
DATABASE_URL="postgres://..." \
PORT=8080 \
./paas-accounts
```
## Deploy
A manifest.yml exists for deploying to cloudfoundry. You should ensure the required environment variables are in place and that a suitable postgres database service is bound.
## API
### PUT /documents/:name
Create or update a document:
curl -u : -H "Content-Type: application/json" -X PUT -d '{"content": "my content"}' https:///documents/my_document
### GET /documents/:name
Retrieve an existing document:
curl -u : https:///documents/my_document
## Agreements
### POST /agreements
Record a user's agreement to a document:
curl -u : -H "Content-Type: application/json" -X POST -d '{"user_uuid": "00000000-0000-0000-0000-000000000001", "document_name": "my_document"}' https:///agreements
### GET /users/:uuid/documents
Get all documents for a user:
curl -u : https:///users/00000000-0000-0000-0000-000000000001/documents
Get all documents for a user that need agreement:
curl -u : -G -d agreed=false https:///users/00000000-0000-0000-0000-000000000001/documents
### GET /users/:uuid
Get a user:
curl -u : https:///users/00000000-0000-0000-0000-000000000001
### GET /users
Get users by guids (accepts multiple guids):
curl -u : -G https:///users?uuids=00000000-0000-0000-0000-000000000001,00000000-0000-0000-0000-000000000002
Get users by email (accepts a single email address):
curl -u : -G https:///users?email=example%40example.com
### POST /users/:uuid
POST a user:
curl -u : -H "Content-Type: application/json" -X POST -d '{"user_email": "example@example.com", "username": "example@example.com", "user_uuid": "00000000-0000-0000-0000-000000000001"}' https:///users/00000000-0000-0000-0000-000000000001
### PATCH /users/:uuid
PATCH a user:
curl -u : -H "Content-Type: application/json" -X PATCH -d '{"user_email": "newexample@example.com"}' https:///users/00000000-0000-0000-0000-000000000001
### Error handling
To handle an error in a handler function, such as an entity not being found or an internal server error, return one of the error types from `api/errors.go`
```go
func HttpHandler(db *database.DB) echo.HandlerFunc {
return func(c echo.Context) error {
thing, err := db.GetAThing(c.Param("id"))
if err != nil {
if err == database.ErrNotFound {
return NotFoundError{"thing not found"}
}
return InternalServerError{err}
}
return c.JSON(http.StatusOK, thing)
}
}
```