Skip to content

V5 #18

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 12 commits into from
Jun 29, 2018
Merged

V5 #18

Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ workflows:
- "build-dev":
filters:
branches:
only: ['dev','feature/m2mtoken-support']
only: ['dev']
- "build-prod":
filters:
branches:
Expand Down
1 change: 0 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1 @@
node_modules/
dist
23 changes: 23 additions & 0 deletions .swagger-codegen-ignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
# Swagger Codegen Ignore
# Generated by swagger-codegen https://github.com/swagger-api/swagger-codegen

# Use this file to prevent files from being overwritten by the generator.
# The patterns follow closely to .gitignore or .dockerignore.

# As an example, the C# client generator defines ApiClient.cs.
# You can make changes and tell Swagger Codgen to ignore just this file by uncommenting the following line:
#ApiClient.cs

# You can match any string of characters against a directory, file or extension with a single asterisk (*):
#foo/*/qux
# The above matches foo/bar/qux and foo/baz/qux, but not foo/bar/baz/qux

# You can recursively match patterns against a directory, file or extension with a double asterisk (**):
#foo/**/qux
# This matches foo/bar/qux, foo/baz/qux, and foo/bar/baz/qux

# You can also negate patterns with an exclamation (!).
# For example, you can ignore all files in a docs folder with the file extension .md:
#docs/*.md
# Then explicitly reverse the ignore rule for a single file:
#!docs/README.md
1 change: 1 addition & 0 deletions .swagger-codegen/VERSION
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
2.3.1
2 changes: 1 addition & 1 deletion Procfile
Original file line number Diff line number Diff line change
@@ -1 +1 @@
web: node index.js
web: node index.js
138 changes: 21 additions & 117 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,15 +1,19 @@
# TopCoder Notifications - Bus API Server
------------------------------------------------------------
# Topcoder Bus API Server

## Overview

A meta service, Topcoder Bus API server provides information about other services offered by Topcoder.

