-
-
Notifications
You must be signed in to change notification settings - Fork 5.8k
add token service support for docker registry #14919
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
Closed
Closed
Changes from 7 commits
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
377c5ac
add token service support for docker registry
a1012112796 cb934f1
Update routers/repo/package.go
a1012112796 d3ae2f5
Merge branch 'master' into docker_support
a1012112796 9555233
use decoder
a1012112796 47e2a11
split code
a1012112796 b1f5379
Merge branch 'master' into docker_support
a1012112796 3548d25
init third part api
a1012112796 260fe61
Update modules/structs/package.go
a1012112796 80b7e1d
fix some spell mistake.
a1012112796 62c8142
Merge branch 'master' into docker_support
a1012112796 759a900
Merge branch 'master' into docker_support
a1012112796 ff44fca
apply suggestions from code review
a1012112796 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
// Copyright 2021 The Gitea Authors. All rights reserved. | ||
// Use of this source code is governed by a MIT-style | ||
// license that can be found in the LICENSE file. | ||
|
||
package migrations | ||
|
||
import ( | ||
"xorm.io/xorm" | ||
) | ||
|
||
func addPackageTable(x *xorm.Engine) error { | ||
type PackageType int64 | ||
|
||
type Package struct { | ||
ID int64 `xorm:"pk autoincr"` | ||
Name string | ||
LowerName string `xorm:"INDEX"` | ||
|
||
RepoID int64 `xorm:"INDEX"` | ||
|
||
Type PackageType | ||
|
||
CreatedUnix int64 `xorm:"INDEX created"` | ||
UpdatedUnix int64 `xorm:"INDEX updated"` | ||
} | ||
|
||
return x.Sync(new(Package)) | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,102 @@ | ||
// Copyright 2021 The Gitea Authors. All rights reserved. | ||
// Use of this source code is governed by a MIT-style | ||
// license that can be found in the LICENSE file. | ||
|
||
package models | ||
|
||
import ( | ||
"strings" | ||
|
||
"code.gitea.io/gitea/modules/timeutil" | ||
) | ||
|
||
// PackageType type of package | ||
type PackageType int64 | ||
|
||
const ( | ||
// PackageTypeDockerImage a docker image (need docker_auth_port) | ||
PackageTypeDockerImage PackageType = iota | ||
) | ||
|
||
func (t PackageType) String() string { | ||
if t == PackageTypeDockerImage { | ||
return "docker" | ||
} | ||
return "" | ||
} | ||
|
||
// Package an image message tmp | ||
type Package struct { | ||
ID int64 `xorm:"pk autoincr"` | ||
Name string | ||
LowerName string `xorm:"INDEX"` | ||
|
||
RepoID int64 `xorm:"INDEX"` | ||
Repo *Repository `xorm:"-"` | ||
|
||
Type PackageType | ||
|
||
CreatedUnix timeutil.TimeStamp `xorm:"INDEX created"` | ||
UpdatedUnix timeutil.TimeStamp `xorm:"INDEX updated"` | ||
} | ||
|
||
// AddPackageOptions options for add package | ||
type AddPackageOptions struct { | ||
Repo *Repository | ||
Name string | ||
Type PackageType | ||
} | ||
|
||
// AddPackage add a new package | ||
func AddPackage(option AddPackageOptions) error { | ||
pkg := &Package{ | ||
Name: option.Name, | ||
Type: option.Type, | ||
RepoID: option.Repo.ID, | ||
} | ||
pkg.LowerName = strings.ToLower(pkg.Name) | ||
_, err := x.Insert(pkg) | ||
return err | ||
} | ||
|
||
// GetPackage get an package | ||
a1012112796 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
func GetPackage(repoID int64, typ PackageType, name string) (*Package, error) { | ||
return getPackage(x, repoID, typ, name) | ||
} | ||
|
||
func getPackage(e Engine, repoID int64, typ PackageType, name string) (*Package, error) { | ||
lowName := strings.ToLower(name) | ||
pkg := new(Package) | ||
has, err := e.Where("repo_id = ? AND type = ? AND lower_name = ?", | ||
repoID, typ, lowName).Get(pkg) | ||
|
||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
if !has { | ||
return nil, ErrPackageNotExist{ | ||
RepoID: repoID, | ||
Name: name, | ||
Type: typ, | ||
} | ||
} | ||
|
||
return pkg, nil | ||
} | ||
|
||
// UpdateCols updates some columns | ||
a1012112796 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
func (pkg *Package) UpdateCols(cols ...string) error { | ||
_, err := x.ID(pkg.ID).Cols(cols...).Update(pkg) | ||
return err | ||
} | ||
|
||
// LoadRepo load package's repo | ||
func (pkg *Package) LoadRepo(cols ...string) (err error) { | ||
if pkg.Repo != nil { | ||
return nil | ||
} | ||
|
||
pkg.Repo, err = GetRepositoryByID(pkg.RepoID) | ||
return err | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.