From 562c376c682b6a8af7f7f4ce1145211a5eff9015 Mon Sep 17 00:00:00 2001 From: Willy Kloucek Date: Wed, 20 Oct 2021 11:35:05 +0200 Subject: [PATCH] fix identifier-registration.yaml creation --- idp/pkg/service/v0/service.go | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) diff --git a/idp/pkg/service/v0/service.go b/idp/pkg/service/v0/service.go index 3de472e8a6..92586ab922 100644 --- a/idp/pkg/service/v0/service.go +++ b/idp/pkg/service/v0/service.go @@ -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 }