2023-12-12 18:42:50 +01:00
|
|
|
package commands
|
|
|
|
|
|
|
|
import (
|
|
|
|
"github.com/urfave/cli"
|
2024-01-13 16:27:05 +01:00
|
|
|
|
2024-01-18 16:53:05 +01:00
|
|
|
"github.com/photoprism/photoprism/internal/acl"
|
2024-01-13 16:27:05 +01:00
|
|
|
"github.com/photoprism/photoprism/pkg/authn"
|
2024-01-29 13:54:50 +01:00
|
|
|
"github.com/photoprism/photoprism/pkg/unix"
|
2023-12-12 18:42:50 +01:00
|
|
|
)
|
|
|
|
|
|
|
|
// Usage hints for the client management subcommands.
|
|
|
|
const (
|
2024-01-29 13:54:50 +01:00
|
|
|
ClientIdUsage = "static client `UID` for test purposes"
|
|
|
|
ClientSecretUsage = "static client `SECRET` for test purposes"
|
2024-01-18 16:53:05 +01:00
|
|
|
ClientNameUsage = "`CLIENT` name to help identify the application"
|
|
|
|
ClientRoleUsage = "client authorization `ROLE`"
|
|
|
|
ClientAuthScope = "client authorization `SCOPES` e.g. \"metrics\" or \"photos albums\" (\"*\" to allow all)"
|
2024-01-19 14:41:08 +01:00
|
|
|
ClientAuthProvider = "client authentication `PROVIDER`"
|
2024-01-18 16:53:05 +01:00
|
|
|
ClientAuthMethod = "client authentication `METHOD`"
|
2024-01-29 13:54:50 +01:00
|
|
|
ClientAuthExpires = "access token `LIFETIME` in seconds, after which a new token must be requested"
|
|
|
|
ClientAuthTokens = "maximum `NUMBER` of access tokens that the client can request (-1 to disable the limit)"
|
|
|
|
ClientRegenerateSecret = "set a new randomly generated client secret"
|
2024-01-18 16:53:05 +01:00
|
|
|
ClientEnable = "enable client authentication if disabled"
|
|
|
|
ClientDisable = "disable client authentication"
|
2024-01-29 13:54:50 +01:00
|
|
|
ClientSecretInfo = "\nPLEASE WRITE DOWN THE %s CLIENT SECRET, AS YOU WILL NOT BE ABLE TO SEE IT AGAIN:\n"
|
2023-12-12 18:42:50 +01:00
|
|
|
)
|
|
|
|
|
2024-01-02 17:06:57 +01:00
|
|
|
// ClientsCommands configures the client application subcommands.
|
|
|
|
var ClientsCommands = cli.Command{
|
2024-01-05 16:31:07 +01:00
|
|
|
Name: "clients",
|
|
|
|
Aliases: []string{"client"},
|
|
|
|
Usage: "Client credentials subcommands",
|
2023-12-12 18:42:50 +01:00
|
|
|
Subcommands: []cli.Command{
|
|
|
|
ClientsListCommand,
|
|
|
|
ClientsAddCommand,
|
|
|
|
ClientsShowCommand,
|
|
|
|
ClientsModCommand,
|
|
|
|
ClientsRemoveCommand,
|
|
|
|
ClientsResetCommand,
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
|
|
|
// ClientAddFlags specifies the "photoprism client add" command flags.
|
|
|
|
var ClientAddFlags = []cli.Flag{
|
2024-01-29 13:54:50 +01:00
|
|
|
cli.StringFlag{
|
|
|
|
Name: "id",
|
|
|
|
Usage: ClientIdUsage,
|
|
|
|
Hidden: true,
|
|
|
|
},
|
2023-12-12 18:42:50 +01:00
|
|
|
cli.StringFlag{
|
|
|
|
Name: "name, n",
|
|
|
|
Usage: ClientNameUsage,
|
|
|
|
},
|
2024-01-18 16:53:05 +01:00
|
|
|
cli.StringFlag{
|
|
|
|
Name: "role, r",
|
|
|
|
Usage: ClientRoleUsage,
|
|
|
|
Value: acl.RoleClient.String(),
|
|
|
|
},
|
2023-12-12 18:42:50 +01:00
|
|
|
cli.StringFlag{
|
|
|
|
Name: "scope, s",
|
|
|
|
Usage: ClientAuthScope,
|
|
|
|
},
|
2024-01-19 14:41:08 +01:00
|
|
|
cli.StringFlag{
|
|
|
|
Name: "provider, p",
|
|
|
|
Usage: ClientAuthProvider,
|
|
|
|
Value: authn.ProviderClientCredentials.String(),
|
|
|
|
Hidden: true,
|
|
|
|
},
|
2024-01-13 16:27:05 +01:00
|
|
|
cli.StringFlag{
|
|
|
|
Name: "method, m",
|
|
|
|
Usage: ClientAuthMethod,
|
|
|
|
Value: authn.MethodOAuth2.String(),
|
|
|
|
Hidden: true,
|
|
|
|
},
|
2023-12-12 18:42:50 +01:00
|
|
|
cli.Int64Flag{
|
|
|
|
Name: "expires, e",
|
|
|
|
Usage: ClientAuthExpires,
|
2024-01-29 13:54:50 +01:00
|
|
|
Value: unix.Day,
|
2023-12-12 18:42:50 +01:00
|
|
|
},
|
|
|
|
cli.Int64Flag{
|
|
|
|
Name: "tokens, t",
|
|
|
|
Usage: ClientAuthTokens,
|
2024-01-18 16:53:05 +01:00
|
|
|
Value: 10,
|
2023-12-12 18:42:50 +01:00
|
|
|
},
|
2024-01-29 13:54:50 +01:00
|
|
|
cli.StringFlag{
|
|
|
|
Name: "secret",
|
|
|
|
Usage: ClientSecretUsage,
|
|
|
|
Hidden: true,
|
|
|
|
},
|
2023-12-12 18:42:50 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
// ClientModFlags specifies the "photoprism client mod" command flags.
|
|
|
|
var ClientModFlags = []cli.Flag{
|
|
|
|
cli.StringFlag{
|
|
|
|
Name: "name, n",
|
|
|
|
Usage: ClientNameUsage,
|
|
|
|
},
|
2024-01-18 16:53:05 +01:00
|
|
|
cli.StringFlag{
|
|
|
|
Name: "role, r",
|
|
|
|
Usage: ClientRoleUsage,
|
|
|
|
Value: acl.RoleClient.String(),
|
|
|
|
},
|
2023-12-12 18:42:50 +01:00
|
|
|
cli.StringFlag{
|
|
|
|
Name: "scope, s",
|
|
|
|
Usage: ClientAuthScope,
|
|
|
|
},
|
2024-01-19 14:41:08 +01:00
|
|
|
cli.StringFlag{
|
|
|
|
Name: "provider, p",
|
|
|
|
Usage: ClientAuthProvider,
|
|
|
|
Value: authn.ProviderClientCredentials.String(),
|
|
|
|
Hidden: true,
|
|
|
|
},
|
2024-01-13 16:27:05 +01:00
|
|
|
cli.StringFlag{
|
|
|
|
Name: "method, m",
|
|
|
|
Usage: ClientAuthMethod,
|
|
|
|
Value: authn.MethodOAuth2.String(),
|
|
|
|
Hidden: true,
|
|
|
|
},
|
2023-12-12 18:42:50 +01:00
|
|
|
cli.Int64Flag{
|
|
|
|
Name: "expires, e",
|
|
|
|
Usage: ClientAuthExpires,
|
2024-01-29 13:54:50 +01:00
|
|
|
Value: unix.Day,
|
2023-12-12 18:42:50 +01:00
|
|
|
},
|
|
|
|
cli.Int64Flag{
|
|
|
|
Name: "tokens, t",
|
|
|
|
Usage: ClientAuthTokens,
|
2024-01-29 13:54:50 +01:00
|
|
|
Value: 10,
|
|
|
|
},
|
|
|
|
cli.StringFlag{
|
|
|
|
Name: "secret",
|
|
|
|
Usage: ClientSecretUsage,
|
|
|
|
Hidden: true,
|
2023-12-12 18:42:50 +01:00
|
|
|
},
|
|
|
|
cli.BoolFlag{
|
2024-01-29 13:54:50 +01:00
|
|
|
Name: "regenerate",
|
2023-12-12 18:42:50 +01:00
|
|
|
Usage: ClientRegenerateSecret,
|
|
|
|
},
|
|
|
|
cli.BoolFlag{
|
|
|
|
Name: "enable",
|
|
|
|
Usage: ClientEnable,
|
|
|
|
},
|
2024-01-18 16:53:05 +01:00
|
|
|
cli.BoolFlag{
|
|
|
|
Name: "disable",
|
|
|
|
Usage: ClientDisable,
|
|
|
|
},
|
2023-12-12 18:42:50 +01:00
|
|
|
}
|