From 8939e457c709ca34fa59f97aeaf61d3df323a8c3 Mon Sep 17 00:00:00 2001 From: Abdulbasid Guled Date: Wed, 17 Mar 2021 20:50:44 -0400 Subject: [PATCH 1/2] Updated readme, docker-compose files, and user related files --- docker/docker-compose.yml | 24 +++++++ docker/production.yml | 10 +++ src/api/docker-compose.yml | 108 -------------------------------- src/api/env.development | 92 --------------------------- src/api/readme.md | 26 ++++---- src/api/user/README.md | 12 ++-- src/api/user/src/models/user.js | 4 +- src/api/user/src/routes/user.js | 2 +- 8 files changed, 55 insertions(+), 223 deletions(-) delete mode 100644 src/api/docker-compose.yml delete mode 100644 src/api/env.development diff --git a/docker/docker-compose.yml b/docker/docker-compose.yml index a9e7134d59..1ec0824c9b 100644 --- a/docker/docker-compose.yml +++ b/docker/docker-compose.yml @@ -118,6 +118,30 @@ services: - 'traefik.http.middlewares.strip_feed_discovery_prefix.stripprefix.forceSlash=true' - 'traefik.http.routers.feed-discovery.middlewares=strip_feed_discovery_prefix' + # user service + user: + container_name: 'user' + build: + context: ../src/api/user + dockerfile: Dockerfile + environment: + - USER_PORT + ports: + - ${USER_PORT} + depends_on: + - traefik + labels: + # Enable Traefik + - 'traefik.enable=true' + # Traefik routing for the user service at /v1/user + - 'traefik.http.routers.user.rule=PathPrefix(`/${API_VERSION}/user`)' + # Specify the user service port + - 'traefik.http.services.user.loadbalancer.server.port=${USER_PORT}' + # Add middleware to this route to strip the /v1/user prefix + - 'traefik.http.middlewares.strip_user_prefix.stripprefix.prefixes=/${API_VERSION}/user' + - 'traefik.http.middlewares.strip_user_prefix.stripprefix.forceSlash=true' + - 'traefik.http.routers.user.middlewares=strip_user_prefix' + ############################################################################## # Third-Party Dependencies and Support Services ############################################################################## diff --git a/docker/production.yml b/docker/production.yml index 90ddc307a0..feba95a5ee 100644 --- a/docker/production.yml +++ b/docker/production.yml @@ -132,6 +132,16 @@ services: # - ELASTICSEARCH_HOSTS=http://elasticsearch:9200 # - ELASTIC_APM_SERVICE_NAME=posts # - ELASTIC_APM_SERVER_URL=http://apm:8200 + # user service + user: + restart: unless-stopped + environment: + - NODE_ENV=production + - USER_PORT + # TODO + # - ELASTICSEARCH_HOSTS=http://elasticsearch:9200 + # - ELASTIC_APM_SERVICE_NAME=user + # - ELASTIC_APM_SERVER_URL=http://apm:8200 ############################################################################## # Third-Party Dependencies and Support Services diff --git a/src/api/docker-compose.yml b/src/api/docker-compose.yml deleted file mode 100644 index 4ff2eda0b6..0000000000 --- a/src/api/docker-compose.yml +++ /dev/null @@ -1,108 +0,0 @@ -################################################################################ -# Development docker-compose.yml, not meant for production -################################################################################ -version: '3' - -services: - # API Gateway - traefik: - image: traefik:v2.4.5 - container_name: 'traefik' - command: - # If you need Traefik debug logs, uncomment this - #- '--log.level=DEBUG' - - '--api.insecure=true' - - '--providers.docker=true' - - '--providers.docker.exposedbydefault=false' - - '--entrypoints.web.address=:80' - ports: - - '80:80' - - '8080:8080' - volumes: - - /var/run/docker.sock:/var/run/docker.sock - labels: - - 'traefik.enable=true' - - # image service - image: - container_name: 'image' - build: - context: ./image - dockerfile: Dockerfile - environment: - - IMAGE_PORT - ports: - - '${IMAGE_PORT}' - depends_on: - - traefik - labels: - # Enable Traefik - - 'traefik.enable=true' - # Traefik routing for the image service at /v1/image - - 'traefik.http.routers.image.rule=Host(`${API_HOST}`) && PathPrefix(`/${API_VERSION}/image`)' - # Specify the image service port - - 'traefik.http.services.image.loadbalancer.server.port=${IMAGE_PORT}' - # Add middleware to this route to strip the /v1/image prefix - - 'traefik.http.middlewares.strip_image_prefix.stripprefix.prefixes=/${API_VERSION}/image' - - 'traefik.http.middlewares.strip_image_prefix.stripprefix.forceSlash=true' - - 'traefik.http.routers.image.middlewares=strip_image_prefix' - - # auth service - auth: - container_name: 'auth' - build: - context: ./auth - dockerfile: Dockerfile - environment: - - AUTH_PORT - - SSO_LOGIN_URL - - SSO_LOGIN_CALLBACK_URL - - SLO_LOGOUT_URL - - SLO_LOGOUT_CALLBACK_URL - - SSO_IDP_PUBLIC_KEY_CERT - - SAML_ENTITY_ID - - SECRET - - ADMINISTRATORS - - ALLOWED_APP_ORIGINS - - JWT_ISSUER - - JWT_EXPIRES_IN - ports: - - ${AUTH_PORT} - depends_on: - - traefik - - login - labels: - # Enable Traefik - - 'traefik.enable=true' - # Traefik routing for the auth service at /v1/auth - - 'traefik.http.routers.auth.rule=Host(`${API_HOST}`) && PathPrefix(`/${API_VERSION}/auth`)' - # Specify the auth service port - - 'traefik.http.services.auth.loadbalancer.server.port=${AUTH_PORT}' - # Add middleware to this route to strip the /v1/auth prefix - - 'traefik.http.middlewares.strip_auth_prefix.stripprefix.prefixes=/${API_VERSION}/auth' - - 'traefik.http.middlewares.strip_auth_prefix.stripprefix.forceSlash=true' - - 'traefik.http.routers.auth.middlewares=strip_auth_prefix' - - # user service - user: - container_name: 'user' - build: - context: ./user - dockerfile: Dockerfile - environment: - - USER_PORT - ports: - - ${USER_PORT} - depends_on: - - traefik - labels: - # Enable Traefik - - 'traefik.enable=true' - # Traefik routing for the user service at /v1/user - - 'traefik.http.routers.user.rule=Host(`${API_HOST}`) && PathPrefix(`/${API_VERSION}/user`)' - # Specify the user service port - - 'traefik.http.services.user.loadbalancer.server.port=${USER_PORT}' - # Add middleware to this route to strip the /v1/user prefix - - 'traefik.http.middlewares.strip_user_prefix.stripprefix.prefixes=/${API_VERSION}/user' - - 'traefik.http.middlewares.strip_user_prefix.stripprefix.forceSlash=true' - - 'traefik.http.routers.user.middlewares=strip_user_prefix' diff --git a/src/api/env.development b/src/api/env.development deleted file mode 100644 index c0578b04ba..0000000000 --- a/src/api/env.development +++ /dev/null @@ -1,92 +0,0 @@ -################################################################################ -# Environment Variables for Development -################################################################################ - -COMPOSE_PROJECT_NAME=telescope_api - -# Compose files to use together on production. NOTE: we specify separator below -# so it will work on Windows and Unix, see -# https://docs.docker.com/compose/reference/envvars/#compose_file -COMPOSE_PATH_SEPARATOR=; -COMPOSE_FILE=docker-compose.yml;development.yml - -# The host where all the microservices run (e.g., http://api.telescope.localhost) -# NOTE: if you change this, change all other occurrences below too. -API_HOST=api.telescope.localhost - -# The API Version, used as a prefix on all routes: /v1 -API_VERSION=v1 - - -################################################################################ -# Auth Service -################################################################################ - -# Image Service Port (default is 4444) -AUTH_PORT=7777 - -# Auth Service URL -AUTH_URL=http://api.telescope.localhost/v1/auth - -# The Single Sign On (SSO) login service URL -SSO_LOGIN_URL=http://login.localhost/simplesaml/saml2/idp/SSOService.php - -# The callback URL endpoint to be used by the SSO login service (see the /auth route) -SSO_LOGIN_CALLBACK_URL=http://api.telescope.localhost/v1/auth/login/callback - -# The Single Logout (SLO) service URL -SLO_LOGOUT_URL=http://login.localhost/simplesaml/saml2/idp/SingleLogoutService.php - -# The callback URL endpoint to be used by the SLO logout service (see the /auth route) -SLO_LOGOUT_CALLBACK_URL=http://api.telescope.localhost/v1/auth/logout/callback - -# The SSO Identity Provider's public key certificate. NOTE: this is the public -# key cert of the test login IdP docker container. Update for staging and prod. -SSO_IDP_PUBLIC_KEY_CERT=MIIDXTCCAkWgAwIBAgIJALmVVuDWu4NYMA0GCSqGSIb3DQEBCwUAMEUxCzAJBgNVBAYTAkFVMRMwEQYDVQQIDApTb21lLVN0YXRlMSEwHwYDVQQKDBhJbnRlcm5ldCBXaWRnaXRzIFB0eSBMdGQwHhcNMTYxMjMxMTQzNDQ3WhcNNDgwNjI1MTQzNDQ3WjBFMQswCQYDVQQGEwJBVTETMBEGA1UECAwKU29tZS1TdGF0ZTEhMB8GA1UECgwYSW50ZXJuZXQgV2lkZ2l0cyBQdHkgTHRkMIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAzUCFozgNb1h1M0jzNRSCjhOBnR+uVbVpaWfXYIR+AhWDdEe5ryY+CgavOg8bfLybyzFdehlYdDRgkedEB/GjG8aJw06l0qF4jDOAw0kEygWCu2mcH7XOxRt+YAH3TVHa/Hu1W3WjzkobqqqLQ8gkKWWM27fOgAZ6GieaJBN6VBSMMcPey3HWLBmc+TYJmv1dbaO2jHhKh8pfKw0W12VM8P1PIO8gv4Phu/uuJYieBWKixBEyy0lHjyixYFCR12xdh4CA47q958ZRGnnDUGFVE1QhgRacJCOZ9bd5t9mr8KLaVBYTCJo5ERE8jymab5dPqe5qKfJsCZiqWglbjUo9twIDAQABo1AwTjAdBgNVHQ4EFgQUxpuwcs/CYQOyui+r1G+3KxBNhxkwHwYDVR0jBBgwFoAUxpuwcs/CYQOyui+r1G+3KxBNhxkwDAYDVR0TBAUwAwEB/zANBgkqhkiG9w0BAQsFAAOCAQEAAiWUKs/2x/viNCKi3Y6blEuCtAGhzOOZ9EjrvJ8+COH3Rag3tVBWrcBZ3/uhhPq5gy9lqw4OkvEws99/5jFsX1FJ6MKBgqfuy7yh5s1YfM0ANHYczMmYpZeAcQf2CGAaVfwTTfSlzNLsF2lW/ly7yapFzlYSJLGoVE+OHEu8g5SlNACUEfkXw+5Eghh+KzlIN7R6Q7r2ixWNFBC/jWf7NKUfJyX8qIG5md1YUeT6GBW9Bm2/1/RiO24JTaYlfLdKK9TYb8sG5B+OLab2DImG99CJ25RkAcSobWNF5zD0O6lgOo3cEdB/ksCq3hmtlC/DlLZ/D8CJ+7VuZnS1rR2naQ== - -# Our apps's Entity ID, which is also the URL to our metadata. -SAML_ENTITY_ID=http://api.telescope.localhost/v1/auth/sp - -# SECRET = cookie session SECRET. If left empty, one will be set automatically -SECRET=secret-sauce - -# ADMINISTRATORS is a list (space delimited) of users who have administrator -# rights. Use the user's nameID (user2@example.com) or hashed version of -# nameID (2b3b2b9ce8). Either will work. -ADMINISTRATORS=user1@example.com - -# Origins of web apps that we'll allow for redirects. See src/api/auth/test -ALLOWED_APP_ORIGINS=http://localhost:8000 http://localhost:8888 - -# The URI of the auth server -JWT_ISSUER=http://api.telescope.localhost/v1/auth - -# The microservices origin -JWT_AUDIENCE=http://api.telescope.localhost - -# How long should a JWT work before it expires -JWT_EXPIRES_IN=1h - - -################################################################################ -# Image Service -################################################################################ - -# Image Service Port (default is 4444) -IMAGE_PORT=4444 - -# Image Service URL -IMAGE_URL=http://api.telescope.localhost/v1/image - - -################################################################################ -# User Service -################################################################################ - -# User Service Port (default is 6666) -USER_PORT=6666 - -# Use Firebase Emulator -# The variable must be set to the emulator's ip and port. -# It is used in conjunction with tests. -FIRESTORE_EMULATOR_HOST=localhost:8088 diff --git a/src/api/readme.md b/src/api/readme.md index 93e9f29744..98354a796f 100644 --- a/src/api/readme.md +++ b/src/api/readme.md @@ -41,22 +41,22 @@ npm run services:stop ## API Lookup Table -| API | Docker Tag | URL | Description | -| ----- | ------------------- | ------------------------- | ------------------------------------------------- | -| posts | telescope_posts_svc | http://localhost/v1/posts | Provides access to cached user posts | -| image | telescope_img_svc | http://localhost/v1/image | Provides a dynamic image processing service | -| auth | telescope_auth_svc | http://localhost/v1/auth | Provides authentication and authorization service | +| API | Docker Tag | URL | Description | +| ----- | ------------------- | --------------------------- | ------------------------------------------------- | +| posts | telescope_posts_svc | | Provides access to cached user posts | +| image | telescope_img_svc | | Provides a dynamic image processing service | +| auth | telescope_auth_svc | | Provides authentication and authorization service | ## Support Services Lookup Table (development only) -| API | URL | Description | -| ------------------ | -------------------------------- | ------------------------------------------------------------------------- | -| Traefik Dashboard | http://localhost:8080 | [Traefik Dashboard](https://doc.traefik.io/traefik/operations/dashboard/) | -| Redis | redis://localhost:6379 | Redis server | -| Elasticsearch | http://localhost:9200 | Elasticserach | -| Firebase UI | http://localhost:4000 | UI Dashboard to Firebase Emulator | -| Firebase Firestore | http://localhost:8088 | Firestore Emulator Service | -| Login | http://localhost:8081/simplesaml | SAML SSO Identity Provider | +| API | URL | Description | +| ------------------ | ---------------------------------- | ------------------------------------------------------------------------- | +| Traefik Dashboard | | [Traefik Dashboard](https://doc.traefik.io/traefik/operations/dashboard/) | +| Redis | redis://localhost:6379 | Redis server | +| Elasticsearch | | Elasticserach | +| Firebase UI | | UI Dashboard to Firebase Emulator | +| Firebase Firestore | | Firestore Emulator Service | +| Login | | SAML SSO Identity Provider | ## References diff --git a/src/api/user/README.md b/src/api/user/README.md index 6c976d7cab..cb60b70ff2 100644 --- a/src/api/user/README.md +++ b/src/api/user/README.md @@ -51,19 +51,19 @@ npm run jest:e2e (or npm run jest:e2e src\api\user\test\e2e) npm run dev ``` -By default the server is running on http://localhost:6666/. +By default the server is running on . ### Examples -\- `GET /user/:id` - returns 200 with the user specified by the id, or 404 if a user does not exist. +\- `GET /:id` - returns 200 with the user specified by the id, or 404 if a user does not exist. -\- `GET /users` - returns 200 with all Telescope users in an array, or 404 if the `users` collection is empty. +\- `GET /` - returns 200 with all Telescope users in an array, or 404 if the `users` collection is empty. -\- `POST /user` - returns 201 if a Telescope user was successfully validated and added to the db, or 400 if the user already exists. (_An example of the JSON data to send as the POST body can be found in `api/user/test/user.test.js`_) +\- `POST /` - returns 201 if a Telescope user was successfully validated and added to the db, or 400 if the user already exists. (_An example of the JSON data to send as the POST body can be found in `api/user/test/user.test.js`_) -\- `PUT /user/:id` - returns 200 if a Telescope user's data was successfully updated, or 400 if the user could not be found in the db. (_An example of the JSON data to send as the POST body can be found in `api/user/test/user.test.js`_) +\- `PUT /:id` - returns 200 if a Telescope user's data was successfully updated, or 400 if the user could not be found in the db. (_An example of the JSON data to send as the POST body can be found in `api/user/test/user.test.js`_) -\- `DELETE /user/:id` - returns 200 when the user is deleted, or 404 if a user to delete could not be found. +\- `DELETE /:id` - returns 200 when the user is deleted, or 404 if a user to delete could not be found. ## Docker (section currently incomplete) diff --git a/src/api/user/src/models/user.js b/src/api/user/src/models/user.js index b9ce27ab6d..c78c5ecbb4 100644 --- a/src/api/user/src/models/user.js +++ b/src/api/user/src/models/user.js @@ -5,9 +5,7 @@ class User { this.id = data.id; this.firstName = data.firstName; this.lastName = data.lastName; - this.displayName = !data.displayName - ? `${this.firstName}${' '}${this.lastName}` - : data.displayName; + this.displayName = data.displayName || `${this.firstName}${' '}${this.lastName}`; this.isAdmin = data.isAdmin; this.isFlagged = data.isFlagged; this.feeds = data.feeds; diff --git a/src/api/user/src/routes/user.js b/src/api/user/src/routes/user.js index cf66b8de85..a763386f54 100644 --- a/src/api/user/src/routes/user.js +++ b/src/api/user/src/routes/user.js @@ -89,7 +89,7 @@ router.put('/:id', validateUser(), async (req, res, next) => { if (!doc.exists) { logger.debug(`User data (id: ${doc.id}) was requested by ${req.ip} but could not be found.`); - res.status(400).json({ + res.status(404).json({ msg: `User with id ${doc.id} was requested to be updated, but does not exist in the db.`, }); } else { From dbe714b99297048747f9aa61b602bc152617dbb9 Mon Sep 17 00:00:00 2001 From: Abdulbasid Guled Date: Wed, 17 Mar 2021 21:08:00 -0400 Subject: [PATCH 2/2] Updated tags in env prod and stag --- config/env.production | 26 ++++++++++++++++---------- config/env.staging | 27 ++++++++++++++++----------- 2 files changed, 32 insertions(+), 21 deletions(-) diff --git a/config/env.production b/config/env.production index bab06d4b6a..df2690410a 100644 --- a/config/env.production +++ b/config/env.production @@ -118,16 +118,22 @@ MOCK_REDIS= # Firebase's private api key. Used to authenticate telescope with firebase # See https://firebase.google.com/docs/admin/setup#initialize-sdk to obtain the key -TYPE= -PROJECT_ID= -PRIVATE_KEY_ID= -PRIVATE_KEY= -CLIENT_EMAIL= -CLIENT_ID= -AUTH_URI= -TOKEN_URI= -AUTH_PROVIDER_X509_CERT_URL= -CLIENT_X509_CERT_URL= +FIREBASE_TYPE= +FIREBASE_PROJECT_ID= +FIREBASE_PRIVATE_KEY_ID= +FIREBASE_PRIVATE_KEY= +FIREBASE_CLIENT_EMAIL= +FIREBASE_CLIENT_ID= +FIREBASE_AUTH_URI= +FIREBASE_TOKEN_URI= +FIREBASE_AUTH_PROVIDER_X509_CERT_URL= +FIREBASE_CLIENT_X509_CERT_URL= + +# User Service Port (default is 6666) +USER_PORT=6666 + +# User Service URL +USER_URL=http://api.telescope.cdot.systems/v1/user ################################################################################ diff --git a/config/env.staging b/config/env.staging index 4c59c72419..e9c52a3ccc 100644 --- a/config/env.staging +++ b/config/env.staging @@ -120,17 +120,22 @@ MOCK_REDIS= # Firebase's private api key. Used to authenticate telescope with firebase # See https://firebase.google.com/docs/admin/setup#initialize-sdk to obtain the key -TYPE= -PROJECT_ID= -PRIVATE_KEY_ID= -PRIVATE_KEY= -CLIENT_EMAIL= -CLIENT_ID= -AUTH_URI= -TOKEN_URI= -AUTH_PROVIDER_X509_CERT_URL= -CLIENT_X509_CERT_URL= - +FIREBASE_TYPE= +FIREBASE_PROJECT_ID= +FIREBASE_PRIVATE_KEY_ID= +FIREBASE_PRIVATE_KEY= +FIREBASE_CLIENT_EMAIL= +FIREBASE_CLIENT_ID= +FIREBASE_AUTH_URI= +FIREBASE_TOKEN_URI= +FIREBASE_AUTH_PROVIDER_X509_CERT_URL= +FIREBASE_CLIENT_X509_CERT_URL= + +# User Service Port (Default is 6666) +USER_PORT=6666 + +# User Service URL +USER_URL=https://dev.api.telescope.cdot.systems/v1/user ################################################################################ # Feed Discovery Service