Compare commits
No commits in common. "cd91ac0a0e57e9ff70d4123c46f05df7f8154587" and "c8958a8f4441f6a0b6eed08359ca0822d518a2d2" have entirely different histories.
cd91ac0a0e
...
c8958a8f44
2 changed files with 12 additions and 26 deletions
|
@ -4,7 +4,7 @@ import (
|
|||
"fmt"
|
||||
|
||||
"git.faercol.me/faercol/polyculeconnect/polyculeconnect/cmd/utils"
|
||||
"git.faercol.me/faercol/polyculeconnect/polyculeconnect/logger"
|
||||
"git.faercol.me/faercol/polyculeconnect/polyculeconnect/services"
|
||||
"git.faercol.me/faercol/polyculeconnect/polyculeconnect/services/backend"
|
||||
"github.com/spf13/cobra"
|
||||
)
|
||||
|
@ -13,8 +13,6 @@ var (
|
|||
backendID string
|
||||
backendName string
|
||||
backendIssuer string
|
||||
backendClientID string
|
||||
backendClientSecret string
|
||||
)
|
||||
|
||||
var backendAddCmd = &cobra.Command{
|
||||
|
@ -27,9 +25,7 @@ Parameters to provide:
|
|||
- name: Human readable name to represent the backend. It will be used by
|
||||
the user in the authentication page to select a backend during
|
||||
authentication
|
||||
- issuer: Full hostname of the OIDC provider, e.g. 'https://github.com'
|
||||
- client-id: OIDC Client ID for the backend
|
||||
- client-secret OIDC Client secret for the backend`,
|
||||
- issuer: Full hostname of the OIDC provider, e.g. 'https://github.com'`,
|
||||
Run: func(cmd *cobra.Command, args []string) {
|
||||
addNewBackend()
|
||||
},
|
||||
|
@ -37,20 +33,17 @@ Parameters to provide:
|
|||
|
||||
func addNewBackend() {
|
||||
c := utils.InitConfig("")
|
||||
logger.Init(c.LogLevel)
|
||||
s := utils.InitStorage(c)
|
||||
|
||||
if backendClientID == "" {
|
||||
utils.Fail("Empty client ID")
|
||||
}
|
||||
if backendClientSecret == "" {
|
||||
utils.Fail("Empty client secret")
|
||||
clientID, clientSecret, err := services.GenerateClientIDSecret()
|
||||
if err != nil {
|
||||
utils.Failf("Failed to generate client id or secret: %s", err.Error())
|
||||
}
|
||||
|
||||
backendConf := backend.BackendConfig{
|
||||
Issuer: backendIssuer,
|
||||
ClientID: backendClientID,
|
||||
ClientSecret: backendClientSecret,
|
||||
ClientID: clientID,
|
||||
ClientSecret: clientSecret,
|
||||
RedirectURI: c.RedirectURI(),
|
||||
ID: backendID,
|
||||
Name: backendName,
|
||||
|
@ -60,6 +53,8 @@ func addNewBackend() {
|
|||
}
|
||||
|
||||
fmt.Printf("New backend %s added.\n", backendName)
|
||||
printProperty("Client ID", clientID)
|
||||
printProperty("Client secret", clientSecret)
|
||||
}
|
||||
|
||||
func init() {
|
||||
|
@ -68,6 +63,4 @@ func init() {
|
|||
backendAddCmd.Flags().StringVarP(&backendID, "id", "i", "", "ID to identify the backend in the storage")
|
||||
backendAddCmd.Flags().StringVarP(&backendName, "name", "n", "", "Name to represent the backend")
|
||||
backendAddCmd.Flags().StringVarP(&backendIssuer, "issuer", "d", "", "Full hostname of the backend")
|
||||
backendAddCmd.Flags().StringVarP(&backendClientID, "client-id", "", "", "OIDC Client ID for the backend")
|
||||
backendAddCmd.Flags().StringVarP(&backendClientSecret, "client-secret", "", "", "OIDC Client secret for the backend")
|
||||
}
|
||||
|
|
|
@ -22,8 +22,6 @@ const (
|
|||
varServerPort envVar = "SERVER_PORT"
|
||||
varServerSocket envVar = "SERVER_SOCK_PATH"
|
||||
|
||||
varIssuer envVar = "ISSUER"
|
||||
|
||||
varStorageType envVar = "STORAGE_TYPE"
|
||||
varStorageFile envVar = "STORAGE_FILEPATH"
|
||||
varStorageHost envVar = "STORAGE_HOST"
|
||||
|
@ -57,8 +55,6 @@ const (
|
|||
defaultServerPort = 5000
|
||||
defaultServerSocket = ""
|
||||
|
||||
defaultIssuer = "locahost"
|
||||
|
||||
defaultStorageType = Memory
|
||||
defaultStorageFile = "./polyculeconnect.db"
|
||||
defaultStorageHost = "127.0.0.1"
|
||||
|
@ -149,8 +145,6 @@ func (ac *AppConfig) getConfFromEnv() {
|
|||
ac.StorageConfig.Password = getStringFromEnv(varStoragePassword, defaultStoragePassword)
|
||||
ac.StorageConfig.Ssl.CaFile = getStringFromEnv(varStorageSSLCaFile, defaultStorageSSLCaFile)
|
||||
ac.StorageConfig.Ssl.Mode = getStringFromEnv(varStorageSSLMode, defaultStorageSSLMode)
|
||||
|
||||
ac.OpenConnectConfig.Issuer = getStringFromEnv(varIssuer, defaultIssuer)
|
||||
}
|
||||
|
||||
func (ac *AppConfig) RedirectURI() string {
|
||||
|
@ -160,7 +154,6 @@ func (ac *AppConfig) RedirectURI() string {
|
|||
func New(filepath string) (*AppConfig, error) {
|
||||
var conf AppConfig
|
||||
conf.StorageConfig = &StorageConfig{}
|
||||
conf.OpenConnectConfig = &OpenConnectConfig{}
|
||||
content, err := os.ReadFile(filepath)
|
||||
if err != nil {
|
||||
if !errors.Is(err, fs.ErrNotExist) {
|
||||
|
|
Loading…
Reference in a new issue