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"
|
|
|
|
"github.com/photoprism/photoprism/internal/entity"
|
2024-01-13 16:27:05 +01:00
|
|
|
"github.com/photoprism/photoprism/pkg/authn"
|
2023-12-12 18:42:50 +01:00
|
|
|
)
|
|
|
|
|
|
|
|
// Usage hints for the client management subcommands.
|
|
|
|
const (
|
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)"
|
|
|
|
ClientAuthMethod = "client authentication `METHOD`"
|
|
|
|
ClientAuthExpires = "authentication `LIFETIME` in seconds, after which a new access token must be requested (-1 to disable the limit)"
|
|
|
|
ClientAuthTokens = "maximum 'NUMBER' of access tokens that the client can request (-1 to disable the limit)"
|
2023-12-12 18:42:50 +01:00
|
|
|
ClientRegenerateSecret = "generate a new client secret and display it"
|
2024-01-18 16:53:05 +01:00
|
|
|
ClientEnable = "enable client authentication if disabled"
|
|
|
|
ClientDisable = "disable client authentication"
|
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{
|
|
|
|
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-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-18 16:53:05 +01:00
|
|
|
Value: entity.UnixDay,
|
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
|
|
|
},
|
|
|
|
}
|
|
|
|
|
|
|
|
// 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-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,
|
|
|
|
},
|
|
|
|
cli.Int64Flag{
|
|
|
|
Name: "tokens, t",
|
|
|
|
Usage: ClientAuthTokens,
|
|
|
|
},
|
|
|
|
cli.BoolFlag{
|
|
|
|
Name: "regenerate-secret, r",
|
|
|
|
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
|
|
|
}
|