Compare commits

..

No commits in common. "db665a30fa9c9100760fd4f211d9e3d8359e923e" and "c8958a8f4441f6a0b6eed08359ca0822d518a2d2" have entirely different histories.

4 changed files with 12 additions and 34 deletions

View file

@ -51,8 +51,6 @@ The rest of the configuration is handled through environment variables
# Can be debug,info,warning,error # Can be debug,info,warning,error
LOG_LEVEL = "info" LOG_LEVEL = "info"
ISSUER = "http://localhost"
# Can be net,unix # Can be net,unix
SERVER_MODE = "net" SERVER_MODE = "net"
SERVER_HOST = "0.0.0.0" SERVER_HOST = "0.0.0.0"

View file

@ -4,17 +4,15 @@ import (
"fmt" "fmt"
"git.faercol.me/faercol/polyculeconnect/polyculeconnect/cmd/utils" "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" "git.faercol.me/faercol/polyculeconnect/polyculeconnect/services/backend"
"github.com/spf13/cobra" "github.com/spf13/cobra"
) )
var ( var (
backendID string backendID string
backendName string backendName string
backendIssuer string backendIssuer string
backendClientID string
backendClientSecret string
) )
var backendAddCmd = &cobra.Command{ var backendAddCmd = &cobra.Command{
@ -27,9 +25,7 @@ Parameters to provide:
- name: Human readable name to represent the backend. It will be used by - name: Human readable name to represent the backend. It will be used by
the user in the authentication page to select a backend during the user in the authentication page to select a backend during
authentication authentication
- issuer: Full hostname of the OIDC provider, e.g. 'https://github.com' - 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`,
Run: func(cmd *cobra.Command, args []string) { Run: func(cmd *cobra.Command, args []string) {
addNewBackend() addNewBackend()
}, },
@ -37,20 +33,17 @@ Parameters to provide:
func addNewBackend() { func addNewBackend() {
c := utils.InitConfig("") c := utils.InitConfig("")
logger.Init(c.LogLevel)
s := utils.InitStorage(c) s := utils.InitStorage(c)
if backendClientID == "" { clientID, clientSecret, err := services.GenerateClientIDSecret()
utils.Fail("Empty client ID") if err != nil {
} utils.Failf("Failed to generate client id or secret: %s", err.Error())
if backendClientSecret == "" {
utils.Fail("Empty client secret")
} }
backendConf := backend.BackendConfig{ backendConf := backend.BackendConfig{
Issuer: backendIssuer, Issuer: backendIssuer,
ClientID: backendClientID, ClientID: clientID,
ClientSecret: backendClientSecret, ClientSecret: clientSecret,
RedirectURI: c.RedirectURI(), RedirectURI: c.RedirectURI(),
ID: backendID, ID: backendID,
Name: backendName, Name: backendName,
@ -60,6 +53,8 @@ func addNewBackend() {
} }
fmt.Printf("New backend %s added.\n", backendName) fmt.Printf("New backend %s added.\n", backendName)
printProperty("Client ID", clientID)
printProperty("Client secret", clientSecret)
} }
func init() { 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(&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(&backendName, "name", "n", "", "Name to represent the backend")
backendAddCmd.Flags().StringVarP(&backendIssuer, "issuer", "d", "", "Full hostname of 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")
} }

View file

@ -22,8 +22,6 @@ const (
varServerPort envVar = "SERVER_PORT" varServerPort envVar = "SERVER_PORT"
varServerSocket envVar = "SERVER_SOCK_PATH" varServerSocket envVar = "SERVER_SOCK_PATH"
varIssuer envVar = "ISSUER"
varStorageType envVar = "STORAGE_TYPE" varStorageType envVar = "STORAGE_TYPE"
varStorageFile envVar = "STORAGE_FILEPATH" varStorageFile envVar = "STORAGE_FILEPATH"
varStorageHost envVar = "STORAGE_HOST" varStorageHost envVar = "STORAGE_HOST"
@ -57,8 +55,6 @@ const (
defaultServerPort = 5000 defaultServerPort = 5000
defaultServerSocket = "" defaultServerSocket = ""
defaultIssuer = "locahost"
defaultStorageType = Memory defaultStorageType = Memory
defaultStorageFile = "./polyculeconnect.db" defaultStorageFile = "./polyculeconnect.db"
defaultStorageHost = "127.0.0.1" defaultStorageHost = "127.0.0.1"
@ -129,9 +125,6 @@ func (ac *AppConfig) UnmarshalJSON(data []byte) error {
return fmt.Errorf("failed to read JSON: %w", err) return fmt.Errorf("failed to read JSON: %w", err)
} }
ac.OpenConnectConfig = jsonConf.OpenConnectConfig ac.OpenConnectConfig = jsonConf.OpenConnectConfig
if ac.OpenConnectConfig == nil {
ac.OpenConnectConfig = &OpenConnectConfig{}
}
return nil return nil
} }
@ -152,8 +145,6 @@ func (ac *AppConfig) getConfFromEnv() {
ac.StorageConfig.Password = getStringFromEnv(varStoragePassword, defaultStoragePassword) ac.StorageConfig.Password = getStringFromEnv(varStoragePassword, defaultStoragePassword)
ac.StorageConfig.Ssl.CaFile = getStringFromEnv(varStorageSSLCaFile, defaultStorageSSLCaFile) ac.StorageConfig.Ssl.CaFile = getStringFromEnv(varStorageSSLCaFile, defaultStorageSSLCaFile)
ac.StorageConfig.Ssl.Mode = getStringFromEnv(varStorageSSLMode, defaultStorageSSLMode) ac.StorageConfig.Ssl.Mode = getStringFromEnv(varStorageSSLMode, defaultStorageSSLMode)
ac.OpenConnectConfig.Issuer = getStringFromEnv(varIssuer, defaultIssuer)
} }
func (ac *AppConfig) RedirectURI() string { func (ac *AppConfig) RedirectURI() string {
@ -163,7 +154,6 @@ func (ac *AppConfig) RedirectURI() string {
func New(filepath string) (*AppConfig, error) { func New(filepath string) (*AppConfig, error) {
var conf AppConfig var conf AppConfig
conf.StorageConfig = &StorageConfig{} conf.StorageConfig = &StorageConfig{}
conf.OpenConnectConfig = &OpenConnectConfig{}
content, err := os.ReadFile(filepath) content, err := os.ReadFile(filepath)
if err != nil { if err != nil {
if !errors.Is(err, fs.ErrNotExist) { if !errors.Is(err, fs.ErrNotExist) {

View file

@ -29,9 +29,6 @@ var defaultConfig = AppConfig{
CaFile string CaFile string
}{Mode: defaultStorageSSLMode, CaFile: defaultStorageSSLCaFile}, }{Mode: defaultStorageSSLMode, CaFile: defaultStorageSSLCaFile},
}, },
OpenConnectConfig: &OpenConnectConfig{
Issuer: defaultIssuer,
},
} }
func initJson(t *testing.T, content string) string { func initJson(t *testing.T, content string) string {