Skip to content

Commit

Permalink
✨ Add role field for namespace api (#299)
Browse files Browse the repository at this point in the history
* 📝 Update config

* ⬆️ Upgrade minio

* ✨ Add role field for namespace api

* ✨ Change auth api
  • Loading branch information
tosone committed Feb 9, 2024
1 parent be5fde3 commit 1fa4acc
Show file tree
Hide file tree
Showing 48 changed files with 386 additions and 234 deletions.
4 changes: 4 additions & 0 deletions conf/config-dev.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,10 @@ storage:
region: cn-north-1
bucket: sigma
forcePathStyle: true
cos:
ak: sigma
sk: sigma-sigma
endpoint: https://hack-1251887554.cos.na-toronto.myqcloud.com
oss:
ak: sigma
sk: sigma-sigma
Expand Down
10 changes: 10 additions & 0 deletions conf/config-full.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,16 @@ storage:
region: cn-north-1
bucket: sigma
forcePathStyle: true
cos:
ak: sigma
sk: sigma-sigma
endpoint: https://hack-1251887554.cos.na-toronto.myqcloud.com
oss:
ak: sigma
sk: sigma-sigma
endpoint: http://127.0.0.1:9000
forcePathStyle: true

# Notice: the tag never update after the first pulled from remote registry, unless you delete the image and pull again.
proxy:
enabled: false
Expand Down
11 changes: 8 additions & 3 deletions conf/config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -101,9 +101,14 @@ storage:
bucket: sigma
forcePathStyle: true
cos:
ak: xxxx
sk: xxxx
endpoint: https://xxxxxxx
ak: sigma
sk: sigma-sigma
endpoint: https://hack-1251887554.cos.na-toronto.myqcloud.com
oss:
ak: sigma
sk: sigma-sigma
endpoint: http://127.0.0.1:9000
forcePathStyle: true

# Notice: the tag never update after the first pulled from remote registry, unless you delete the image and pull again.
proxy:
Expand Down
2 changes: 1 addition & 1 deletion docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ services:
- default
minio:
container_name: minio
image: quay.io/minio/minio:RELEASE.2024-01-31T20-20-33Z
image: quay.io/minio/minio:RELEASE.2024-02-06T21-36-22Z
ports:
- "9000:9000"
- "9001:9001"
Expand Down
9 changes: 9 additions & 0 deletions docs/docs/configuration.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,15 @@ storage:
region: cn-north-1
bucket: sigma
forcePathStyle: true
cos:
ak: sigma
sk: sigma-sigma
endpoint: https://hack-1251887554.cos.na-toronto.myqcloud.com
oss:
ak: sigma
sk: sigma-sigma
endpoint: http://127.0.0.1:9000
forcePathStyle: true

# Notice: the tag never update after the first pulled from remote registry, unless you delete the image and pull again.
proxy:
Expand Down
2 changes: 0 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -219,8 +219,6 @@ github.com/asaskevich/govalidator v0.0.0-20190424111038-f61b66f89f4a/go.mod h1:l
github.com/asaskevich/govalidator v0.0.0-20230301143203-a9d515a09cc2 h1:DklsrG3dyBCFEj5IhUbnKptjxatkF07cF2ak3yi77so=
github.com/asaskevich/govalidator v0.0.0-20230301143203-a9d515a09cc2/go.mod h1:WaHUgvxTVq04UNunO+XhnAqY/wQc+bxr74GqbsZ/Jqw=
github.com/aws/aws-sdk-go v1.15.11/go.mod h1:mFuSZ37Z9YOHbQEwBWztmVzqXrEkub65tZoCYDt7FT0=
github.com/aws/aws-sdk-go v1.50.11 h1:BxUqMbkzKzzQ6FXLlZFNFkFjHnv6utbc4PItVs5SvaE=
github.com/aws/aws-sdk-go v1.50.11/go.mod h1:LF8svs817+Nz+DmiMQKTO3ubZ/6IaTpq3TjupRn3Eqk=
github.com/aws/aws-sdk-go v1.50.13 h1:yeXram2g7q8uKkQkAEeZyk9FmPzxI4UpGwAZGZtEGmM=
github.com/aws/aws-sdk-go v1.50.13/go.mod h1:LF8svs817+Nz+DmiMQKTO3ubZ/6IaTpq3TjupRn3Eqk=
github.com/aws/aws-sdk-go-v2 v1.24.1 h1:xAojnj+ktS95YZlDf0zxWBkbFtymPeDP+rvUQIH3uAU=
Expand Down
9 changes: 5 additions & 4 deletions pkg/auth/artifact.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,19 +15,20 @@
package auth

import (
"context"
"errors"
"fmt"

"github.com/labstack/echo/v4"
"github.com/rs/zerolog/log"
"gorm.io/gorm"

"github.com/go-sigma/sigma/pkg/dal/models"
"github.com/go-sigma/sigma/pkg/types/enums"
)

// Tag ...
func (s authService) Artifact(c echo.Context, artifactID int64, auth enums.Auth) (bool, error) {
ctx := log.Logger.WithContext(c.Request().Context())
func (s authService) Artifact(user models.User, artifactID int64, auth enums.Auth) (bool, error) {
ctx := log.Logger.WithContext(context.Background())

artifactService := s.artifactServiceFactory.New()
artifactObj, err := artifactService.Get(ctx, artifactID)
Expand All @@ -39,5 +40,5 @@ func (s authService) Artifact(c echo.Context, artifactID int64, auth enums.Auth)
log.Error().Err(err).Int64("artifactID", artifactID).Msg("Get artifact by id not found")
return false, errors.Join(err, fmt.Errorf("Get artifact by id(%d) not found", artifactID))
}
return s.Repository(c, artifactObj.RepositoryID, auth)
return s.Repository(user, artifactObj.RepositoryID, auth)
}
19 changes: 11 additions & 8 deletions pkg/auth/auth.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,25 +15,28 @@
package auth

import (
"github.com/labstack/echo/v4"

"github.com/go-sigma/sigma/pkg/dal/dao"
"github.com/go-sigma/sigma/pkg/dal/models"
"github.com/go-sigma/sigma/pkg/types/enums"
)

//go:generate mockgen -destination=mocks/service.go -package=mocks github.com/go-sigma/sigma/pkg/auth Service
//go:generate mockgen -destination=mocks/service_factory.go -package=mocks github.com/go-sigma/sigma/pkg/auth ServiceFactory
//go:generate mockgen -destination=mocks/service.go -package=mocks github.com/go-sigma/sigma/pkg/auth AuthService
//go:generate mockgen -destination=mocks/service_factory.go -package=mocks github.com/go-sigma/sigma/pkg/auth AuthServiceFactory

// AuthService is the interface for the auth service
type AuthService interface {
// Namespace ...
Namespace(c echo.Context, namespaceID int64, auth enums.Auth) (bool, error)
Namespace(user models.User, namespaceID int64, auth enums.Auth) (bool, error)
// NamespaceRole get user role in namespace
NamespaceRole(user models.User, namespaceID int64) (*enums.NamespaceRole, error)
// NamespacesRole ...
NamespacesRole(user models.User, namespaceIDs []int64) (map[int64]*enums.NamespaceRole, error)
// Repository ...
Repository(c echo.Context, repositoryID int64, auth enums.Auth) (bool, error)
Repository(user models.User, repositoryID int64, auth enums.Auth) (bool, error)
// Tag ...
Tag(c echo.Context, tagID int64, auth enums.Auth) (bool, error)
Tag(user models.User, tagID int64, auth enums.Auth) (bool, error)
// Artifact ...
Artifact(c echo.Context, artifactID int64, auth enums.Auth) (bool, error)
Artifact(user models.User, artifactID int64, auth enums.Auth) (bool, error)
}

// AuthServiceFactory is the interface that provides the artifact service factory methods.
Expand Down
82 changes: 56 additions & 26 deletions pkg/auth/mocks/service.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

32 changes: 16 additions & 16 deletions pkg/auth/mocks/service_factory.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit 1fa4acc

Please sign in to comment.