Skip to content
This repository was archived by the owner on Feb 8, 2024. It is now read-only.

[DB Access 3] Define route, endpoint, and service #271

Closed
6 tasks done
kimlisa opened this issue Apr 21, 2021 · 0 comments · Fixed by #288
Closed
6 tasks done

[DB Access 3] Define route, endpoint, and service #271

kimlisa opened this issue Apr 21, 2021 · 0 comments · Fixed by #288
Assignees

Comments

@kimlisa
Copy link
Contributor

kimlisa commented Apr 21, 2021

Define route, api endpoint, and service

In config.ts:

  • Define a database route and api endpoint and its getters. Since database viewing is cluster specific, remember to pass in the clusterId to this route and endpoint.

services/database/ is a directory that contains all logic for retrieving/processing/typing response values from api:

  • Create a database class that will define a fetch method to get a list of all database servers for the specified clusterId.
  • The response value from the fetch method (or any api responses really) will need to be processed. The convention is to create a separate file named make.ts, and it will contain methods named makeXXX that will be responsible for processing the responses we get from api. There are variety of reasons why we want to process the response values:
    1. Arrays may come as undefined and needs to be replaced with an empty array to avoid accessing undefined props errors.
    2. Setting default values to objects if undefined
    3. Sometimes json response contains field names containing underscore ie. expires_in. JS conventions dictates we use camelCase, so we can rename this field to expiresIn: json.expires_in
    4. Sometimes with the response given, we want to add an extra field. For example, if the response value contained a field date: Date, and we wanted a formatted string version of this date, we can add a field dateText: stringValue (while keeping the original data). These text values often helps with table searching.
    5. Sometimes we want to reformat the response value
    6. All of the above helps create consistent responses sent to our components
  • Instantiate this class in our teleportContext.tsx file, so that children components can have access to it.
  • Test the class you made, to ensure the response received from api, is processed and formatted as you expected.

Table Cell formatting

  • Format the database columns protocol and type cells to the following:

Protocol Formatting

postgres -> PostgreSQL
mysql -> MySQL

Type Formatting

self-hosted -> Self-hosted
rds -> RDS
gcp -> GCP
redshift -> Redshift

Mocked response

This is what response data would look like from the api

[
 {
    name: 'aurora',
    desc: 'PostgreSQL 11.6: AWS Aurora ',
    protocol: 'postgres',
    type: 'rds',
    uri: 'postgres-aurora-instance-1.c1xpjrob56xs.us-west-1.rds.amazonaws.com:5432',
    labels: [
      { name: 'cluster', value: 'root' },
      { name: 'env', value: 'aws' },
    ],
  },
]

This is what data should look like after being processed:

[
 {
    name: 'aurora',
    desc: 'PostgreSQL 11.6: AWS Aurora ',
    protocol: 'postgres',
    type: 'rds',
    uri: 'postgres-aurora-instance-1.c1xpjrob56xs.us-west-1.rds.amazonaws.com:5432',
    labels: [ 'cluster: root', 'env: aws' ],
  },
]

Note

We won't be using this service until the next issue.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants