Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

✨ Change distribution user get func #356

Merged
merged 1 commit into from
Apr 12, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 12 additions & 5 deletions .github/workflows/e2e.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,19 @@ jobs:
with:
fetch-depth: 0
lfs: true
- name: Install latest Skopeo # GitHub's ubuntu 22 uses Skopeo 1.4 but we need 1.14
- name: Setup golang
uses: actions/setup-go@v5
with:
go-version: "1.22"
- name: Build latest skopeo
run: |
echo 'deb http://download.opensuse.org/repositories/home:/alvistack/xUbuntu_22.04/ /' | sudo tee /etc/apt/sources.list.d/home:alvistack.list
curl -fsSL https://download.opensuse.org/repositories/home:alvistack/xUbuntu_22.04/Release.key | gpg --dearmor | sudo tee /etc/apt/trusted.gpg.d/home_alvistack.gpg > /dev/null
sudo apt update
sudo apt -o Dpkg::Options::="--force-overwrite" install skopeo
git clone --depth 1 --branch v1.15.0 https://github.com/containers/skopeo.git
cd skopeo
DISABLE_CGO=1 make bin/skopeo
sudo cp ./bin/skopeo /usr/bin/skopeo
cd ..
rm -rf skopeo
skopeo --version
- name: Build
run: |
IP=`hostname -I | awk '{print $1}'`
Expand Down
68 changes: 48 additions & 20 deletions .github/workflows/image-build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -49,12 +49,19 @@ jobs:
with:
username: tosone
password: ${{ secrets.DOCKERHUB_PASSWORD }}
- name: Install latest Skopeo # GitHub's ubuntu 22 uses Skopeo 1.4 but we need 1.14
- name: Setup golang
uses: actions/setup-go@v5
with:
go-version: "1.22"
- name: Build latest skopeo
run: |
echo 'deb http://download.opensuse.org/repositories/home:/alvistack/xUbuntu_22.04/ /' | sudo tee /etc/apt/sources.list.d/home:alvistack.list
curl -fsSL https://download.opensuse.org/repositories/home:alvistack/xUbuntu_22.04/Release.key | gpg --dearmor | sudo tee /etc/apt/trusted.gpg.d/home_alvistack.gpg > /dev/null
sudo apt update
sudo apt -o Dpkg::Options::="--force-overwrite" install skopeo
git clone --depth 1 --branch v1.15.0 https://github.com/containers/skopeo.git
cd skopeo
DISABLE_CGO=1 make bin/skopeo
sudo cp ./bin/skopeo /usr/bin/skopeo
cd ..
rm -rf skopeo
skopeo --version
- name: Save dockerfile to local
run: |
make dockerfile-local
Expand Down Expand Up @@ -130,12 +137,19 @@ jobs:
with:
username: tosone
password: ${{ secrets.DOCKERHUB_PASSWORD }}
- name: Install latest Skopeo # GitHub's ubuntu 22 uses Skopeo 1.4 but we need 1.14
- name: Setup golang
uses: actions/setup-go@v5
with:
go-version: "1.22"
- name: Build latest skopeo
run: |
echo 'deb http://download.opensuse.org/repositories/home:/alvistack/xUbuntu_22.04/ /' | sudo tee /etc/apt/sources.list.d/home:alvistack.list
curl -fsSL https://download.opensuse.org/repositories/home:alvistack/xUbuntu_22.04/Release.key | gpg --dearmor | sudo tee /etc/apt/trusted.gpg.d/home_alvistack.gpg > /dev/null
sudo apt update
sudo apt -o Dpkg::Options::="--force-overwrite" install skopeo
git clone --depth 1 --branch v1.15.0 https://github.com/containers/skopeo.git
cd skopeo
DISABLE_CGO=1 make bin/skopeo
sudo cp ./bin/skopeo /usr/bin/skopeo
cd ..
rm -rf skopeo
skopeo --version
- name: Save dockerfile to local
run: |
make dockerfile-local
Expand Down Expand Up @@ -215,12 +229,19 @@ jobs:
with:
username: tosone
password: ${{ secrets.DOCKERHUB_PASSWORD }}
- name: Install latest Skopeo # GitHub's ubuntu 22 uses Skopeo 1.4 but we need 1.14
- name: Setup golang
uses: actions/setup-go@v5
with:
go-version: "1.22"
- name: Build latest skopeo
run: |
echo 'deb http://download.opensuse.org/repositories/home:/alvistack/xUbuntu_22.04/ /' | sudo tee /etc/apt/sources.list.d/home:alvistack.list
curl -fsSL https://download.opensuse.org/repositories/home:alvistack/xUbuntu_22.04/Release.key | gpg --dearmor | sudo tee /etc/apt/trusted.gpg.d/home_alvistack.gpg > /dev/null
sudo apt update
sudo apt -o Dpkg::Options::="--force-overwrite" install skopeo
git clone --depth 1 --branch v1.15.0 https://github.com/containers/skopeo.git
cd skopeo
DISABLE_CGO=1 make bin/skopeo
sudo cp ./bin/skopeo /usr/bin/skopeo
cd ..
rm -rf skopeo
skopeo --version
- name: Save dockerfile to local
run: |
make dockerfile-local
Expand Down Expand Up @@ -298,12 +319,19 @@ jobs:
with:
username: tosone
password: ${{ secrets.DOCKERHUB_PASSWORD }}
- name: Install latest Skopeo # GitHub's ubuntu 22 uses Skopeo 1.4 but we need 1.14
- name: Setup golang
uses: actions/setup-go@v5
with:
go-version: "1.22"
- name: Build latest skopeo
run: |
echo 'deb http://download.opensuse.org/repositories/home:/alvistack/xUbuntu_22.04/ /' | sudo tee /etc/apt/sources.list.d/home:alvistack.list
curl -fsSL https://download.opensuse.org/repositories/home:alvistack/xUbuntu_22.04/Release.key | gpg --dearmor | sudo tee /etc/apt/trusted.gpg.d/home_alvistack.gpg > /dev/null
sudo apt update
sudo apt -o Dpkg::Options::="--force-overwrite" install skopeo
git clone --depth 1 --branch v1.15.0 https://github.com/containers/skopeo.git
cd skopeo
DISABLE_CGO=1 make bin/skopeo
sudo cp ./bin/skopeo /usr/bin/skopeo
cd ..
rm -rf skopeo
skopeo --version
- name: Save dockerfile to local
run: |
make dockerfile-local
Expand Down
16 changes: 6 additions & 10 deletions pkg/handlers/distribution/base/repository_list.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,26 +25,22 @@
"github.com/rs/zerolog/log"
"gorm.io/gorm"

