Skip to content

Commit

Permalink
WIP
Browse files Browse the repository at this point in the history
Signed-off-by: jay-dee7 <me@jsdp.dev>
  • Loading branch information
jay-dee7 committed Nov 8, 2023
1 parent d4f6624 commit a5f74e8
Show file tree
Hide file tree
Showing 20 changed files with 272 additions and 182 deletions.
1 change: 1 addition & 0 deletions auth/github.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import (

func (a *auth) LoginWithGithub(ctx echo.Context) error {
ctx.Set(types.HandlerStartTime, time.Now())

state, err := uuid.NewRandom()
if err != nil {
echoErr := ctx.JSON(http.StatusBadRequest, echo.Map{
Expand Down
4 changes: 4 additions & 0 deletions auth/invites.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,9 @@ import (
"net/http"
"regexp"
"strings"
"time"

"github.com/containerish/OpenRegistry/types"
"github.com/labstack/echo/v4"
)

Expand All @@ -15,6 +17,8 @@ type List struct {
}

func (a *auth) Invites(ctx echo.Context) error {
ctx.Set(types.HandlerStartTime, time.Now())

var list List
err := json.NewDecoder(ctx.Request().Body).Decode(&list)
if err != nil {
Expand Down
4 changes: 3 additions & 1 deletion auth/jwt_middleware.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ const (
func (a *auth) JWT() echo.MiddlewareFunc {
return echo_jwt.WithConfig(echo_jwt.Config{
Skipper: func(ctx echo.Context) bool {
ctx.Set(types.HandlerStartTime, time.Now())

if strings.HasPrefix(ctx.Request().RequestURI, "/auth") {
return false
}
Expand All @@ -46,7 +48,6 @@ func (a *auth) JWT() echo.MiddlewareFunc {
return true
},
ErrorHandler: func(ctx echo.Context, err error) error {
ctx.Set(types.HandlerStartTime, time.Now())
echoErr := ctx.JSON(http.StatusUnauthorized, echo.Map{
"error": err.Error(),
"message": "missing authentication information",
Expand Down Expand Up @@ -131,6 +132,7 @@ func (a *auth) JWTRest() echo.MiddlewareFunc {
return echo_jwt.WithConfig(echo_jwt.Config{
ErrorHandler: func(ctx echo.Context, err error) error {
ctx.Set(types.HandlerStartTime, time.Now())

echoErr := ctx.JSON(http.StatusUnauthorized, echo.Map{
"error": err.Error(),
"message": "missing authentication information",
Expand Down
7 changes: 7 additions & 0 deletions auth/reset_password.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"errors"
"fmt"
"net/http"
"time"

"github.com/containerish/OpenRegistry/services/email"
v2_types "github.com/containerish/OpenRegistry/store/v2/types"
Expand All @@ -16,6 +17,8 @@ import (
)

func (a *auth) ResetForgottenPassword(ctx echo.Context) error {
ctx.Set(types.HandlerStartTime, time.Now())

token, ok := ctx.Get("user").(*jwt.Token)
if !ok {
err := fmt.Errorf("ERR_EMPTY_TOKEN")
Expand Down Expand Up @@ -108,6 +111,8 @@ and an uppercase letter`,
}

func (a *auth) ResetPassword(ctx echo.Context) error {
ctx.Set(types.HandlerStartTime, time.Now())

token, ok := ctx.Get("user").(*jwt.Token)
if !ok {
err := fmt.Errorf("ERR_EMPTY_TOKEN")
Expand Down Expand Up @@ -212,6 +217,8 @@ and an uppercase letter`,
}

func (a *auth) ForgotPassword(ctx echo.Context) error {
ctx.Set(types.HandlerStartTime, time.Now())

userEmail := ctx.QueryParam("email")
if err := a.verifyEmail(userEmail); err != nil {
echoErr := ctx.JSON(http.StatusBadRequest, echo.Map{
Expand Down
5 changes: 5 additions & 0 deletions auth/server/webauthn_server.go
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,7 @@ func (wa *webauthn_server) webAuthNTxnCleanup() {

func (wa *webauthn_server) BeginRegistration(ctx echo.Context) error {
ctx.Set(types.HandlerStartTime, time.Now())

user := v2_types.User{}

if err := json.NewDecoder(ctx.Request().Body).Decode(&user); err != nil {
Expand Down Expand Up @@ -195,6 +196,8 @@ func (wa *webauthn_server) BeginRegistration(ctx echo.Context) error {
}

func (wa *webauthn_server) RollbackRegistration(ctx echo.Context) error {
ctx.Set(types.HandlerStartTime, time.Now())

username := ctx.QueryParam("username")
meta, ok := wa.txnStore[username]
if !ok {
Expand Down Expand Up @@ -226,6 +229,8 @@ func (wa *webauthn_server) RollbackRegistration(ctx echo.Context) error {
}

func (wa *webauthn_server) RollbackSessionData(ctx echo.Context) error {
ctx.Set(types.HandlerStartTime, time.Now())

username := ctx.QueryParam("username")
if username == "" {
return ctx.JSON(http.StatusBadRequest, echo.Map{
Expand Down
1 change: 0 additions & 1 deletion auth/sessions.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ import (
)

func (a *auth) ExpireSessions(ctx echo.Context) error {
//queryParamSessionId := ctx.QueryParam("session_id")
ctx.Set(types.HandlerStartTime, time.Now())

sessionCookie, err := ctx.Cookie("session_id")
Expand Down
16 changes: 9 additions & 7 deletions cmd/extras/digest.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import (
"strings"

"github.com/fatih/color"
"github.com/opencontainers/go-digest"
oci_digest "github.com/opencontainers/go-digest"
"github.com/urfave/cli/v2"
)

Expand Down Expand Up @@ -45,21 +45,23 @@ func generateDigest(ctx *cli.Context) error {
digestType = "CANONICAL"
}

manifestContent, err := json.MarshalIndent(input, "", "\t")
// inputBz := bytes.TrimSpace([]byte(input))

manifestContent, err := json.Marshal([]byte(input))
if err != nil {
return fmt.Errorf(color.RedString("generateDigest: ERR_MARSHAL_INDENT: %s", err))
}

var inputDigest digest.Digest
var inputDigest oci_digest.Digest
switch digestType {
case "SHA256":
inputDigest = digest.SHA256.FromBytes(manifestContent)
inputDigest = oci_digest.SHA256.FromBytes(manifestContent)
case "SHA512":
inputDigest = digest.SHA512.FromBytes(manifestContent)
inputDigest = oci_digest.SHA512.FromBytes(manifestContent)
default:
inputDigest = digest.Canonical.FromBytes(manifestContent)
inputDigest = oci_digest.Canonical.FromBytes(manifestContent)
}

color.Green("%s", inputDigest)
color.Green("input=\n%s\ndigest=%s", manifestContent, inputDigest)
return nil
}
1 change: 0 additions & 1 deletion conformance.vars
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,3 @@ OCI_PASSWORD=Qwerty@123
OCI_ROOT_URL=http://localhost:5000
OCI_NAMESPACE=johndoe/dummmy-server
OCI_CROSSMOUNT_NAMESPACE=johndoe/dummmy-server-cross-mount
OCI_DELETE_MANIFEST_BEFORE_BLOBS=0
6 changes: 3 additions & 3 deletions dfs/filebase/filebase.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import (
"github.com/containerish/OpenRegistry/config"
"github.com/containerish/OpenRegistry/dfs"
"github.com/containerish/OpenRegistry/store/v2/types"
"github.com/opencontainers/go-digest"
oci_digest "github.com/opencontainers/go-digest"
)

type filebase struct {
Expand Down Expand Up @@ -119,7 +119,7 @@ func (fb *filebase) CompleteMultipartUpload(
ctx, cancel := context.WithTimeout(ctx, time.Minute*5)
defer cancel()

dig, err := digest.Parse(layerDigest)
digest, err := oci_digest.Parse(layerDigest)
if err != nil {
return "", fmt.Errorf("ERR_FILEBASE_DIGEST_PARSE: %w", err)
}
Expand All @@ -128,7 +128,7 @@ func (fb *filebase) CompleteMultipartUpload(
Key: &layerKey,
Bucket: &fb.bucket,
UploadId: &uploadId,
ChecksumSHA256: aws.String(dig.Encoded()),
ChecksumSHA256: aws.String(digest.Encoded()),
MultipartUpload: &s3types.CompletedMultipartUpload{Parts: completedParts},
})
if err != nil {
Expand Down
6 changes: 3 additions & 3 deletions dfs/storj/storj.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import (
"github.com/containerish/OpenRegistry/config"
"github.com/containerish/OpenRegistry/dfs"
"github.com/containerish/OpenRegistry/store/v2/types"
"github.com/opencontainers/go-digest"
oci_digest "github.com/opencontainers/go-digest"
)

type storj struct {
Expand Down Expand Up @@ -103,7 +103,7 @@ func (sj *storj) CompleteMultipartUpload(
ctx, cancel := context.WithTimeout(ctx, time.Minute*5)
defer cancel()

dig, err := digest.Parse(layerDigest)
digest, err := oci_digest.Parse(layerDigest)
if err != nil {
return "", fmt.Errorf("ERR_STORJ_DIGEST_PARSE: %w", err)
}
Expand All @@ -112,7 +112,7 @@ func (sj *storj) CompleteMultipartUpload(
Key: &layerKey,
Bucket: &sj.bucket,
UploadId: &uploadId,
ChecksumSHA256: aws.String(dig.Encoded()),
ChecksumSHA256: aws.String(digest.Encoded()),
MultipartUpload: &s3types.CompletedMultipartUpload{Parts: completedParts},
})
if err != nil {
Expand Down
1 change: 1 addition & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ require (
golang.org/x/oauth2 v0.13.0
gopkg.in/yaml.v2 v2.4.0
storj.io/uplink v1.12.1
github.com/opencontainers/image-spec v1.1.0-rc5
)

require (
Expand Down
4 changes: 4 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -412,6 +412,10 @@ github.com/opencontainers/distribution-spec v1.0.1 h1:hT6tF6uKZAQh+HH3BrJqn7/xHh
github.com/opencontainers/distribution-spec v1.0.1/go.mod h1:copR2flp+jTEvQIFMb6MIx45OkrxzqyjszPDT3hx/5Q=
github.com/opencontainers/go-digest v1.0.0 h1:apOUWs51W5PlhuyGyz9FCeeBIOUDA/6nW8Oi/yOhh5U=
github.com/opencontainers/go-digest v1.0.0/go.mod h1:0JzlMkj0TRzQZfJkVvzbP0HBR3IKzErnv2BNG4W4MAM=
github.com/opencontainers/image-spec v1.0.2 h1:9yCKha/T5XdGtO0q9Q9a6T5NUCsTn/DrBg0D7ufOcFM=
github.com/opencontainers/image-spec v1.0.2/go.mod h1:BtxoFyWECRxE4U/7sNtV5W15zMzWCbyJoFRP3s7yZA0=
github.com/opencontainers/image-spec v1.1.0-rc5 h1:Ygwkfw9bpDvs+c9E34SdgGOj41dX/cbdlwvlWt0pnFI=
github.com/opencontainers/image-spec v1.1.0-rc5/go.mod h1:X4pATf0uXsnn3g5aiGIsVnJBR4mxhKzfwmvK/B2NTm8=
github.com/pelletier/go-toml/v2 v2.1.0 h1:FnwAJ4oYMvbT/34k9zzHuZNrhlz48GB3/s6at6/MHO4=
github.com/pelletier/go-toml/v2 v2.1.0/go.mod h1:tJU2Z3ZkXwnxa4DPO899bsyIoywizdUvyaeZurnPPDc=
github.com/pkg/errors v0.8.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
Expand Down
10 changes: 5 additions & 5 deletions registry/v2/blobs.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import (
"github.com/containerish/OpenRegistry/types"
"github.com/fatih/color"
"github.com/labstack/echo/v4"
"github.com/opencontainers/go-digest"
oci_digest "github.com/opencontainers/go-digest"
)

func (b *blobs) errorResponse(code, msg string, detail map[string]interface{}) []byte {
Expand Down Expand Up @@ -103,14 +103,14 @@ func (b *blobs) UploadBlob(ctx echo.Context) error {
}
defer ctx.Request().Body.Close()

checksum := digest.FromBytes(buf.Bytes())
digest := oci_digest.FromBytes(buf.Bytes())

b.blobCounter[uploadID]++
part, err := b.registry.dfs.UploadPart(
ctx.Request().Context(),
uploadID,
GetLayerIdentifier(layerKey),
checksum.String(),
digest.String(),
b.blobCounter[uploadID],
bytes.NewReader(buf.Bytes()),
int64(buf.Len()),
Expand Down Expand Up @@ -171,13 +171,13 @@ func (b *blobs) UploadBlob(ctx echo.Context) error {
}
defer ctx.Request().Body.Close()

checksum := digest.FromBytes(buf.Bytes())
digest := oci_digest.FromBytes(buf.Bytes())
b.blobCounter[uploadID]++
part, err := b.registry.dfs.UploadPart(
ctx.Request().Context(),
uploadID,
GetLayerIdentifier(layerKey),
checksum.String(),
digest.String(),
b.blobCounter[uploadID],
bytes.NewReader(buf.Bytes()),
int64(buf.Len()),
Expand Down
4 changes: 4 additions & 0 deletions registry/v2/extensions/catalog_detail.go
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,8 @@ func (ext *extension) RepositoryDetail(ctx echo.Context) error {
}

func (ext *extension) PublicCatalog(ctx echo.Context) error {
ctx.Set(types.HandlerStartTime, time.Now())

queryParamPageSize := ctx.QueryParam("n")
queryParamOffset := ctx.QueryParam("last")
var pageSize int
Expand Down Expand Up @@ -206,6 +208,8 @@ func (ext *extension) PublicCatalog(ctx echo.Context) error {
}

func (ext *extension) GetUserCatalog(ctx echo.Context) error {
ctx.Set(types.HandlerStartTime, time.Now())

user, ok := ctx.Get(string(types.UserContextKey)).(*types.User)
if !ok {
errMsg := fmt.Errorf("missing user in request context")
Expand Down
Loading

0 comments on commit a5f74e8

Please sign in to comment.