cleanups for OAuth in sdk.ShareRequest (#404)

This commit is contained in:
Michael Quigley 2023-09-28 13:06:00 -04:00
parent 957e50412e
commit 27fcf98fbd
No known key found for this signature in database
GPG Key ID: 9B60314A9DD20A62
5 changed files with 9 additions and 10 deletions

View File

@ -83,7 +83,7 @@ func (cmd *reserveCommand) run(_ *cobra.Command, args []string) {
req := &sdk.ShareRequest{ req := &sdk.ShareRequest{
BackendMode: sdk.BackendMode(cmd.backendMode), BackendMode: sdk.BackendMode(cmd.backendMode),
ShareMode: shareMode, ShareMode: shareMode,
Auth: cmd.basicAuth, BasicAuth: cmd.basicAuth,
Target: target, Target: target,
} }
if shareMode == sdk.PublicShareMode { if shareMode == sdk.PublicShareMode {

View File

@ -99,7 +99,7 @@ func (cmd *sharePrivateCommand) run(_ *cobra.Command, args []string) {
req := &sdk.ShareRequest{ req := &sdk.ShareRequest{
BackendMode: sdk.BackendMode(cmd.backendMode), BackendMode: sdk.BackendMode(cmd.backendMode),
ShareMode: sdk.PrivateShareMode, ShareMode: sdk.PrivateShareMode,
Auth: cmd.basicAuth, BasicAuth: cmd.basicAuth,
Target: target, Target: target,
} }
shr, err := sdk.CreateShare(root, req) shr, err := sdk.CreateShare(root, req)

View File

@ -105,10 +105,9 @@ func (cmd *sharePublicCommand) run(_ *cobra.Command, args []string) {
BackendMode: sdk.BackendMode(cmd.backendMode), BackendMode: sdk.BackendMode(cmd.backendMode),
ShareMode: sdk.PublicShareMode, ShareMode: sdk.PublicShareMode,
Frontends: cmd.frontendSelection, Frontends: cmd.frontendSelection,
Auth: cmd.basicAuth, BasicAuth: cmd.basicAuth,
Target: target, Target: target,
} }
if cmd.oauthProvider != "" { if cmd.oauthProvider != "" {
req.OauthProvider = cmd.oauthProvider req.OauthProvider = cmd.oauthProvider
req.OauthEmailDomains = cmd.oauthEmailDomains req.OauthEmailDomains = cmd.oauthEmailDomains

View File

@ -22,9 +22,9 @@ const (
type ShareRequest struct { type ShareRequest struct {
BackendMode BackendMode BackendMode BackendMode
ShareMode ShareMode ShareMode ShareMode
Frontends []string
Auth []string
Target string Target string
Frontends []string
BasicAuth []string
OauthProvider string OauthProvider string
OauthEmailDomains []string OauthEmailDomains []string
OauthAuthorizationCheckInterval time.Duration OauthAuthorizationCheckInterval time.Duration

View File

@ -26,14 +26,14 @@ func CreateShare(root env_core.Root, request *ShareRequest) (*Share, error) {
return nil, errors.Errorf("unknown share mode '%v'", request.ShareMode) return nil, errors.Errorf("unknown share mode '%v'", request.ShareMode)
} }
if len(request.Auth) > 0 { if len(request.BasicAuth) > 0 {
out.Body.AuthScheme = string(Basic) out.Body.AuthScheme = string(Basic)
for _, pair := range request.Auth { for _, basicAuthUser := range request.BasicAuth {
tokens := strings.Split(pair, ":") tokens := strings.Split(basicAuthUser, ":")
if len(tokens) == 2 { if len(tokens) == 2 {
out.Body.AuthUsers = append(out.Body.AuthUsers, &rest_model_zrok.AuthUser{Username: strings.TrimSpace(tokens[0]), Password: strings.TrimSpace(tokens[1])}) out.Body.AuthUsers = append(out.Body.AuthUsers, &rest_model_zrok.AuthUser{Username: strings.TrimSpace(tokens[0]), Password: strings.TrimSpace(tokens[1])})
} else { } else {
return nil, errors.Errorf("invalid username:password pair '%v'", pair) return nil, errors.Errorf("invalid username:password '%v'", basicAuthUser)
} }
} }
} }