-
-
Notifications
You must be signed in to change notification settings - Fork 5.8k
Add Allow-/Block-List for Migrate & Mirrors #13610
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
Merged
techknowlogick
merged 38 commits into
go-gitea:master
from
6543-forks:allow-block_list_migrate-mirror_8040
Nov 29, 2020
Merged
Changes from 32 commits
Commits
Show all changes
38 commits
Select commit
Hold shift + click to select a range
7a083b9
add black list and white list support for migrating repositories
lunny 3f2b34b
fix fmt
lunny ad5a226
fix lint
lunny 7280964
fix vendor
lunny cdff51c
fix modules.txt
lunny ab362e5
Merge branch 'master' into allow-block_list_migrate-mirror_8040
6543 ec4dbc8
clean diff
6543 770dab6
specify log message
6543 05e45bf
use blocklist/allowlist
6543 a078736
allways use lowercase to match url
6543 dec70f1
Apply allow/block
6543 d2c1619
Merge branch 'master' into allow-block_list_migrate-mirror_8040
6543 840fc85
Settings: use existing "migrations" section
6543 af32a09
Merge branch 'master' into allow-block_list_migrate-mirror_8040
6543 9f5e0de
convert domains lower case
6543 3ede511
Merge branch 'master' into allow-block_list_migrate-mirror_8040
6543 37f45f4
dont store unused value
6543 e0934b8
Block private addresses for migration by default
6543 43982b4
fix lint
6543 9cd404a
Merge branch 'master' into allow-block_list_migrate-mirror_8040
6543 6725fd5
use proposed-upstream func to detect private IP addr
6543 6b8ecc4
a nit
6543 6ef7267
add own error for blocked migration, add tests, imprufe api
6543 c66cf83
fix test
6543 3b57ffc
fix-if-localhost-is-ipv4
6543 027f6f1
Merge branch 'master' into allow-block_list_migrate-mirror_8040
6543 ab53576
Merge branch 'master' into allow-block_list_migrate-mirror_8040
6543 8372dd1
rename error & error message
6543 b9dda50
Merge branch 'master' into allow-block_list_migrate-mirror_8040
6543 aa8ec6f
Merge branch 'master' into allow-block_list_migrate-mirror_8040
6543 bb5ce58
rename setting options
6543 9815e9d
Merge branch 'master' into allow-block_list_migrate-mirror_8040
6543 e13cd15
Apply suggestions from code review
zeripath 6602023
Merge branch 'master' into allow-block_list_migrate-mirror_8040
6543 870ca5b
Merge branch 'master' into allow-block_list_migrate-mirror_8040
lunny e091333
Merge branch 'master' into allow-block_list_migrate-mirror_8040
zeripath 7850e5e
Merge branch 'master' into allow-block_list_migrate-mirror_8040
6543 3c67197
Merge branch 'master' into allow-block_list_migrate-mirror_8040
techknowlogick 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,46 @@ | ||
// Copyright 2019 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 matchlist | ||
|
||
import ( | ||
"strings" | ||
|
||
"github.com/gobwas/glob" | ||
) | ||
|
||
// Matchlist represents a block or allow list | ||
type Matchlist struct { | ||
ruleGlobs []glob.Glob | ||
} | ||
|
||
// NewMatchlist creates a new block or allow list | ||
func NewMatchlist(rules ...string) (*Matchlist, error) { | ||
for i := range rules { | ||
rules[i] = strings.ToLower(rules[i]) | ||
} | ||
list := Matchlist{ | ||
ruleGlobs: make([]glob.Glob, 0, len(rules)), | ||
} | ||
|
||
for _, rule := range rules { | ||
rg, err := glob.Compile(rule) | ||
if err != nil { | ||
return nil, err | ||
} | ||
list.ruleGlobs = append(list.ruleGlobs, rg) | ||
} | ||
|
||
return &list, nil | ||
} | ||
|
||
// Match will matches | ||
func (b *Matchlist) Match(u string) bool { | ||
for _, r := range b.ruleGlobs { | ||
if r.Match(u) { | ||
return true | ||
} | ||
} | ||
return false | ||
} |
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,34 @@ | ||
// Copyright 2019 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 ( | ||
"testing" | ||
|
||
"code.gitea.io/gitea/modules/setting" | ||
|
||
"github.com/stretchr/testify/assert" | ||
) | ||
|
||
func TestMigrateWhiteBlocklist(t *testing.T) { | ||
setting.Migrations.AllowedDomains = []string{"github.com"} | ||
assert.NoError(t, Init()) | ||
|
||
err := isMigrateURLAllowed("https://gitlab.com/gitlab/gitlab.git") | ||
assert.Error(t, err) | ||
|
||
err = isMigrateURLAllowed("https://github.com/go-gitea/gitea.git") | ||
assert.NoError(t, err) | ||
|
||
setting.Migrations.AllowedDomains = []string{} | ||
setting.Migrations.BlockedDomains = []string{"github.com"} | ||
assert.NoError(t, Init()) | ||
|
||
err = isMigrateURLAllowed("https://gitlab.com/gitlab/gitlab.git") | ||
assert.NoError(t, err) | ||
|
||
err = isMigrateURLAllowed("https://github.com/go-gitea/gitea.git") | ||
assert.Error(t, 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
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.