Skip to content

Commit

Permalink
Merge pull request #14 from openfort-xyz/of-515-add-endpoint-to-shiel…
Browse files Browse the repository at this point in the history
…d-to-get-share-encryption-type

feat: add endpoint to get encryption type
  • Loading branch information
gllm-dev authored Sep 16, 2024
2 parents 3024902 + 31ac694 commit 69c15a3
Show file tree
Hide file tree
Showing 5 changed files with 57 additions and 0 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,10 @@ All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## [v0.1.22]
### Added
- Endpoint to get the encryption type of share

## [v0.1.21]
### Fixed
- Register Share encryption validation switch
Expand Down
1 change: 1 addition & 0 deletions internal/adapters/handlers/rest/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@ func (s *Server) Start(ctx context.Context) error {
u := r.PathPrefix("/shares").Subrouter()
u.Use(authMdw.AuthenticateUser)
u.HandleFunc("", shareHdl.GetShare).Methods(http.MethodGet)
u.HandleFunc("/encryption", shareHdl.GetShareEncryption).Methods(http.MethodGet)
u.HandleFunc("", shareHdl.RegisterShare).Methods(http.MethodPost)
u.HandleFunc("", shareHdl.DeleteShare).Methods(http.MethodDelete)
u.HandleFunc("", shareHdl.UpdateShare).Methods(http.MethodPut)
Expand Down
35 changes: 35 additions & 0 deletions internal/adapters/handlers/rest/sharehdl/handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -220,3 +220,38 @@ func (h *Handler) GetShare(w http.ResponseWriter, r *http.Request) {
w.WriteHeader(http.StatusOK)
_, _ = w.Write(resp)
}

// GetShareEncryption gets the encryption of a share
// @Summary Get share encryption
// @Description Get the encryption of a share for the user
// @Tags Share
// @Accept json
// @Produce json
// @Param X-API-Key header string true "API Key"
// @Param Authorization header string true "Bearer token"
// @Param X-Auth-Provider header string true "Auth Provider"
// @Param X-Openfort-Provider header string false "Openfort Provider"
// @Param X-Openfort-Token-Type header string false "Openfort Token Type"
// @Success 200 {object} GetShareEncryptionResponse "Successful response"
// @Failure 404 "Description: Not Found"
// @Failure 500 "Description: Internal Server Error"
// @Router /shares/encryption [get]
func (h *Handler) GetShareEncryption(w http.ResponseWriter, r *http.Request) {
ctx := r.Context()
h.logger.InfoContext(ctx, "getting share")

shr, err := h.app.GetShareEncryption(ctx)
if err != nil {
api.RespondWithError(w, fromApplicationError(err))
return
}

resp, err := json.Marshal(GetShareEncryptionResponse{Entropy: h.parser.mapDomainEntropy[shr]})
if err != nil {
api.RespondWithError(w, api.ErrInternal)
return
}

w.WriteHeader(http.StatusOK)
_, _ = w.Write(resp)
}
4 changes: 4 additions & 0 deletions internal/adapters/handlers/rest/sharehdl/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,3 +26,7 @@ const (
EntropyUser Entropy = "user"
EntropyProject Entropy = "project"
)

type GetShareEncryptionResponse struct {
Entropy Entropy `json:"entropy"`
}
13 changes: 13 additions & 0 deletions internal/applications/shareapp/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,19 @@ func (a *ShareApplication) UpdateShare(ctx context.Context, shr *share.Share, op
return shr, nil
}

func (a *ShareApplication) GetShareEncryption(ctx context.Context) (share.Entropy, error) {
a.logger.InfoContext(ctx, "getting share encryption")
usrID := contexter.GetUserID(ctx)

shr, err := a.shareRepo.GetByUserID(ctx, usrID)
if err != nil {
a.logger.ErrorContext(ctx, "failed to get share by user ID", logger.Error(err))
return 0, fromDomainError(err)
}

return shr.Entropy, nil
}

func (a *ShareApplication) GetShare(ctx context.Context, opts ...Option) (*share.Share, error) {
a.logger.InfoContext(ctx, "getting share")
usrID := contexter.GetUserID(ctx)
Expand Down

0 comments on commit 69c15a3

Please sign in to comment.