mirror of
https://github.com/opencloud-eu/opencloud.git
synced 2026-07-19 20:14:17 -04:00
Merge pull request #2648 from owncloud/fix_identifier_registration_yaml_creation
fix identifier-registration.yaml creation
This commit is contained in:
@@ -7,6 +7,7 @@ import (
|
||||
"io/ioutil"
|
||||
"net/http"
|
||||
"os"
|
||||
"path"
|
||||
"strings"
|
||||
|
||||
"github.com/go-chi/chi/v5"
|
||||
@@ -41,7 +42,7 @@ func NewService(opts ...Option) Service {
|
||||
logger.Fatal().Err(err).Msg("could not initialize env vars")
|
||||
}
|
||||
|
||||
if err := createConfigsIfNotExist(assetVFS, options.Config.IDP.Iss); err != nil {
|
||||
if err := createConfigsIfNotExist(assetVFS, options.Config.IDP.IdentifierRegistrationConf, options.Config.IDP.Iss); err != nil {
|
||||
logger.Fatal().Err(err).Msg("could not create default config")
|
||||
}
|
||||
|
||||
@@ -68,14 +69,16 @@ func NewService(opts ...Option) Service {
|
||||
return svc
|
||||
}
|
||||
|
||||
func createConfigsIfNotExist(assets http.FileSystem, ocisURL string) error {
|
||||
if _, err := os.Stat("./config"); os.IsNotExist(err) {
|
||||
if err := os.Mkdir("./config", 0700); err != nil {
|
||||
func createConfigsIfNotExist(assets http.FileSystem, filePath, ocisURL string) error {
|
||||
|
||||
folder := path.Dir(filePath)
|
||||
if _, err := os.Stat(folder); os.IsNotExist(err) {
|
||||
if err := os.Mkdir(folder, 0700); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
|
||||
if _, err := os.Stat("./config/identifier-registration.yaml"); os.IsNotExist(err) {
|
||||
if _, err := os.Stat(filePath); os.IsNotExist(err) {
|
||||
defaultConf, err := assets.Open("/identifier-registration.yaml")
|
||||
if err != nil {
|
||||
return err
|
||||
@@ -83,7 +86,7 @@ func createConfigsIfNotExist(assets http.FileSystem, ocisURL string) error {
|
||||
|
||||
defer defaultConf.Close()
|
||||
|
||||
confOnDisk, err := os.Create("./config/identifier-registration.yaml")
|
||||
confOnDisk, err := os.Create(filePath)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
@@ -98,7 +101,7 @@ func createConfigsIfNotExist(assets http.FileSystem, ocisURL string) error {
|
||||
// replace placeholder {{OCIS_URL}} with https://localhost:9200 / correct host
|
||||
conf = []byte(strings.ReplaceAll(string(conf), "{{OCIS_URL}}", strings.TrimRight(ocisURL, "/")))
|
||||
|
||||
err = ioutil.WriteFile("./config/identifier-registration.yaml", conf, 0600)
|
||||
err = ioutil.WriteFile(filePath, conf, 0600)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user