-
Notifications
You must be signed in to change notification settings - Fork 505
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: create some routes with rpc naming (#332)
* feat: create some routes with rpc naming * fix(workflow.json): change HTTP method from POST to GET for "Get Key" step * fix(workflow.json): change "params" to "json" for consistency and clarity * chore(deploy-agent.yaml): add MySQL service for testing feat(deploy-agent.yaml): add DATABASE_DSN environment variable for testing * chore(workflow.json): update step name from "Verify Key" to "Verify key again after removal" fix(workflow.json): update expected value of jsonpath "$.valid" to false * chore(workflow.json): remove unnecessary step for verifying key again after removal * chore(workflow.json): add newline at the end of the file
- Loading branch information
Showing
15 changed files
with
325 additions
and
65 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,80 @@ | ||
package server | ||
|
||
import ( | ||
"fmt" | ||
|
||
"github.com/gofiber/fiber/v2" | ||
"github.com/unkeyed/unkey/apps/agent/pkg/cache" | ||
"github.com/unkeyed/unkey/apps/agent/pkg/errors" | ||
) | ||
|
||
type GetKeyRequestV1 struct { | ||
KeyId string `validate:"required"` | ||
} | ||
|
||
type GetKeyResponseV1 = keyResponse | ||
|
||
func (s *Server) v1FindKey(c *fiber.Ctx) error { | ||
ctx, span := s.tracer.Start(c.UserContext(), "server.v1FindKey") | ||
defer span.End() | ||
req := GetKeyRequest{ | ||
KeyId: c.Query("keyId"), | ||
} | ||
|
||
err := s.validator.Struct(req) | ||
if err != nil { | ||
return errors.NewHttpError(c, errors.BAD_REQUEST, err.Error()) | ||
} | ||
|
||
authorizedWorkspaceId, err := s.authorizeRootKey(ctx, c) | ||
if err != nil { | ||
return errors.NewHttpError(c, errors.UNAUTHORIZED, err.Error()) | ||
} | ||
|
||
key, found, err := cache.WithCache(s.keyCache, s.db.FindKeyById)(ctx, req.KeyId) | ||
if err != nil { | ||
return errors.NewHttpError(c, errors.INTERNAL_SERVER_ERROR, err.Error()) | ||
} | ||
if !found { | ||
return errors.NewHttpError(c, errors.NOT_FOUND, fmt.Sprintf("key %s not found", req.KeyId)) | ||
} | ||
if key.WorkspaceId != authorizedWorkspaceId { | ||
return errors.NewHttpError(c, errors.UNAUTHORIZED, "workspace access denied") | ||
} | ||
api, found, err := cache.WithCache(s.apiCache, s.db.FindApiByKeyAuthId)(ctx, key.KeyAuthId) | ||
if err != nil { | ||
return errors.NewHttpError(c, errors.INTERNAL_SERVER_ERROR, fmt.Sprintf("unable to find api: %s", err.Error())) | ||
} | ||
if !found { | ||
|
||
return errors.NewHttpError(c, errors.NOT_FOUND, fmt.Sprintf("unable to find api: %s", err.Error())) | ||
} | ||
|
||
res := GetKeyResponse{ | ||
Id: key.Id, | ||
ApiId: api.Id, | ||
WorkspaceId: key.WorkspaceId, | ||
Name: key.Name, | ||
Start: key.Start, | ||
OwnerId: key.OwnerId, | ||
Meta: key.Meta, | ||
CreatedAt: key.CreatedAt.UnixMilli(), | ||
ForWorkspaceId: key.ForWorkspaceId, | ||
} | ||
if !key.Expires.IsZero() { | ||
res.Expires = key.Expires.UnixMilli() | ||
} | ||
if key.Ratelimit != nil { | ||
res.Ratelimit = &ratelimitSettng{ | ||
Type: key.Ratelimit.Type, | ||
Limit: key.Ratelimit.Limit, | ||
RefillRate: key.Ratelimit.RefillRate, | ||
RefillInterval: key.Ratelimit.RefillInterval, | ||
} | ||
} | ||
if key.Remaining != nil { | ||
res.Remaining = key.Remaining | ||
} | ||
|
||
return c.JSON(res) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
5eb0657
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Successfully deployed to the following URLs:
unkey – ./
unkey-unkey.vercel.app
unkey.vercel.app
unkey-git-main-unkey.vercel.app
unkey.dev
www.unkey.dev