This server was generated initially by the [swagger-codegen](https://github.com/swagger-api/swagger-codegen) project. We then copied over changes that existed in the older version over to version 5

## Requirements

- node.js 8.7.0 (the latest)
- Heroku CLI: https://devcenter.heroku.com/articles/heroku-cli#download-and-install
Nodejs: ~8

## Configuration

### Kafka Configurations
The following Kafka configurations must be set in the environment variables:

- `KAFKA_URL` the Kafka url
- `KAFKA_CLIENT_CERT` the SSL client cert, can be string or file path
- `KAFKA_CLIENT_CERT_KEY` the SSL client cert key, can be string or file path
Expand Down Expand Up @@ -69,7 +73,7 @@ Jp8xItVz3sqz5aCg+EvcewSGZ18AC+9cbxrbI2I83jQDHw+DQmVUyR6rl5+r+S6O
-----END RSA PRIVATE KEY-----"
```

### Other Configurations
## Other Configurations

The other configurations can be changed in `config/default.js` or by setting environment variables.

Expand All @@ -84,123 +88,23 @@ The other configurations can be changed in `config/default.js` or by setting env
- `TC_EMAIL_TOKEN` the email service authentication token (see tc-email README for details **link should be added later**)
- `TC_EMAIL_CACHE_PERIOD` the period to cache template placeholders from email service (60 min default)

## Code Standard
The code follows StandardJS:

```bash
npm install
npm run lint
```

## Generate JWT Tokens:
To generate JWT Tokens for allowed services, run:

```bash
npm run generate-tokens
```

## Local Deployment and Verification

- Start

```
npm run start
```

- Import `docs/tc-bus-api-server.postman_collection.json` and `docs/tc-bus-api-server.postman_environment.json` to Postman
- Change `URL` environment variable in Postman according to your deployment. If you deploy locally, it should be `http://localhost:3000/api/v1` by default
- Change `VALID_TOKEN` if you want to test with another JWT token
- Change `VALID_MESSAGE_TYPE` if you want to test with another message type
- Change `EMAIL` to a valid e-mail address
- Execute calls to verify the endpoints


### Verify the messsages end up in Kafka queue
Check `bus-api-test/README.md` to run a consumer that consumes and prints all messages in Kafka queue.

## Heroku Deployment and Verification

- Login and create a new app
```bash
heroku login
heroku create
```
## Deploying the server

- Set Kafka configurations (and other configurations if necessary)
```bash
heroku config:set KAFKA_URL=<your Kafka url> --app <your app name>
heroku config:set KAFKA_CLIENT_CERT=<your Kafka client cert string or file> --app <your app name>
heroku config:set KAFKA_CLIENT_CERT_KEY=<your Kafka client cert key string or file> --app <your app name>
```
To deploy the server locally, run:

Example (please change your app name):
```bash
heroku config:set KAFKA_URL="kafka+ssl://ec2-34-205-227-216.compute-1.amazonaws.com:9096,kafka+ssl://ec2-34-233-75-247.compute-1.amazonaws.com:9096,kafka+ssl://ec2-34-198-118-170.compute-1.amazonaws.com:9096,kafka+ssl://ec2-34-231-150-104.compute-1.amazonaws.com:9096,kafka+ssl://ec2-34-233-209-20.compute-1.amazonaws.com:9096,kafka+ssl://ec2-34-233-131-252.compute-1.amazonaws.com:9096,kafka+ssl://ec2-52-205-198-73.compute-1.amazonaws.com:9096,kafka+ssl://ec2-52-4-109-80.compute-1.amazonaws.com:9096" --app <your app name>

heroku config:set KAFKA_CLIENT_CERT="-----BEGIN CERTIFICATE-----
MIIDQzCCAiugAwIBAgIBADANBgkqhkiG9w0BAQsFADAyMTAwLgYDVQQDDCdjYS1j
YmJiNGVkZi1mNDFhLTRjNzMtYTg5OC01NDYyMjhkNmQyNDIwHhcNMTcwOTI3MDUw
MTIyWhcNMjcwOTI3MDUwMTIyWjAZMRcwFQYDVQQDDA51ODFvcjFsdTl2dTB1bzCC
ASIwDQYJKoZIhvcNAQEBBQADggEPADCCAQoCggEBAKjkcV/BXD13Q09bRKohN/sK
iDMGFA2QZ57TGd7svX7iZQIk9HmXEPd5zCTHZ6nZBbcGDQ9P+zGlJIGZQuRVKLOn
ZPilaeUHRGrvCWGJZ6lVPNqInC1STHTfFJhcUNMG6qaD2ayBAw16f13vD1wGEWCm
/DRfvrjIp3JIetGdKctmdiGLYH7CQecRW88Czx9e3Vpl1nxGcNAPDDCj0nRwuPse
fVrg5onPX355om+Ct/teSeSONhio4dFL3fwl47CXFCReZFYOrBoLexfHXHumJ/Kp
TQW+k056hhoagykcpTf8uNjxNRalDPkw7ngt+1IzatbhOacea1/WUE1444eEak8C
AwEAAaN9MHswHQYDVR0OBBYEFJJzd6OZVLthBkhVZEW42CR8NJbtMFoGA1UdIwRT
MFGAFORcypfrQ0tfS5tyBdv89jfpZEMaoTakNDAyMTAwLgYDVQQDDCdjYS1jYmJi
NGVkZi1mNDFhLTRjNzMtYTg5OC01NDYyMjhkNmQyNDKCAQAwDQYJKoZIhvcNAQEL
BQADggEBALVAdOWXdnSqhucXHjpIf0lxlH6WhzhhlctLCreSf+/7y6pPVpWSVIEl
seVxOE5tsO2OzdtGgN2t7rr6bHuakL5rk9rH06r1jYAVQBR+T6SSLFbSVzl4Q5TO
b+T9/sHx5QtXSYgMh4FhZcBjrmDmWvpd42Y4MPfjLTqTP8RWHHib8E4/FYS9txk6
WoxrKcgnm/RmOcFWrjNjgm6JJprO1BSnbc2i/Rs5rxG2tRTTmXp6d7QCRa0bdhKz
yETgcStnaVvyh64zhls3xXBm06rvpu2wwo6QHcPeekvQwxQvb63oovD8b+pFJri+
6MBSQE4TtQenlVx7Ksy9UdNmU21xCYU=
-----END CERTIFICATE-----" --app <your app name>

heroku config:set KAFKA_CLIENT_CERT_KEY="-----BEGIN RSA PRIVATE KEY-----
MIIEogIBAAKCAQEAqORxX8FcPXdDT1tEqiE3+wqIMwYUDZBnntMZ3uy9fuJlAiT0
eZcQ93nMJMdnqdkFtwYND0/7MaUkgZlC5FUos6dk+KVp5QdEau8JYYlnqVU82oic
LVJMdN8UmFxQ0wbqpoPZrIEDDXp/Xe8PXAYRYKb8NF++uMinckh60Z0py2Z2IYtg
fsJB5xFbzwLPH17dWmXWfEZw0A8MMKPSdHC4+x59WuDmic9ffnmib4K3+15J5I42
GKjh0Uvd/CXjsJcUJF5kVg6sGgt7F8dce6Yn8qlNBb6TTnqGGhqDKRylN/y42PE1
FqUM+TDueC37UjNq1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lx8CEtBGUz/iM
bZpxAoGAEnJFUEGCB1ta3RQpI5L4nH2Rex0Avv8rkXGK2T/t5z2h8Ujg4WW3J7DD
Jp8xItVz3sqz5aCg+EvcewSGZ18AC+9cbxrbI2I83jQDHw+DQmVUyR6rl5+r+S6O
69wdZ08Y/jYkltb5PbhPqs0Kfr86cUqBuKEptRtto6Wto3k/Za4=
-----END RSA PRIVATE KEY-----" --app <your app name>
npm install
npm start
```

- Push to Heroku
```bash
git init
git add .
git commit -m "init"
heroku git:remote -a <your app name>
git push heroku master
```
## Generate JWT Tokens:

- The app will be available at `https://<your app name>.herokuapps.com/api/v1`
To generate JWT Tokens for allowed services, run:

- Verification is similar to local verification, but you need to change `URL` in Postman to the Heroku app url `https://<your app name>.herokuapps.com/api/v1`
```bash
npm run generate-tokens
```

## Others
To view the Swagger UI interface visit `http://localhost:3000/docs`

- Swagger definition: `docs/swagger.yaml`
- Demo Heroku app: `https://morning-mesa-65797.herokuapp.com/api/v1`
This project leverages the mega-awesome [swagger-tools](https://github.com/apigee-127/swagger-tools) middleware which does most all the work.
Loading