[cli] Add API to get authenticator data

This commit is contained in:
Neeraj Gupta 2024-09-18 16:06:45 +05:30
parent 6b831378ba
commit cda7dda3cb
2 changed files with 57 additions and 0 deletions

View File

@ -0,0 +1,41 @@
package api
import (
"context"
"github.com/ente-io/cli/internal/api/models"
"strconv"
)
func (c *Client) GetAuthKey(ctx context.Context) (*models.AuthKey, error) {
var res models.AuthKey
r, err := c.restClient.R().
SetContext(ctx).
SetResult(&res).
Get("/authenticator/key")
if r.IsError() {
return nil, &ApiError{
StatusCode: r.StatusCode(),
Message: r.String(),
}
}
return &res, err
}
func (c *Client) GetDiff(ctx context.Context, sinceTime int64, limit int64) ([]models.AuthEntity, error) {
var res struct {
Diff []models.AuthEntity `json:"diff"`
}
r, err := c.restClient.R().
SetContext(ctx).
SetQueryParam("sinceTime", strconv.FormatInt(sinceTime, 10)).
SetQueryParam("limit", strconv.FormatInt(limit, 10)).
SetResult(&res).
Get("/authenticator/entity/diff")
if r.IsError() {
return nil, &ApiError{
StatusCode: r.StatusCode(),
Message: r.String(),
}
}
return res.Diff, err
}

View File

@ -0,0 +1,16 @@
package models
type AuthKey struct {
UserID int64 `json:"userID" binding:"required"`
EncryptedKey string `json:"encryptedKey" binding:"required"`
Header string `json:"header" binding:"required"`
}
type AuthEntity struct {
ID string `json:"id" binding:"required"`
EncryptedKey *string `json:"encryptedKey"`
Header *string `json:"header"`
IsDeleted bool `json:"isDeleted" binding:"required"`
CreatedAt int64 `json:"createdAt" binding:"required"`
UpdatedAt int64 `json:"updatedAt" binding:"required"`
}