Coder Social home page Coder Social logo

hn275 / envhub Goto Github PK

View Code? Open in Web Editor NEW
0.0 0.0 1.0 874 KB

Home Page: https://envhub-rosy.vercel.app

License: GNU General Public License v3.0

JavaScript 1.15% CSS 0.38% TypeScript 9.91% HTML 0.31% Go 51.45% Dockerfile 0.23% Shell 1.57% Svelte 35.00%

envhub's People

Contributors

hn275 avatar malcolmseyd avatar scott-kenning avatar

Watchers

 avatar

Forkers

scott-kenning

envhub's Issues

[API] link a repo

  • handles a POST request.
  • handles it at /repos/link?id=123
    • id is a repo id that can be used to request from github.
  • writes to database, only if the user is the owner (schemas defined here)
  • returns 201 on success, or forward github response code otherwise.
  • no response body

[WEB] home page get started section

I've built out the hero section, but the feature section will still need to be developed.
Here is the figma.

Color palette have been configured in the Tailwind config file (./web/tailwind.config.js)

The page is in ./web/src/pages/home/index.tsx

unlink repository

Unlink repositories

Make an api call to github API to see if the user owns the repository or not, then delete it from the database if they are. I'm using Github ID's for both user and repository. The variables column has the constraint to be deleted as well so no worries about cleaning up in that table.

Requirements

  • I'm making an api calls to /repos/{repo-id}/delete with a header entry for "Authorization" and cookie, but I have code to manage this data extraction, see below.

  • On success it should return a 204 with no response body on success. Otherwise a json
    {"message":"some error"}, with the appropriate status code.

    • NOTE: The codebase uses the constants defined in the http package (ie: http.StatusNoContent). In the interest of consistency, please use it as well, this will be the only micro-managing I do lol.

Getting started

  1. Request API

    1.1. Response: To handle the communication to the frontend, they also provide some utilities for error handling.

    1.2. RequestCtx: To extract some useful information from the user. Note that this only works if you're are calling it from a handler that has the TokenValidator middleware applied to it. Otherwise it returns an error, (which you may ignore, but leave a note indicating that it is being used in the appropriate route, I just find that it's less keystrokes for me to handle it since.. hotkeys...).

  2. Github API

  • Since the route is likely going to have the (mentioned) middleware, you'd have access to the user token that you would need to make an api call, this endpointis a good example on how to use this api and the Response struct.
  1. Auth flow:

Could I have used an auth service? Maybe. But I wanted to learn how to implement this from scratch.

  • On user login, I'm rewriting to the database the user information, along with a refresh token, this is purely to update and sync the user information with GitHub, (nothing telemetry-like, I have more features in mind to utilize these information for the next version, if the app lasts).

  • User then receives an httpOnly cookie that has the refresh token. This is only used to refresh the JWT, the access token is then ciphered and is contained within this JWT that exipires in 24h. These Github access token supposedly lasts for an entire year or after the first write request.

    • Once a session, the user will make and api call to refresh the token for a day.
  • On sign out, the token in database is deleted, and the cookie will be invalidated. One issue is that we have no way to invalidate a JWT though...

  • The middleware TokenValidator is applied to almost all of the routes, it validates the state of authorization and extract the needed access token for Github API call.

[API] delete a variable

I've made a middleware to check for write access, this middleware should be applied for this endpoint as well.

This handler deletes a variable based on the request context being passed down by the middleware, take a look at the endpoint that creates a new variable (~ line 22, rCtx).

No need to write test, I'll deal with that part. but you are expected to have the db function as an interface (see here.) This is so I can mock the testing bit of the db (test for the sql query will be written as well.)

NOTE:

  • I have a very general way of handling responses, is done via the response
api.NewResponse(w)...
  • router is setup in server/handlers/router.go, I'm making an api call from the front-end to repo/{repoID}/variables/{variableID}, for both delete and update http methods. make sure to allow these when you are doing a request method check.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.