mirror of
https://git.sr.ht/~phw/scotty
synced 2025-04-26 22:27:56 +02:00
Prompt user for auth after service requireing auth added
This commit is contained in:
parent
9449a29fb1
commit
ab0e50f7aa
3 changed files with 106 additions and 53 deletions
|
@ -27,9 +27,11 @@ import (
|
|||
|
||||
"github.com/manifoldco/promptui"
|
||||
"github.com/spf13/cobra"
|
||||
"go.uploadedlobster.com/scotty/internal/backends"
|
||||
"go.uploadedlobster.com/scotty/internal/cli"
|
||||
"go.uploadedlobster.com/scotty/internal/config"
|
||||
"go.uploadedlobster.com/scotty/internal/i18n"
|
||||
"go.uploadedlobster.com/scotty/internal/models"
|
||||
)
|
||||
|
||||
var serviceAddCmd = &cobra.Command{
|
||||
|
@ -71,6 +73,10 @@ var serviceAddCmd = &cobra.Command{
|
|||
err = service.Save()
|
||||
cobra.CheckErr(err)
|
||||
fmt.Println(i18n.Tr("Saved service %v using backend %v", service.Name, service.Backend))
|
||||
|
||||
// Check whether authentication is required
|
||||
err = promptForAuth(service)
|
||||
cobra.CheckErr(err)
|
||||
},
|
||||
}
|
||||
|
||||
|
@ -87,3 +93,25 @@ func init() {
|
|||
// is called directly, e.g.:
|
||||
// serviceAddCmd.Flags().BoolP("toggle", "t", false, "Help message for toggle")
|
||||
}
|
||||
|
||||
func promptForAuth(service config.ServiceConfig) error {
|
||||
backend, err := backends.ResolveBackend[models.OAuth2Authenticator](service)
|
||||
if err != nil {
|
||||
// No authentication required, return
|
||||
return nil
|
||||
}
|
||||
|
||||
doAuth, err := cli.PromptYesNo(
|
||||
i18n.Tr("The backend %v requires authentication. Authenticate now?", service.Backend),
|
||||
true,
|
||||
)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
if !doAuth {
|
||||
return nil
|
||||
}
|
||||
|
||||
cli.AuthenticationFlow(service, backend)
|
||||
return nil
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue