feat: Add Git auth for GitHub, GitLab, Azure DevOps, and BitBucket (#4670)

* Add scaffolding

* Move migration

* Add endpoints for gitauth

* Add configuration files and tests!

* Update typesgen

* Convert configuration format for git auth

* Fix unclosed database conn

* Add overriding VS Code configuration

* Fix Git screen

* Write VS Code special configuration if providers exist

* Enable automatic cloning from VS Code

* Add tests for gitaskpass

* Fix feature visibiliy

* Add banner for too many configurations

* Fix update loop for oauth token

* Jon comments

* Add deployment config page
This commit is contained in:
Kyle Carberry
2022-10-24 19:46:24 -05:00
committed by GitHub
parent 585045b359
commit eec406b739
62 changed files with 2211 additions and 88 deletions
+2 -1
View File
@@ -40,7 +40,8 @@ func init() {
if !ok {
return false
}
return UsernameValid(str)
valid := UsernameValid(str)
return valid == nil
}
for _, tag := range []string{"username", "template_name", "workspace_name"} {
err := validate.RegisterValidation(tag, nameValidator)
+11 -6
View File
@@ -5,6 +5,7 @@ import (
"strings"
"github.com/moby/moby/pkg/namesgenerator"
"golang.org/x/xerrors"
)
var (
@@ -13,14 +14,18 @@ var (
)
// UsernameValid returns whether the input string is a valid username.
func UsernameValid(str string) bool {
func UsernameValid(str string) error {
if len(str) > 32 {
return false
return xerrors.New("must be <= 32 characters")
}
if len(str) < 1 {
return false
return xerrors.New("must be >= 1 character")
}
return UsernameValidRegex.MatchString(str)
matched := UsernameValidRegex.MatchString(str)
if !matched {
return xerrors.New("must be alphanumeric with hyphens")
}
return nil
}
// UsernameFrom returns a best-effort username from the provided string.
@@ -30,7 +35,7 @@ func UsernameValid(str string) bool {
// the username from an email address. If no success happens during
// these steps, a random username will be returned.
func UsernameFrom(str string) string {
if UsernameValid(str) {
if valid := UsernameValid(str); valid == nil {
return str
}
emailAt := strings.LastIndex(str, "@")
@@ -38,7 +43,7 @@ func UsernameFrom(str string) string {
str = str[:emailAt]
}
str = usernameReplace.ReplaceAllString(str, "")
if UsernameValid(str) {
if valid := UsernameValid(str); valid == nil {
return str
}
return strings.ReplaceAll(namesgenerator.GetRandomName(1), "_", "-")
+4 -2
View File
@@ -59,7 +59,8 @@ func TestValid(t *testing.T) {
testCase := testCase
t.Run(testCase.Username, func(t *testing.T) {
t.Parallel()
require.Equal(t, testCase.Valid, httpapi.UsernameValid(testCase.Username))
valid := httpapi.UsernameValid(testCase.Username)
require.Equal(t, testCase.Valid, valid == nil)
})
}
}
@@ -91,7 +92,8 @@ func TestFrom(t *testing.T) {
t.Parallel()
converted := httpapi.UsernameFrom(testCase.From)
t.Log(converted)
require.True(t, httpapi.UsernameValid(converted))
valid := httpapi.UsernameValid(converted)
require.True(t, valid == nil)
if testCase.Match == "" {
require.NotEqual(t, testCase.From, converted)
} else {