Update configuration parameters #1

Closed
opened 2023-10-25 09:25:37 +02:00 by yc · 2 comments
Owner

Use Onion lib for configuring the software at startup like in oc-dicovery.

Use Onion lib for configuring the software at startup like in oc-dicovery.
yc added the
Kind/Feature
Priority/High
labels 2023-10-25 09:25:37 +02:00
pb was assigned by yc 2023-10-25 09:25:37 +02:00
root added this to the OpenCloud project 2023-10-25 21:16:44 +02:00
Owner

Added a function to handlle configuration from JSON file following the implementation with onion in oc-discovery :

  • check for a .json file in /etc/oc/[oc-module]
  • check for a .json file in the current directory

A conf file in the current directory will override the conf file in /etc/oc/..

Default value for URLs, if no key found in files or env, will be on localhost

models.GetConfig().OcCatalogUrl = o.GetStringDefault("oc-catalog", "localhost:49618")

Added a function to handlle configuration from JSON file following the implementation with onion in oc-discovery : - check for a .json file in /etc/oc/[oc-module] - check for a .json file in the current directory A conf file in the current directory will override the conf file in /etc/oc/.. Default value for URLs, if no key found in files or env, will be on *localhost* > models.GetConfig().OcCatalogUrl = o.GetStringDefault("oc-catalog", "localhost:49618")
pb added reference main 2023-10-26 10:53:03 +02:00
pb removed reference main 2023-10-26 10:53:06 +02:00
Owner

Modified the way the OC-CatalogAPI object is instancied.
It was previously constructed in an init() function that was executed before the conf files were retrieved as :

func init() {
	config := models.GetConfig()

	OCCatalogAPI = OCCatalog_cli.NewAPIClient(&OCCatalog_cli.Configuration{BasePath: "http://"+config.OcCatalogUrl+"/v1",
		DefaultHeader: map[string]string{
			"authorization": "",
		},
	})

}

We changed this to a normal function that is called in oc-search/main.go after retrieving the conf :

func main() {

	loadConfig()                                              <- HERE
	controllers.CreateOCCatalogAPI()  <- HERE

	beego.BConfig.WebConfig.Session.SessionOn = true
	beego.SetStaticPath("/favicon.ico", "/static/favicon.ico")
	beego.BConfig.WebConfig.DirectoryIndex = true
	beego.BConfig.WebConfig.StaticDir["/swagger"] = "swagger"

	beego.Run()
}
Modified the way the OC-CatalogAPI object is instancied. It was previously constructed in an init() function that was executed before the conf files were retrieved as : ``` func init() { config := models.GetConfig() OCCatalogAPI = OCCatalog_cli.NewAPIClient(&OCCatalog_cli.Configuration{BasePath: "http://"+config.OcCatalogUrl+"/v1", DefaultHeader: map[string]string{ "authorization": "", }, }) } ``` We changed this to a normal function that is called in oc-search/main.go after retrieving the conf : ``` func main() { loadConfig() <- HERE controllers.CreateOCCatalogAPI() <- HERE beego.BConfig.WebConfig.Session.SessionOn = true beego.SetStaticPath("/favicon.ico", "/static/favicon.ico") beego.BConfig.WebConfig.DirectoryIndex = true beego.BConfig.WebConfig.StaticDir["/swagger"] = "swagger" beego.Run() } ```
pb closed this issue 2023-10-26 10:57:20 +02:00
Sign in to join this conversation.
No Milestone
No project
No Assignees
2 Participants
Notifications
Due Date
The due date is invalid or out of range. Please use the format 'yyyy-mm-dd'.

No due date set.

Dependencies

No dependencies set.

Reference: core/deprecated-oc-search#1
No description provided.