feat(codersdk): export name validators (#14550)

* feat(codersdk): export name validators

* review
This commit is contained in:
Ethan
2024-09-04 18:17:53 +10:00
committed by GitHub
parent 093d243811
commit 01a904c133
10 changed files with 154 additions and 31 deletions

View File

@ -266,7 +266,7 @@ func validOrganizationRoleRequest(ctx context.Context, req codersdk.CustomRoleRe
return false
}
if err := httpapi.NameValid(req.Name); err != nil {
if err := codersdk.NameValid(req.Name); err != nil {
httpapi.Write(ctx, rw, http.StatusBadRequest, codersdk.Response{
Message: "Invalid role name",
Detail: err.Error(),

View File

@ -206,7 +206,7 @@ func (api *API) scimPostUser(rw http.ResponseWriter, r *http.Request) {
// The username is a required property in Coder. We make a best-effort
// attempt at using what the claims provide, but if that fails we will
// generate a random username.
usernameValid := httpapi.NameValid(sUser.UserName)
usernameValid := codersdk.NameValid(sUser.UserName)
if usernameValid != nil {
// If no username is provided, we can default to use the email address.
// This will be converted in the from function below, so it's safe
@ -214,7 +214,7 @@ func (api *API) scimPostUser(rw http.ResponseWriter, r *http.Request) {
if sUser.UserName == "" {
sUser.UserName = email
}
sUser.UserName = httpapi.UsernameFrom(sUser.UserName)
sUser.UserName = codersdk.UsernameFrom(sUser.UserName)
}
// TODO: This is a temporary solution that does not support multi-org