| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102 |
- package client
- import (
- "context"
- "fmt"
- "github.com/porter-dev/porter/api/types"
- )
- // AuthCheck performs a check to ensure that the user is logged in
- func (c *Client) AuthCheck(ctx context.Context) (*types.GetAuthenticatedUserResponse, error) {
- resp := &types.GetAuthenticatedUserResponse{}
- err := c.getRequest(
- fmt.Sprintf(
- "/users/current",
- ),
- nil,
- resp,
- )
- return resp, err
- }
- // Login authorizes the user and grants them a cookie-based session
- func (c *Client) Login(ctx context.Context, req *types.LoginUserRequest) (*types.GetAuthenticatedUserResponse, error) {
- resp := &types.GetAuthenticatedUserResponse{}
- err := c.postRequest(
- fmt.Sprintf(
- "/login",
- ),
- req,
- resp,
- )
- return resp, err
- }
- // Logout logs the user out and deauthorizes the cookie-based session
- func (c *Client) Logout(ctx context.Context) error {
- err := c.postRequest(
- fmt.Sprintf(
- "/logout",
- ),
- nil,
- nil,
- )
- if err != nil {
- return err
- }
- // remove the cookie, if it exists
- return c.deleteCookie()
- }
- // CreateUser will create the user, authorize the user and grant them a cookie-based session
- func (c *Client) CreateUser(
- ctx context.Context,
- req *types.CreateUserRequest,
- ) (*types.CreateUserResponse, error) {
- resp := &types.CreateUserResponse{}
- err := c.postRequest(
- fmt.Sprintf(
- "/users",
- ),
- req,
- resp,
- )
- return resp, err
- }
- // ListUserProjects returns a list of projects associated with a user
- func (c *Client) ListUserProjects(ctx context.Context) (*types.ListUserProjectsResponse, error) {
- resp := &types.ListUserProjectsResponse{}
- err := c.getRequest(
- fmt.Sprintf(
- "/projects",
- ),
- nil,
- resp,
- )
- return resp, err
- }
- // DeleteUser deletes the current user
- func (c *Client) DeleteUser(
- ctx context.Context,
- ) error {
- return c.deleteRequest(
- fmt.Sprintf(
- "/users/current",
- ),
- nil,
- nil,
- )
- }
|