fix identifier-registration.yaml creation
This commit is contained in:
1 file changed
+10
-7
@@ -7,6 +7,7 @@ import (
|
|||||||
"io/ioutil"
|
"io/ioutil"
|
||||||
"net/http"
|
"net/http"
|
||||||
"os"
|
"os"
|
||||||
|
"path"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
"github.com/go-chi/chi/v5"
|
"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")
|
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")
|
logger.Fatal().Err(err).Msg("could not create default config")
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -68,14 +69,16 @@ func NewService(opts ...Option) Service {
|
|||||||
return svc
|
return svc
|
||||||
}
|
}
|
||||||
|
|
||||||
func createConfigsIfNotExist(assets http.FileSystem, ocisURL string) error {
|
func createConfigsIfNotExist(assets http.FileSystem, filePath, ocisURL string) error {
|
||||||
if _, err := os.Stat("./config"); os.IsNotExist(err) {
|
|
||||||
if err := os.Mkdir("./config", 0700); err != nil {
|
folder := path.Dir(filePath)
|
||||||
|
if _, err := os.Stat(folder); os.IsNotExist(err) {
|
||||||
|
if err := os.Mkdir(folder, 0700); err != nil {
|
||||||
return err
|
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")
|
defaultConf, err := assets.Open("/identifier-registration.yaml")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
@@ -83,7 +86,7 @@ func createConfigsIfNotExist(assets http.FileSystem, ocisURL string) error {
|
|||||||
|
|
||||||
defer defaultConf.Close()
|
defer defaultConf.Close()
|
||||||
|
|
||||||
confOnDisk, err := os.Create("./config/identifier-registration.yaml")
|
confOnDisk, err := os.Create(filePath)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
@@ -98,7 +101,7 @@ func createConfigsIfNotExist(assets http.FileSystem, ocisURL string) error {
|
|||||||
// replace placeholder {{OCIS_URL}} with https://localhost:9200 / correct host
|
// replace placeholder {{OCIS_URL}} with https://localhost:9200 / correct host
|
||||||
conf = []byte(strings.ReplaceAll(string(conf), "{{OCIS_URL}}", strings.TrimRight(ocisURL, "/")))
|
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 {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in new issue
Block a user