-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
moving from toml config to json config
- Loading branch information
1 parent
a08405d
commit f754085
Showing
7 changed files
with
357 additions
and
218 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -31,3 +31,4 @@ secrets.txt | |
__debug_bin1949266242 | ||
|
||
/zot | ||
/runtime |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
{ | ||
"auth": { | ||
"name": "admin", | ||
"registry": "https://registry.bupd.xyz", | ||
"secret": "Harbor12345" | ||
}, | ||
"bring_own_registry": false, | ||
"ground_control_url": "http://localhost:8080", | ||
"log_level": "info", | ||
"own_registry_adr": "127.0.0.1", | ||
"own_registry_port": "8585", | ||
"states": ["https://registry.bupd.xyz/satellite/group10/state:latest"], | ||
"url_or_file": "https://registry.bupd.xyz", | ||
"zotconfigpath": "./registry/config.json" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,193 +1,185 @@ | ||
package config | ||
|
||
import ( | ||
"fmt" | ||
"os" | ||
|
||
"github.com/joho/godotenv" | ||
"github.com/spf13/viper" | ||
) | ||
|
||
var AppConfig *Config | ||
|
||
type Config struct { | ||
log_level string | ||
own_registry bool | ||
own_registry_adr string | ||
own_registry_port string | ||
zot_config_path string | ||
input string | ||
zot_url string | ||
registry string | ||
repository string | ||
user_input string | ||
scheme string | ||
api_version string | ||
image string | ||
harbor_password string | ||
harbor_username string | ||
env string | ||
use_unsecure bool | ||
remote_registry_url string | ||
group_name string | ||
state_artifact_name string | ||
state_fetch_period string | ||
} | ||
|
||
func GetLogLevel() string { | ||
return AppConfig.log_level | ||
} | ||
|
||
func GetOwnRegistry() bool { | ||
return AppConfig.own_registry | ||
} | ||
|
||
func GetOwnRegistryAdr() string { | ||
return AppConfig.own_registry_adr | ||
} | ||
|
||
func GetOwnRegistryPort() string { | ||
return AppConfig.own_registry_port | ||
} | ||
|
||
func GetZotConfigPath() string { | ||
return AppConfig.zot_config_path | ||
} | ||
|
||
func GetInput() string { | ||
return AppConfig.input | ||
} | ||
|
||
func SetZotURL(url string) { | ||
AppConfig.zot_url = url | ||
} | ||
|
||
func GetZotURL() string { | ||
return AppConfig.zot_url | ||
} | ||
|
||
func SetRegistry(registry string) { | ||
AppConfig.registry = registry | ||
} | ||
|
||
func GetRegistry() string { | ||
return AppConfig.registry | ||
} | ||
|
||
func SetRepository(repository string) { | ||
AppConfig.repository = repository | ||
} | ||
|
||
func GetRepository() string { | ||
return AppConfig.repository | ||
} | ||
|
||
func SetUserInput(user_input string) { | ||
AppConfig.user_input = user_input | ||
} | ||
|
||
func GetUserInput() string { | ||
return AppConfig.user_input | ||
} | ||
|
||
func SetScheme(scheme string) { | ||
AppConfig.scheme = scheme | ||
} | ||
|
||
func GetScheme() string { | ||
return AppConfig.scheme | ||
} | ||
|
||
func SetAPIVersion(api_version string) { | ||
AppConfig.api_version = api_version | ||
} | ||
|
||
func GetAPIVersion() string { | ||
return AppConfig.api_version | ||
} | ||
|
||
func SetImage(image string) { | ||
AppConfig.image = image | ||
} | ||
|
||
func GetImage() string { | ||
return AppConfig.image | ||
} | ||
|
||
func UseUnsecure() bool { | ||
return AppConfig.use_unsecure | ||
} | ||
|
||
func GetHarborPassword() string { | ||
return AppConfig.harbor_password | ||
} | ||
|
||
func GetHarborUsername() string { | ||
return AppConfig.harbor_username | ||
} | ||
|
||
func SetRemoteRegistryURL(url string) { | ||
AppConfig.remote_registry_url = url | ||
} | ||
|
||
func GetRemoteRegistryURL() string { | ||
return AppConfig.remote_registry_url | ||
} | ||
|
||
func GetGroupName() string { | ||
return AppConfig.group_name | ||
} | ||
|
||
func GetStateArtifactName() string { | ||
return AppConfig.state_artifact_name | ||
} | ||
|
||
func GetStateFetchPeriod() string { | ||
return AppConfig.state_fetch_period | ||
} | ||
|
||
func LoadConfig() (*Config, error) { | ||
viper.SetConfigName("config") | ||
viper.SetConfigType("toml") | ||
viper.AddConfigPath(".") | ||
if err := viper.ReadInConfig(); err != nil { | ||
return nil, fmt.Errorf("error reading config file at path '%s': %w", viper.ConfigFileUsed(), err) | ||
} | ||
|
||
// Load environment and start satellite | ||
if err := godotenv.Load(); err != nil { | ||
return &Config{}, fmt.Errorf("error loading .env file: %w", err) | ||
} | ||
var use_unsecure bool | ||
if os.Getenv("USE_UNSECURE") == "true" { | ||
use_unsecure = true | ||
} else { | ||
use_unsecure = false | ||
} | ||
|
||
return &Config{ | ||
log_level: viper.GetString("log_level"), | ||
own_registry: viper.GetBool("bring_own_registry"), | ||
own_registry_adr: viper.GetString("own_registry_adr"), | ||
own_registry_port: viper.GetString("own_registry_port"), | ||
zot_config_path: viper.GetString("zotConfigPath"), | ||
input: viper.GetString("url_or_file"), | ||
harbor_password: os.Getenv("HARBOR_PASSWORD"), | ||
harbor_username: os.Getenv("HARBOR_USERNAME"), | ||
env: os.Getenv("ENV"), | ||
zot_url: os.Getenv("ZOT_URL"), | ||
use_unsecure: use_unsecure, | ||
group_name: os.Getenv("GROUP_NAME"), | ||
state_artifact_name: os.Getenv("STATE_ARTIFACT_NAME"), | ||
state_fetch_period: os.Getenv("STATE_FETCH_PERIOD"), | ||
}, nil | ||
} | ||
|
||
func InitConfig() error { | ||
var err error | ||
AppConfig, err = LoadConfig() | ||
if err != nil { | ||
return err | ||
} | ||
return nil | ||
} | ||
// import ( | ||
// "fmt" | ||
// "os" | ||
|
||
// "github.com/joho/godotenv" | ||
// "github.com/spf13/viper" | ||
// ) | ||
|
||
// var AppConfig *Config | ||
|
||
// type Config struct { | ||
// log_level string | ||
// own_registry bool | ||
// own_registry_adr string | ||
// own_registry_port string | ||
// zot_config_path string | ||
// input string | ||
// zot_url string | ||
// registry string | ||
// repository string | ||
// user_input string | ||
// scheme string | ||
// api_version string | ||
// image string | ||
// harbor_password string | ||
// harbor_username string | ||
// env string | ||
// use_unsecure bool | ||
// remote_registry_url string | ||
// group_name string | ||
// state_artifact_name string | ||
// state_fetch_period string | ||
// } | ||
|
||
// func GetLogLevel() string { | ||
// return AppConfig.log_level | ||
// } | ||
|
||
// func GetOwnRegistry() bool { | ||
// return AppConfig.own_registry | ||
// } | ||
|
||
// func GetOwnRegistryAdr() string { | ||
// return AppConfig.own_registry_adr | ||
// } | ||
|
||
// func GetOwnRegistryPort() string { | ||
// return AppConfig.own_registry_port | ||
// } | ||
|
||
// func GetZotConfigPath() string { | ||
// return AppConfig.zot_config_path | ||
// } | ||
|
||
// func GetInput() string { | ||
// return AppConfig.input | ||
// } | ||
|
||
// func SetZotURL(url string) { | ||
// AppConfig.zot_url = url | ||
// } | ||
|
||
// func GetZotURL() string { | ||
// return AppConfig.zot_url | ||
// } | ||
|
||
// func SetRegistry(registry string) { | ||
// AppConfig.registry = registry | ||
// } | ||
|
||
// func GetRegistry() string { | ||
// return AppConfig.registry | ||
// } | ||
|
||
// func SetRepository(repository string) { | ||
// AppConfig.repository = repository | ||
// } | ||
|
||
// func GetRepository() string { | ||
// return AppConfig.repository | ||
// } | ||
|
||
// func SetUserInput(user_input string) { | ||
// AppConfig.user_input = user_input | ||
// } | ||
|
||
// func GetUserInput() string { | ||
// return AppConfig.user_input | ||
// } | ||
|
||
// func SetScheme(scheme string) { | ||
// AppConfig.scheme = scheme | ||
// } | ||
|
||
// func GetScheme() string { | ||
// return AppConfig.scheme | ||
// } | ||
|
||
// func SetAPIVersion(api_version string) { | ||
// AppConfig.api_version = api_version | ||
// } | ||
|
||
// func GetAPIVersion() string { | ||
// return AppConfig.api_version | ||
// } | ||
|
||
// func SetImage(image string) { | ||
// AppConfig.image = image | ||
// } | ||
|
||
// func GetImage() string { | ||
// return AppConfig.image | ||
// } | ||
|
||
// func UseUnsecure() bool { | ||
// return AppConfig.use_unsecure | ||
// } | ||
|
||
// func GetHarborPassword() string { | ||
// return AppConfig.harbor_password | ||
// } | ||
|
||
// func GetHarborUsername() string { | ||
// return AppConfig.harbor_username | ||
// } | ||
|
||
// func SetRemoteRegistryURL(url string) { | ||
// AppConfig.remote_registry_url = url | ||
// } | ||
|
||
// func GetRemoteRegistryURL() string { | ||
// return AppConfig.remote_registry_url | ||
// } | ||
|
||
// func GetGroupName() string { | ||
// return AppConfig.group_name | ||
// } | ||
|
||
// func GetStateArtifactName() string { | ||
// return AppConfig.state_artifact_name | ||
// } | ||
|
||
// func GetStateFetchPeriod() string { | ||
// return AppConfig.state_fetch_period | ||
// } | ||
|
||
// func LoadConfig() (*Config, error) { | ||
// viper.SetConfigName("config") | ||
// viper.SetConfigType("toml") | ||
// viper.AddConfigPath(".") | ||
// if err := viper.ReadInConfig(); err != nil { | ||
// return nil, fmt.Errorf("error reading config file at path '%s': %w", viper.ConfigFileUsed(), err) | ||
// } | ||
|
||
// // Load environment and start satellite | ||
// if err := godotenv.Load(); err != nil { | ||
// return &Config{}, fmt.Errorf("error loading .env file: %w", err) | ||
// } | ||
// var use_unsecure bool | ||
// if os.Getenv("USE_UNSECURE") == "true" { | ||
// use_unsecure = true | ||
// } else { | ||
// use_unsecure = false | ||
// } | ||
|
||
// return &Config{ | ||
// log_level: viper.GetString("log_level"), | ||
// own_registry: viper.GetBool("bring_own_registry"), | ||
// own_registry_adr: viper.GetString("own_registry_adr"), | ||
// own_registry_port: viper.GetString("own_registry_port"), | ||
// zot_config_path: viper.GetString("zotConfigPath"), | ||
// input: viper.GetString("url_or_file"), | ||
// harbor_password: os.Getenv("HARBOR_PASSWORD"), | ||
// harbor_username: os.Getenv("HARBOR_USERNAME"), | ||
// env: os.Getenv("ENV"), | ||
// zot_url: os.Getenv("ZOT_URL"), | ||
// use_unsecure: use_unsecure, | ||
// group_name: os.Getenv("GROUP_NAME"), | ||
// state_artifact_name: os.Getenv("STATE_ARTIFACT_NAME"), | ||
// state_fetch_period: os.Getenv("STATE_FETCH_PERIOD"), | ||
// }, nil | ||
// } | ||
|
Oops, something went wrong.