Skip to content

Commit

Permalink
[#157768307] Replaces autorest with fetch and autogenerated models (#292
Browse files Browse the repository at this point in the history
)
  • Loading branch information
lussoluca authored and cloudify committed Sep 19, 2018
1 parent b81e1a7 commit 3c18b5a
Show file tree
Hide file tree
Showing 50 changed files with 1,084 additions and 1,890 deletions.
6 changes: 0 additions & 6 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -32,12 +32,6 @@ jobs:
# Generate the proxy API models
- run: yarn generate:proxy-models

# Generate API client
- run: yarn generate:api-client

# Generate PagoPA client
- run: yarn generate:pagopa-client

# Generate certificates
- run: yarn generate:test-certs

Expand Down
1 change: 1 addition & 0 deletions .env.example
Original file line number Diff line number Diff line change
Expand Up @@ -19,5 +19,6 @@ ALLOW_PAGOPA_IP_SOURCE_RANGE="::ffff:ac13:1/112"
AUTHENTICATION_BASE_PATH=""
API_BASE_PATH="/api/v1"
PAGOPA_BASE_PATH="/pagopa/api/v1"
PAGOPA_API_URL= ""
SPID_AUTOLOGIN=lussoluca
SPID_TESTENV_URL=https://spid-testenv2:8088
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ npm-debug.log
*.js.map

# Excluded auto-generated API client.
/src/clients/
/src/clients/pagopa