"github.com/go-sigma/sigma/pkg/consts"
"github.com/go-sigma/sigma/pkg/dal/models"
"github.com/go-sigma/sigma/pkg/utils"
"github.com/go-sigma/sigma/pkg/xerrors"
)

// ListRepositories handles the list repositories request
func (h *handler) ListRepositories(c echo.Context) error {
iuser := c.Get(consts.ContextUser)
if iuser == nil {
log.Error().Msg("Get user from header failed")
return xerrors.NewHTTPError(c, xerrors.HTTPErrCodeUnauthorized)
user, needRet, err := utils.GetUserFromCtxForDs(c)
if err != nil {
return err

Check warning on line 37 in pkg/handlers/distribution/base/repository_list.go

View check run for this annotation

Codecov / codecov/patch

pkg/handlers/distribution/base/repository_list.go#L37

Added line #L37 was not covered by tests
}
user, ok := iuser.(*models.User)
if !ok {
log.Error().Msg("Convert user from header failed")
return xerrors.NewHTTPError(c, xerrors.HTTPErrCodeUnauthorized)
if needRet {
return nil

Check warning on line 40 in pkg/handlers/distribution/base/repository_list.go

View check run for this annotation

Codecov / codecov/patch

pkg/handlers/distribution/base/repository_list.go#L40

Added line #L40 was not covered by tests
}

var n = 1000
var err error
var nStr = c.QueryParam("n")
if nStr != "" {
n, err = strconv.Atoi(nStr)
Expand Down
15 changes: 5 additions & 10 deletions pkg/handlers/distribution/base/tags_list.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@
"github.com/rs/zerolog/log"
"gorm.io/gorm"

"github.com/go-sigma/sigma/pkg/consts"
"github.com/go-sigma/sigma/pkg/dal/models"
"github.com/go-sigma/sigma/pkg/types/enums"
"github.com/go-sigma/sigma/pkg/utils"
Expand All @@ -41,15 +40,12 @@

// ListTags handles the list tags request
func (h *handler) ListTags(c echo.Context) error {
iuser := c.Get(consts.ContextUser)
if iuser == nil {
log.Error().Msg("Get user from header failed")
return xerrors.NewHTTPError(c, xerrors.HTTPErrCodeUnauthorized)
user, needRet, err := utils.GetUserFromCtxForDs(c)
if err != nil {
return err

Check warning on line 45 in pkg/handlers/distribution/base/tags_list.go

View check run for this annotation

Codecov / codecov/patch

pkg/handlers/distribution/base/tags_list.go#L45

Added line #L45 was not covered by tests
}
user, ok := iuser.(*models.User)
if !ok {
log.Error().Msg("Convert user from header failed")
return xerrors.NewHTTPError(c, xerrors.HTTPErrCodeUnauthorized)
if needRet {
return nil

Check warning on line 48 in pkg/handlers/distribution/base/tags_list.go

View check run for this annotation

Codecov / codecov/patch

pkg/handlers/distribution/base/tags_list.go#L48

Added line #L48 was not covered by tests
}

var uri = c.Request().URL.Path
Expand All @@ -58,7 +54,6 @@
}

var n = 1000
var err error
var nStr = c.QueryParam("n")
if nStr != "" {
n, err = strconv.Atoi(nStr)
Expand Down
5 changes: 4 additions & 1 deletion pkg/handlers/distribution/blob/blob_delete.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,10 +37,13 @@
func (h *handler) DeleteBlob(c echo.Context) error {
ctx := log.Logger.WithContext(c.Request().Context())

user, err := utils.GetUserFromCtx(c)
user, needRet, err := utils.GetUserFromCtxForDs(c)

Check warning on line 40 in pkg/handlers/distribution/blob/blob_delete.go

View check run for this annotation

Codecov / codecov/patch

pkg/handlers/distribution/blob/blob_delete.go#L40

Added line #L40 was not covered by tests
if err != nil {
return err
}
if needRet {
return nil
}

Check warning on line 46 in pkg/handlers/distribution/blob/blob_delete.go

View check run for this annotation

Codecov / codecov/patch

pkg/handlers/distribution/blob/blob_delete.go#L44-L46

Added lines #L44 - L46 were not covered by tests

uri := c.Request().URL.Path

Expand Down
5 changes: 4 additions & 1 deletion pkg/handlers/distribution/blob/blob_get.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,10 +47,13 @@
func (h *handler) GetBlob(c echo.Context) error {
ctx := log.Logger.WithContext(c.Request().Context())

user, err := utils.GetUserFromCtx(c)
user, needRet, err := utils.GetUserFromCtxForDs(c)

Check warning on line 50 in pkg/handlers/distribution/blob/blob_get.go

View check run for this annotation

Codecov / codecov/patch

pkg/handlers/distribution/blob/blob_get.go#L50

Added line #L50 was not covered by tests
if err != nil {
return err
}
if needRet {
return nil
}

Check warning on line 56 in pkg/handlers/distribution/blob/blob_get.go

View check run for this annotation

Codecov / codecov/patch

pkg/handlers/distribution/blob/blob_get.go#L54-L56

Added lines #L54 - L56 were not covered by tests

uri := c.Request().URL.Path

Expand Down
5 changes: 4 additions & 1 deletion pkg/handlers/distribution/blob/blob_head.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,10 +38,13 @@
func (h *handler) HeadBlob(c echo.Context) error {
ctx := log.Logger.WithContext(c.Request().Context())

user, err := utils.GetUserFromCtx(c)
user, needRet, err := utils.GetUserFromCtxForDs(c)

Check warning on line 41 in pkg/handlers/distribution/blob/blob_head.go

View check run for this annotation

Codecov / codecov/patch

pkg/handlers/distribution/blob/blob_head.go#L41

Added line #L41 was not covered by tests
if err != nil {
return err
}
if needRet {
return nil
}

Check warning on line 47 in pkg/handlers/distribution/blob/blob_head.go

View check run for this annotation

Codecov / codecov/patch

pkg/handlers/distribution/blob/blob_head.go#L45-L47

Added lines #L45 - L47 were not covered by tests

uri := c.Request().URL.Path

Expand Down
14 changes: 5 additions & 9 deletions pkg/handlers/distribution/manifest/manifest_delete.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@
"gorm.io/gorm"

"github.com/go-sigma/sigma/pkg/consts"
"github.com/go-sigma/sigma/pkg/dal/models"
"github.com/go-sigma/sigma/pkg/dal/query"
"github.com/go-sigma/sigma/pkg/types/enums"
"github.com/go-sigma/sigma/pkg/utils"
Expand All @@ -41,15 +40,12 @@
func (h *handler) DeleteManifest(c echo.Context) error {
ctx := log.Logger.WithContext(c.Request().Context())

iuser := c.Get(consts.ContextUser)
if iuser == nil {
log.Error().Msg("Get user from header failed")
return xerrors.NewHTTPError(c, xerrors.HTTPErrCodeUnauthorized)
user, needRet, err := utils.GetUserFromCtxForDs(c)
if err != nil {
return err

Check warning on line 45 in pkg/handlers/distribution/manifest/manifest_delete.go

View check run for this annotation

Codecov / codecov/patch

pkg/handlers/distribution/manifest/manifest_delete.go#L45

Added line #L45 was not covered by tests
}
user, ok := iuser.(*models.User)
if !ok {
log.Error().Msg("Convert user from header failed")
return xerrors.NewHTTPError(c, xerrors.HTTPErrCodeUnauthorized)
if needRet {
return nil

Check warning on line 48 in pkg/handlers/distribution/manifest/manifest_delete.go

View check run for this annotation

Codecov / codecov/patch

pkg/handlers/distribution/manifest/manifest_delete.go#L48

Added line #L48 was not covered by tests
}

uri := c.Request().URL.Path
Expand Down
14 changes: 5 additions & 9 deletions pkg/handlers/distribution/manifest/manifest_get.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@
"gorm.io/gorm"

"github.com/go-sigma/sigma/pkg/consts"
"github.com/go-sigma/sigma/pkg/dal/models"
"github.com/go-sigma/sigma/pkg/types/enums"
"github.com/go-sigma/sigma/pkg/utils"
"github.com/go-sigma/sigma/pkg/utils/imagerefs"
Expand All @@ -38,15 +37,12 @@
func (h *handler) GetManifest(c echo.Context) error {
ctx := log.Logger.WithContext(c.Request().Context())

iuser := c.Get(consts.ContextUser)
if iuser == nil {
log.Error().Msg("Get user from header failed")
return xerrors.NewHTTPError(c, xerrors.HTTPErrCodeUnauthorized)
user, needRet, err := utils.GetUserFromCtxForDs(c)
if err != nil {
return err

Check warning on line 42 in pkg/handlers/distribution/manifest/manifest_get.go

View check run for this annotation

Codecov / codecov/patch

pkg/handlers/distribution/manifest/manifest_get.go#L40-L42

Added lines #L40 - L42 were not covered by tests
}
user, ok := iuser.(*models.User)
if !ok {
log.Error().Msg("Convert user from header failed")
return xerrors.NewHTTPError(c, xerrors.HTTPErrCodeUnauthorized)
if needRet {
return nil

Check warning on line 45 in pkg/handlers/distribution/manifest/manifest_get.go

View check run for this annotation

Codecov / codecov/patch

pkg/handlers/distribution/manifest/manifest_get.go#L44-L45

Added lines #L44 - L45 were not covered by tests
}

uri := c.Request().URL.Path
Expand Down
14 changes: 5 additions & 9 deletions pkg/handlers/distribution/manifest/manifest_head.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@
"gorm.io/gorm"

"github.com/go-sigma/sigma/pkg/consts"
"github.com/go-sigma/sigma/pkg/dal/models"
"github.com/go-sigma/sigma/pkg/types/enums"
"github.com/go-sigma/sigma/pkg/utils"
"github.com/go-sigma/sigma/pkg/utils/imagerefs"
Expand All @@ -39,15 +38,12 @@
func (h *handler) HeadManifest(c echo.Context) error {
ctx := log.Logger.WithContext(c.Request().Context())

iuser := c.Get(consts.ContextUser)
if iuser == nil {
log.Error().Msg("Get user from header failed")
return xerrors.NewHTTPError(c, xerrors.HTTPErrCodeUnauthorized)
user, needRet, err := utils.GetUserFromCtxForDs(c)
if err != nil {
return err

Check warning on line 43 in pkg/handlers/distribution/manifest/manifest_head.go

View check run for this annotation

Codecov / codecov/patch

pkg/handlers/distribution/manifest/manifest_head.go#L43

Added line #L43 was not covered by tests
}
user, ok := iuser.(*models.User)
if !ok {
log.Error().Msg("Convert user from header failed")
return xerrors.NewHTTPError(c, xerrors.HTTPErrCodeUnauthorized)
if needRet {
return nil

Check warning on line 46 in pkg/handlers/distribution/manifest/manifest_head.go

View check run for this annotation

Codecov / codecov/patch

pkg/handlers/distribution/manifest/manifest_head.go#L46

Added line #L46 was not covered by tests
}

uri := c.Request().URL.Path
Expand Down
15 changes: 6 additions & 9 deletions pkg/handlers/distribution/manifest/manifest_put.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,15 +54,12 @@
func (h *handler) PutManifest(c echo.Context) error {
ctx := log.Logger.WithContext(c.Request().Context())

iuser := c.Get(consts.ContextUser)
if iuser == nil {
log.Error().Msg("Get user from header failed")
return xerrors.NewHTTPError(c, xerrors.HTTPErrCodeUnauthorized)
}
user, ok := iuser.(*models.User)
if !ok {
log.Error().Msg("Convert user from header failed")
return xerrors.NewHTTPError(c, xerrors.HTTPErrCodeUnauthorized)
user, needRet, err := utils.GetUserFromCtxForDs(c)
if err != nil {
return err
}

Check warning on line 60 in pkg/handlers/distribution/manifest/manifest_put.go

View check run for this annotation

Codecov / codecov/patch

pkg/handlers/distribution/manifest/manifest_put.go#L59-L60

Added lines #L59 - L60 were not covered by tests
if needRet {
return nil

Check warning on line 62 in pkg/handlers/distribution/manifest/manifest_put.go

View check run for this annotation

Codecov / codecov/patch

pkg/handlers/distribution/manifest/manifest_put.go#L62

Added line #L62 was not covered by tests
}

uri := c.Request().URL.Path
Expand Down
13 changes: 5 additions & 8 deletions pkg/handlers/distribution/upload/upload_post.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,15 +43,12 @@
func (h *handler) PostUpload(c echo.Context) error {
ctx := log.Logger.WithContext(c.Request().Context())

iuser := c.Get(consts.ContextUser)
if iuser == nil {
log.Error().Msg("Get user from header failed")
return xerrors.NewHTTPError(c, xerrors.HTTPErrCodeUnauthorized)
user, needRet, err := utils.GetUserFromCtxForDs(c)
if err != nil {
return err

Check warning on line 48 in pkg/handlers/distribution/upload/upload_post.go

View check run for this annotation

Codecov / codecov/patch

pkg/handlers/distribution/upload/upload_post.go#L46-L48

Added lines #L46 - L48 were not covered by tests
}
user, ok := iuser.(*models.User)
if !ok {
log.Error().Msg("Convert user from header failed")
return xerrors.NewHTTPError(c, xerrors.HTTPErrCodeUnauthorized)
if needRet {
return nil

Check warning on line 51 in pkg/handlers/distribution/upload/upload_post.go

View check run for this annotation

Codecov / codecov/patch

pkg/handlers/distribution/upload/upload_post.go#L50-L51

Added lines #L50 - L51 were not covered by tests
}

host := c.Request().Host
Expand Down
Loading
Loading