Skip to content
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

Feature: Add API #58

Merged
merged 38 commits into from
Nov 15, 2020
Merged

Feature: Add API #58

merged 38 commits into from
Nov 15, 2020

Conversation

connorads
Copy link
Owner

@connorads connorads commented Aug 16, 2020

Closes #43

To generate a new access token for the Lockbot API use /lbtoken new

The API offers the following functionality:

  • Fetch all locks 📜
  • Fetch one lock 👀
  • Create lock 🔒
  • Delete lock 🔓

TODO

  • Update REAMDE.md

@connorads connorads added the enhancement New feature or request label Aug 16, 2020
@ghost
Copy link

ghost commented Aug 16, 2020

DeepCode's analysis on #a44faf found:

  • ℹ️ 1 minor issue. 👇

Top issues

Description Example fixes
Extract the port number hardcoded in "http://localhost:3000" to a variable. Occurrences: 🔧 Example fixes

👉 View analysis in DeepCode’s Dashboard | Configure the bot

@coveralls
Copy link

coveralls commented Aug 16, 2020

Coverage Status

Coverage increased (+0.4%) to 99.338% when pulling a44faf6 on add-api into bbb462e on master.

const lockOwner = await lockRepo.getOwner(lockName, channel, team);
if (!lockOwner) {
console.log("No lock to delete", { lockName });
res.status(204).end();
Copy link

@frshwtr frshwtr Sep 8, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would returning a 410 Gone error work here instead of 204?

Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice spot 🧐

410 is an interesting one, I've never used it! It might not be quite accurate all the time because can something be Gone if it was never there in the first place? Or only Gone if it was previously locked?

This was one where I wasn't quite sure what to return and opted for a 2XX/success code over 4XX because I assumed that clients wouldn't care (or want an error) for when they're trying to delete a lock and there isn't one. But my assumption might be very wrong.

@@ -0,0 +1,204 @@
import awsServerlessExpress from "aws-serverless-express";
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not too familiar with serverless express but it sounds interesting, what does it give that plain serverless does not?

Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not too familiar with it either 😁

The short answer is that I don't think Express gives you anything particularly special over standard AWS Lambda/Serverless.

aws-serverless-express is just an easy way to get Express to work with AWS lambda.

It means if you're used to writing apps using Express you can continue doing so. For example by creating and using Express middleware like authorizer.

The only reason I chose to use Express was because Bolt, the Slack library I'm using in the other handler in this project, also uses Express so I thought I'd use it for consistency.

There's other newer Node web frameworks on the block like Koa and Fastify but I've only really dabbled in AWS Lambda and Express thus far ...

@frshwtr
Copy link

frshwtr commented Sep 9, 2020

This is looking great, thanks Connor!

I think our use for this would be to block deployments to our dev environments when someone is using it. With the API, we should be able to add a check to our CI pipelines to block our dev deployments should it be locked. I'm not sure how much demand we have in our team for such blocking feature at the moment as we haven't had much need to use dev presently, but I would love to see if the rest of the team would like to trial it on one of our repositories.

One thing that would be nice to have would be expiring locks. It looks like a lock will exist until they unlock it themselves. An option to set an expiry on a lock may be nice to make sure someone doesn't block a resource longer than needed.

@connorads
Copy link
Owner Author

Thanks for the feedback @frshwtr

Expiring locks is a good shout.
I've wanted to add it for a while but didn't think of a nice way of implementing it.
Just jotted some notes in a comment on #7, if you have any thoughts lemme know!

package.json Outdated Show resolved Hide resolved
@connorads
Copy link
Owner Author

Fixes #60

@connorads connorads marked this pull request as ready for review November 8, 2020 23:27
@sonarqubecloud
Copy link

sonarqubecloud bot commented Nov 9, 2020

SonarCloud Quality Gate failed.

Bug A 0 Bugs
Vulnerability A 0 Vulnerabilities (and Security Hotspot 0 Security Hotspots to review)
Code Smell A 2 Code Smells

No Coverage information No Coverage information
4.4% 4.4% Duplication

@connorads connorads merged commit 33b6a08 into master Nov 15, 2020
@connorads connorads deleted the add-api branch November 15, 2020 19:10
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Suggestion: Add a way to update lockbot via an API
3 participants