# Excluded auto-generated API types.
/src/types/api/*.ts
Expand Down
2 changes: 0 additions & 2 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,6 @@ COPY /api_public.yaml /usr/src/app/api_public.yaml
RUN sudo chmod -R 777 /usr/src/app \
&& yarn install \
&& yarn generate:proxy-models \
&& yarn generate:api-client \
&& yarn generate:pagopa-client \
&& yarn build

FROM node:8.9.4-alpine
Expand Down
21 changes: 6 additions & 15 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ The code that manage this flow are in the `src/strategies/bearerSessionTokenStra

* [Docker](https://www.docker.com/) and [Docker Compose](https://github.com/docker/compose)

To fully simulate the SPID authentication process we use the images provided by the
To fully simulate the SPID authentication process we use the images provided by the
[spid-testenv2](https://github.com/italia/spid-testenv2) project.

A Linux/macOS environment is required at the moment.
Expand All @@ -96,12 +96,10 @@ A Linux/macOS environment is required at the moment.
3. run `scripts/build-tools.sh` to build the `tools` Docker image
4. run `scripts/yarn.sh` to install backend dependencies
5. run `scripts/generate-proxy-api-models.sh` to generate the models defined in api_proxy.yaml and api_notifications.yaml
6. run `scripts/generate-api-client.sh` to generate the Autorest API Client
7. run `scripts/generate-pagopa-client.sh` to generate the Autorest PagoPA Client
8. run `scripts/build.sh` to compile the Typescript files
9. run `scripts/generate-test-certs-task.sh` to create SAML (SPID) certificates
10. run `docker-compose up -d` to start the containers
11. edit your `/etc/hosts` file by adding:
6. run `scripts/build.sh` to compile the Typescript files
7. run `scripts/generate-test-certs-task.sh` to create SAML (SPID) certificates
8. run `docker-compose up -d` to start the containers
9. edit your `/etc/hosts` file by adding:

```
localhost spid-testenv2
Expand Down Expand Up @@ -148,7 +146,7 @@ Those are all Environment variables needed by the application:
| ALLOW_PAGOPA_IP_SOURCE_RANGE | The range in CIDR form of allowed IPs for the PagoPA API | string |
| AUTHENTICATION_BASE_PATH | The root path for the authentication endpoints | string |
| API_BASE_PATH | The root path for the api endpoints | string |
| PAGOPA_BASE_PATH | The root path for the PagoPA endpoints | string |
| PAGOPA_BASE_PATH | The root path for the PagoPA endpoints | string |
| SPID_AUTOLOGIN | The user used in the autologin feature, omit this to disable autologin | string |
### Logs
Expand Down Expand Up @@ -180,13 +178,6 @@ A Linux/macOS environment is required at the moment.
In general follow the [Node Best Practices](https://devcenter.heroku.com/articles/node-best-practices).
### Generate the API client
The API client is generated with the [AutoRest](https://github.com/Azure/autorest) tool, in case of API change you need
to regenerate the client code:
* run the command `yarn generate:api-client`
### Generate SAML (SPID) certs (development)
The backend implements a SAML Service Provider - for authenticating the clients
Expand Down
121 changes: 82 additions & 39 deletions api_proxy.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,11 @@ paths:
"$ref": "#/definitions/ServicePublic"
examples:
application/json:
department_name: dept
organization_name: org
service_id: 2b3e728c1a5d1efa035c
service_name: service
department_name: "IO"
organization_fiscal_code: "00000000000"
organization_name: "IO"
service_id: "5a563817fcc896087002ea46c49a"
service_name: "App IO"
version: 1
"401":
description: Bearer token null or expired.
Expand All @@ -56,9 +57,9 @@ paths:
$ref: "#/definitions/ServiceList"
examples:
application/json:
page_size: 1
items:
- service_id: 2b3e728c1a5d1efa035c
page_size: 1
"401":
description: Bearer token null or expired.
"500":
Expand All @@ -79,6 +80,14 @@ paths:
description: Found.
schema:
$ref: "#/definitions/ServiceList"
examples:
application/json:
items:
- service_id: "AzureDeployc49a"
version: 1
- service_id: "5a25abf4fcc89605c082f042c49a"
version: 0
page_size: 1
"401":
description: Bearer token null or expired.
"500":
Expand Down Expand Up @@ -106,10 +115,16 @@ paths:
examples:
application/json:
items:
- id: 01BX9NSMKVXXS5PSP2FATZMYYY
sender_service_id: "5a25abf4fcc89605c082f042c49a"
- id: 01BX9NSMKVXXS5PSP2FATZM123
sender_service_id: "5a25abf4fcc89605c082f042c49a"
- created_at: "2018-05-21T07:36:41.209Z"
fiscal_code: "LSSLCU79B24L219P"
id: "01CE0T1Z18T3NT9ECK5NJ09YR3"
sender_service_id: "5a563817fcc896087002ea46c49a"
time_to_live: 3600
- created_at: "2018-05-21T07:41:01.361Z"
fiscal_code: "LSSLCU79B24L219P"
id: "01CE0T9X1HT595GEF8FH9NRSW7"
sender_service_id: "5a563817fcc896087002ea46c49a"
time_to_live: 3600
page_size: 2
next: https://example.com/next
"401":
Expand Down Expand Up @@ -139,18 +154,24 @@ paths:
"200":
description: Found.
schema:
$ref: "#/definitions/MessageWithContent"
$ref: "#/definitions/CreatedMessageWithContent"
examples:
application/json:
id: 01BX9NSMKAAAS5PSP2FATZM6BQ
subject: message subject, aliquip sint nulla in estinut
markdown: Lorem ipsum dolor sit amet, consectetur adipiscing elit. Maecenas et mollis felis.
Vivamus orci nisl, commodo ut sodales ut, eleifend a libero. Donec dapibus, turpis in mattis tempor,
risus nunc malesuada ex, non aliquet metus nunc a lacus. Aenean in arcu vitae nisl porta
fermentum nec non nibh. Phasellus tortor tellus, semper in metus eget, eleifend
laoreet nibh. Aenean feugiat lectus ut nisl eleifend gravida.
sender_service_id: "5a25abf4fcc89605c082f042c49a"
created_at: "2018-05-21T12:45:41.105Z"
message: {
content: {
markdown: "hey hey !! <a style=\"color: red\" href=\"http://example.com\"> some content here ..... this is a link with a style applied, some other content</a>",
subject: "my subject ............"
},
created_at: "2018-06-06T12:22:24.523Z",
fiscal_code: "LSSLCU79B24L219P",
id: "01CFAGRMGB9XCA8B2CQ4QA7K76",
sender_service_id: "5a25abf4fcc89605c082f042c49a",
time_to_live: 3600
}
notification: {
email: "SENT"
}
status: "PROCESSED"
"401":
description: Bearer token null or expired.
"404":
Expand All @@ -176,16 +197,17 @@ paths:
- $ref: "#/definitions/AuthenticatedProfile"
examples:
application/json:
email: "email@example.com"
family_name: "Rossi"
fiscal_code: "TMMEXQ60A10Y526X"
has_profile: true
is_email_set: false
is_email_set: true
is_inbox_enabled: true
is_webhook_enabled: false
is_webhook_enabled: true
name: "Mario"
preferred_email: "preferred@example.com"
spid_email: "preferred@example.com"
spid_mobile_phone: "1234567890"
version: 1
email: "email@example.com"
"401":
description: Bearer token null or expired.
"500":
Expand Down Expand Up @@ -215,10 +237,16 @@ paths:
$ref: "#/definitions/InitializedProfile"
examples:
application/json:
email: foobar@example.com
preferred_languages: [ it_IT ]
email: "email@example.com"
family_name: "Rossi"
fiscal_code: "TMMEXQ60A10Y526X"
has_profile: true
is_email_set: true
is_inbox_enabled: true
is_webhook_enabled: false
is_webhook_enabled: true
name: "Mario"
spid_email: "preferred@example.com"
spid_mobile_phone: "1234567890"
version: 1
'400':
description: Invalid payload.
Expand Down Expand Up @@ -442,10 +470,12 @@ definitions:
$ref: "https://raw.githubusercontent.com/teamdigitale/digital-citizenship-functions/v0.51.0/api/definitions.yaml#/PaymentData"
TimeToLiveSeconds:
$ref: "https://raw.githubusercontent.com/teamdigitale/digital-citizenship-functions/v0.51.0/api/definitions.yaml#/TimeToLiveSeconds"
MessageWithContent:
CreatedMessageWithContent:
$ref: "https://raw.githubusercontent.com/teamdigitale/digital-citizenship-functions/v0.51.0/api/definitions.yaml#/CreatedMessageWithContent"
MessageWithoutContent:
CreatedMessageWithoutContent:
$ref: "https://raw.githubusercontent.com/teamdigitale/digital-citizenship-functions/v0.51.0/api/definitions.yaml#/CreatedMessageWithoutContent"
MessageResponseWithContent:
$ref: "https://raw.githubusercontent.com/teamdigitale/digital-citizenship-functions/v0.51.0/api/definitions.yaml#/MessageResponseWithContent"
ServiceList:
type: object
title: List of services.
Expand All @@ -468,7 +498,7 @@ definitions:
items:
type: array
items:
$ref: "#/definitions/MessageWithoutContent"
$ref: "#/definitions/CreatedMessageWithoutContent"
next:
type: string
page_size:
Expand All @@ -495,29 +525,27 @@ definitions:
properties:
email:
$ref: '#/definitions/EmailAddress'
blocked_inbox_or_channels:
$ref: "#/definitions/BlockedInboxOrChannels"
preferred_languages:
$ref: "#/definitions/PreferredLanguages"
is_inbox_enabled:
$ref: "#/definitions/IsInboxEnabled"
is_webhook_enabled:
$ref: "#/definitions/IsWebhookEnabled"
family_name:
type: string
fiscal_code:
$ref: '#/definitions/FiscalCode'
has_profile:
$ref: "#/definitions/HasProfile"
is_inbox_enabled:
$ref: "#/definitions/IsInboxEnabled"
is_webhook_enabled:
$ref: "#/definitions/IsWebhookEnabled"
name:
type: string
spid_email:
$ref: '#/definitions/EmailAddress'
spid_mobile_phone:
type: string
minLength: 1
preferred_languages:
type: array
items:
$ref: '#/definitions/PreferredLanguage'
blocked_inbox_or_channels:
$ref: "#/definitions/BlockedInboxOrChannels"
version:
$ref: '#/definitions/Version'
required:
Expand Down Expand Up @@ -601,6 +629,21 @@ definitions:
description: |-
The Push Notification Service handle for this Installation.
See https://docs.microsoft.com/en-us/azure/notification-hubs/notification-hubs-push-notification-registration-management
Services:
type: object
title: A list of services
properties:
items:
type: array
items:
$ref: "#/definitions/ServiceTuple"
next:
type: string
page_size:
$ref: '#/definitions/PageSize'
required:
- items
- page_size
SpidLevel:
type: string
description: A SPID level.
Expand Down
6 changes: 2 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,6 @@
"prettify": "prettier --write \"./**/*.ts\"",
"test": "jest -i",
"start": "node src/server.js",
"generate:api-client": "swagger-cli bundle https://raw.githubusercontent.com/teamdigitale/digital-citizenship-functions/v0.49.0/api/public_api_v1.yaml | autorest --typescript --input-file=/dev/stdin --output-folder=src/clients/api --add-credentials --use=@microsoft.azure/autorest.typescript@2.0.157",
"generate:pagopa-client": "swagger-cli bundle https://raw.githubusercontent.com/teamdigitale/italia-pagopa-proxy/v0.5.12/api_pagopa.yaml | autorest --typescript --input-file=/dev/stdin --output-folder=src/clients/pagopa --use=@microsoft.azure/autorest.typescript@2.0.157",
"generate:proxy-models": "npm-run-all generate:proxy:*",
"generate:proxy:api-models": "gen-api-models --api-spec api_proxy.yaml --no-strict --out-dir src/types/api",
"generate:proxy:notification-models": "gen-api-models --api-spec api_notifications.yaml --no-strict --out-dir src/types/api",
Expand Down Expand Up @@ -50,7 +48,7 @@
"italia-ts-commons": "^2.12.3",
"json-set-map": "^1.0.2",
"morgan": "^1.9.1",
"ms-rest-js": "^0.3.1",
"node-fetch": "^2.2.0",
"passport": "^0.4.0",
"passport-auth-token": "^1.0.1",
"passport-http-bearer": "^1.0.1",
Expand All @@ -77,6 +75,7 @@
"@types/jest": "^23.3.2",
"@types/lolex": "2.1.3",
"@types/morgan": "^1.7.35",
"@types/node-fetch": "^2.1.2",
"@types/passport": "^0.4.6",
"@types/passport-http-bearer": "^1.0.33",
"@types/passport-strategy": "^0.2.35",
Expand All @@ -88,7 +87,6 @@
"@types/validator": "^9.4.2",
"@types/xml2js": "^0.4.3",
"@types/xmldom": "^0.1.29",
"autorest": "^2.0.4280",
"danger": "^4.0.1",
"danger-plugin-digitalcitizenship": "^0.3.1",
"fp-ts": "^1.8.1",
Expand Down
10 changes: 5 additions & 5 deletions public/message.html
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ <h1>Message</h1>
response.json().then(function(data) {
console.log(data);

fetch('./api/v1/services/' + data.sender_service_id, {
fetch('./api/v1/services/' + data.message.sender_service_id, {
headers: {
'Authorization': 'Bearer ' + token
},
Expand All @@ -97,10 +97,10 @@ <h1>Message</h1>
console.log('Fetch Error :-S', err);
});

$('#subject').append(data.subject);
$('#markdown').append(data.markdown);
$('#created_at').append(data.created_at);
$('#sender_service_id').append(data.sender_service_id);
$('#subject').append(data.message.content.subject);
$('#markdown').append(data.message.content.markdown);
$('#created_at').append(data.message.created_at);
$('#sender_service_id').append(data.message.sender_service_id);

if(data.payment_data) {
$('#amount').append(data.payment_data.amount);
Expand Down
3 changes: 0 additions & 3 deletions scripts/generate-api-client.sh

This file was deleted.

3 changes: 0 additions & 3 deletions scripts/generate-pagopa-client.sh

This file was deleted.

Loading

0 comments on commit 3c18b5a

Please sign in to comment.