Skip to content

Commit 7463a76

Browse files
committed
IN-493 fix ports for new ver of motoserver and improve makefile
1 parent ee3e8be commit 7463a76

11 files changed

+71
-302
lines changed

.secrets.baseline

+2-2
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
"files": null,
44
"lines": null
55
},
6-
"generated_at": "2020-10-27T15:31:23Z",
6+
"generated_at": "2020-11-06T13:37:02Z",
77
"plugins_used": [
88
{
99
"name": "AWSKeyDetector"
@@ -58,7 +58,7 @@
5858
{
5959
"hashed_secret": "dc724af18fbdd4e59189f5fe768a5f8311527050",
6060
"is_verified": false,
61-
"line_number": 68,
61+
"line_number": 69,
6262
"type": "Secret Keyword"
6363
}
6464
]

Makefile

+19-6
Original file line numberDiff line numberDiff line change
@@ -3,23 +3,36 @@ THIS_FILE := $(lastword $(MAKEFILE_LIST))
33
help:
44
make -pRrq -f $(THIS_FILE) : 2>/dev/null | awk -v RS= -F: '/^# File/,/^# Finished Make data base/ {if ($$1 !~ "^[#.]") {print $$1}}' | sort | egrep -v -e '^[^[:alnum:]]' -e '^$@$$'
55

6-
everything:
7-
docker-compose -f docker-compose.yml up -d --build
8-
chmod +x mock_aws_services/create_secret.sh
9-
mock_aws_services/create_secret.sh
10-
just_api:
11-
docker-compose -f docker-compose.yml up --build -d mock-sirius motoserver api_gateway
6+
create_secrets:
127
chmod +x mock_aws_services/create_secret.sh
8+
sleep 5
139
mock_aws_services/create_secret.sh
10+
python3 mock_aws_services/create_secret.py
11+
12+
build:
13+
./build.sh
14+
15+
up:
16+
docker-compose -f docker-compose.yml up -d mock-sirius motoserver api_gateway
17+
18+
up-all:
19+
docker-compose -f docker-compose.yml up -d
1420

1521
down:
1622
docker-compose -f docker-compose.yml down $(c)
1723

24+
setup: build up create_secrets
25+
26+
setup-all: build up-all create_secrets
27+
1828
destroy:
1929
docker-compose down -v --rmi all --remove-orphans
30+
2031
ps:
2132
docker-compose -f docker-compose.yml ps
33+
2234
login-api-gateway:
2335
docker-compose -f docker-compose.yml exec api_gateway /bin/bash
36+
2437
logs:
2538
docker-compose -f docker-compose.yml logs --tail=100 -f $(c)

README.md

+38-23
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,35 @@ LPA related functions.
2222

2323
## Running the API locally
2424

25-
### Set up
25+
To run the API locally you should have aws-vault installed and have an account that has access to assume
26+
the operator role in sirius dev.
27+
28+
- Run full setup script from the make file:
29+
```
30+
make setup
31+
```
32+
or if you want pact as well:
33+
```
34+
make setup-all
35+
```
36+
- Test the setup
37+
38+
```
39+
curl -X GET http://localhost:4343/v1/healthcheck
40+
curl -X GET http://localhost:4343/v1/lpa-online-tool/lpas/A39721583862
41+
curl -X GET http://localhost:4343/v1/use-an-lpa/lpas/700000000013
42+
```
43+
44+
That should be all you need to set it up locally.
45+
46+
-----------------------------------
47+
48+
## Manual setup
49+
50+
#### Set up local development environment outside of docker
51+
52+
If you wish to develop against this environment and don't want to be dealing with docker containers then there
53+
is a bit more of an in depth set up process required.
2654

2755
1. Create a virtual environment
2856
```bash
@@ -48,30 +76,19 @@ LPA related functions.
4876
pip3 install -r lambda_functions/v1/requirements/dev-requirements.txt
4977
```
5078

51-
52-
53-
#### Running flask app locally, aka the quick way
79+
1. Remove the codeartifact login
80+
```bash
81+
rm ~/.pypirc
82+
```
83+
#### Running flask app locally
5484

5585
1. `cd lambda_functions/v1/functions/lpa/app`
5686
1. `flask run`
5787
1. Endpoints should be available on `http://localhost:5000`
5888

59-
#### Running everything in Docker
60-
61-
1. Get your AWS credentials
62-
```bash
63-
cd docs/support_scripts/aws
64-
65-
aws-vault exec identity -- go run ./getcreds.go
66-
```
67-
1. Copy & paste the output to set your AWS details as env vars
68-
* This is because we are using custom packages hosted in AWS CodeArtifact and we need to log in to be able to pip install them
69-
1. In the root folder: `make everything` (you can also use `make just_api` if you are not interested in Pact)
70-
1. Endpoints should be available on `http://0.0.0.0:4343`
71-
7289
## Unit Tests
7390

74-
1. [Set up local environment](#Set up)
91+
1. [Set up local environment](#set-up-local-development-environment-outside-of-docker)
7592

7693
1. Run the tests command-line style
7794
```bash
@@ -84,12 +101,12 @@ LPA related functions.
84101
```
85102
1. Run the tests in PyCharm
86103

87-
* Go to PyCharm > Preferences > Tools > Python Integrated Tools
104+
* Go to PyCharm > Preferences > Tools > Python Integrated Tools
88105
* Set the Default Test Runner to 'pytest'
89106
* Right click on the tests folder (or single file) > 'Run pytest in tests'
90107

91108
## Integration Tests
92-
1. [Set up local environment](#Set up)
109+
1. [Set up local environment](#set-up-local-development-environment-outside-of-docker)
93110

94111
1. Setup the tests:
95112
- In `integration_tests/v1/conftest.py`, check that the url you are pointing to is correct.
@@ -101,8 +118,6 @@ LPA related functions.
101118
aws-vault exec identity -- python -m pytest -n2 --dist=loadfile --html=report.html --self-contained-html
102119
```
103120

104-
105-
106121
## PACT
107122

108123
To run pact locally, the easiest way to interact with it is to use the client tools.
@@ -135,7 +150,7 @@ http://localhost:9292/pacticipants/lpa_data/versions/x12345/tags/v1
135150

136151
You can check it has worked here:
137152

138-
`http://localhost:9292/matrix/provider/OPG%20Data/consumer/Complete%20the%20deputy%20report`
153+
`http://localhost:9292/matrix/provider/lpa_data_sirius/consumer/lpa_data`
139154

140155
Run the secret creation against mock
141156

build.sh

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
$(aws-vault exec identity -- go run ./docs/support_scripts/aws/getcreds.go)
2+
docker-compose -f docker-compose.yml build \
3+
--build-arg AWS_ACCESS_KEY_ID=$AWS_ACCESS_KEY_ID \
4+
--build-arg AWS_SECRET_ACCESS_KEY=$AWS_SECRET_ACCESS_KEY \
5+
--build-arg AWS_SESSION_TOKEN=$AWS_SESSION_TOKEN

docker-compose.yml

+1
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ services:
4040
dockerfile: Dockerfile
4141
ports:
4242
- "4584:4584"
43+
- "4566:4566"
4344
redis:
4445
image: "redis:alpine"
4546
ports:

docs/support_scripts/aws/getcreds.go

+2-4
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,10 @@ import (
1212
func main() {
1313

1414
roletoassume := "arn:aws:iam::288342028542:role/operator"
15-
// roletoassume := "arn:aws:iam::492687888235:role/operator"
1615

1716
mysession := session.Must(session.NewSession())
18-
digidepcreds := stscreds.NewCredentials(mysession, roletoassume)
19-
cfg := aws.Config{Credentials: digidepcreds,Region: aws.String("eu-west-1")}
17+
creds := stscreds.NewCredentials(mysession, roletoassume)
18+
cfg := aws.Config{Credentials: creds,Region: aws.String("eu-west-1")}
2019
sess := session.Must(session.NewSession(&cfg))
2120
sessionstring, err := sess.Config.Credentials.Get()
2221

@@ -30,7 +29,6 @@ func main() {
3029
fmt.Println(accesskey)
3130
fmt.Println(secret)
3231
fmt.Println(session)
33-
fmt.Println("Provider Name: ",sessionstring.ProviderName)
3432

3533
}
3634

mock_aws_services/Dockerfile

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,5 +5,5 @@ RUN apk add --no-cache gcc musl-dev libffi-dev openssl-dev && \
55
apk del gcc musl-dev libffi-dev openssl-dev
66

77

8-
CMD moto_server secretsmanager -H 0.0.0.0 -p 4584
8+
CMD moto_server secretsmanager -H 0.0.0.0 -p 4566
99

mock_aws_services/create_secret.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
from tenacity import retry
33
import requests
44

5-
url = "http://0.0.0.0:4584/?Action=CreateSecret"
5+
url = "http://0.0.0.0:4566/?Action=CreateSecret"
66

77

88
payload = {

mock_aws_services/create_secret.sh

+2-2
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,9 @@
22

33

44
printf "creating secret\n"
5-
until $(curl --output /dev/null --silent --head --fail 'http://0.0.0.0:4584/?Action=ListSecrets'); do
5+
until $(curl --output /dev/null --silent --head --fail 'http://0.0.0.0:4566/?Action=ListSecrets'); do
66
printf '.'
77
sleep 1
88
done
9-
curl --location --request POST 'http://0.0.0.0:4584/?Action=CreateSecret' --header 'Content-Type: application/json' --header 'Content-Type: text/plain' --data-raw '{"Name": "local/jwt-key_docker", "Description": "Secret for local testing with Docker","SecretString":"this_is_a_secret_string","ClientRequestToken": "EXAMPLE1-90ab-cdef-fedc-ba987SECRET1"}'
9+
curl --location --request POST 'http://0.0.0.0:4566/?Action=CreateSecret' --header 'Content-Type: application/json' --header 'Content-Type: text/plain' --data-raw '{"Name": "local/jwt-key_docker", "Description": "Secret for local testing with Docker","SecretString":"this_is_a_secret_string","ClientRequestToken": "EXAMPLE1-90ab-cdef-fedc-ba987SECRET1"}'
1010
printf "\nsecret created\n"

pact/example/digideps-pact-v1.json

-83
This file was deleted.

0 commit comments

Comments
 (0)