Skip to content

Commit

Permalink
added config
Browse files Browse the repository at this point in the history
  • Loading branch information
Thenujan-Nagaratnam committed May 3, 2024
1 parent 62e0679 commit 501d506
Show file tree
Hide file tree
Showing 6 changed files with 28 additions and 1 deletion.
1 change: 1 addition & 0 deletions import-export-cli/cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,7 @@ func createConfigFiles() {
if !utils.IsFileExist(utils.MainConfigFilePath) {
var mainConfig = new(utils.MainConfig)
mainConfig.Config = utils.Config{HttpRequestTimeout: utils.DefaultHttpRequestTimeout,
MarketplaceAssistantThreadSize: utils.DefaultMarketplaceAssistantThreadSize,
ExportDirectory: utils.DefaultExportDirPath,
KubernetesMode: k8sUtils.DefaultKubernetesMode,
TokenType: utils.DefaultTokenType,
Expand Down
20 changes: 20 additions & 0 deletions import-export-cli/cmd/set.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ import (
)

var flagHttpRequestTimeout int
var flagMarketplaceAssistantThreadSize int
var flagExportDirectory string
var flagKubernetesMode string
var flagTLSRenegotiationMode string
Expand All @@ -47,6 +48,7 @@ const setCmdShortDesc = "Set configuration parameters, per API log levels or cor

const setCmdLongDesc = `Set configuration parameters. You can use one of the following flags
* --http-request-timeout <time-in-milli-seconds>
* --marketplace-assistant-thread-count <number-of-threads>
* --tls-renegotiation-mode <never|once|freely>
* --export-directory <path-to-directory-where-apis-should-be-saved>
* --vcs-deletion-enabled <enable-or-disable-project-deletion-via-vcs>
Expand All @@ -57,6 +59,7 @@ const setCmdLongDesc = `Set configuration parameters. You can use one of the fol
const setCmdExamples = utils.ProjectName + ` ` + SetCmdLiteral + ` --http-request-timeout 3600 --export-directory /home/user/exported-apis
` + utils.ProjectName + ` ` + SetCmdLiteral + ` --http-request-timeout 5000 --export-directory C:\Documents\exported
` + utils.ProjectName + ` ` + SetCmdLiteral + ` --http-request-timeout 5000
` + utils.ProjectName + ` ` + SetCmdLiteral + ` --marketplace-assistant-thread-count 5
` + utils.ProjectName + ` ` + SetCmdLiteral + ` --tls-renegotiation-mode freely
` + utils.ProjectName + ` ` + SetCmdLiteral + ` --vcs-deletion-enabled=true
` + utils.ProjectName + ` ` + SetCmdLiteral + ` --vcs-config-path /home/user/custom/vcs-config.yaml
Expand Down Expand Up @@ -91,6 +94,16 @@ func executeSetCmd(mainConfigFilePath string, cmd *cobra.Command) {
fmt.Println("Invalid input for flag --http-request-timeout")
}

if flagMarketplaceAssistantThreadSize > 0 {
//Check whether the provided Http time out value is not equal to default value
if flagMarketplaceAssistantThreadSize != configVars.Config.MarketplaceAssistantThreadSize {
fmt.Println("Marketplace Assistant Thread Size is set to : ", flagMarketplaceAssistantThreadSize)
}
configVars.Config.MarketplaceAssistantThreadSize = flagMarketplaceAssistantThreadSize
} else {
fmt.Println("Invalid input for flag --marketplace-assistant-thread-count")
}

//Change Export Directory path
if flagExportDirectory != "" && utils.IsValid(flagExportDirectory) {
//Check whether the provided export directory is not equal to default value
Expand Down Expand Up @@ -160,6 +173,7 @@ func init() {
RootCmd.AddCommand(SetCmd)

var defaultHttpRequestTimeout int
var defaultMarketplaceAssistantThreadSize int
var defaultExportDirectory string

// read current values in file to be passed into default values for flags below
Expand All @@ -169,12 +183,18 @@ func init() {
defaultHttpRequestTimeout = mainConfig.Config.HttpRequestTimeout
}

if mainConfig.Config.MarketplaceAssistantThreadSize != 0 {
defaultMarketplaceAssistantThreadSize = mainConfig.Config.MarketplaceAssistantThreadSize
}

if mainConfig.Config.ExportDirectory != "" {
defaultExportDirectory = mainConfig.Config.ExportDirectory
}

SetCmd.Flags().IntVar(&flagHttpRequestTimeout, "http-request-timeout", defaultHttpRequestTimeout,
"Timeout for HTTP Client")
SetCmd.Flags().IntVar(&flagMarketplaceAssistantThreadSize, "marketplace-assistant-thread-count", defaultMarketplaceAssistantThreadSize,
"No of threads to be used by Marketplace Assistant for parallel processing")
SetCmd.Flags().StringVar(&flagExportDirectory, "export-directory", defaultExportDirectory,
"Path to directory where APIs should be saved")
SetCmd.Flags().StringVar(&flagTLSRenegotiationMode, "tls-renegotiation-mode", utils.TLSRenegotiationNever,
Expand Down
2 changes: 1 addition & 1 deletion import-export-cli/impl/vectordbUploadAPIs.go
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ func UploadAPIs(credential credentials.Credential, cmdUploadEnvironment, authTok
go ProduceAPIPayloads(devPortalEndpoint, apiListQueue)

// consumer
numConsumers := 3
numConsumers := utils.MarketplaceAssistantThreadSize
var wg sync.WaitGroup
for i := 0; i < numConsumers; i++ {
wg.Add(1)
Expand Down
4 changes: 4 additions & 0 deletions import-export-cli/utils/configVars.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ import (
)

var HttpRequestTimeout = DefaultHttpRequestTimeout
var MarketplaceAssistantThreadSize = DefaultMarketplaceAssistantThreadSize
var Insecure bool
var ExportDirectory string

Expand Down Expand Up @@ -57,6 +58,9 @@ func SetConfigVars(mainConfigFilePath string) error {
HttpRequestTimeout = mainConfig.Config.HttpRequestTimeout
Logln(LogPrefixInfo + "Setting HttpTimeoutRequest to " + fmt.Sprint(mainConfig.Config.HttpRequestTimeout))

MarketplaceAssistantThreadSize = mainConfig.Config.MarketplaceAssistantThreadSize
Logln(LogPrefixInfo + "Setting MarketplaceAssistantThreadSize to " + fmt.Sprint(mainConfig.Config.MarketplaceAssistantThreadSize))

ExportDirectory = mainConfig.Config.ExportDirectory
Logln(LogPrefixInfo + "Setting ExportDirectory " + mainConfig.Config.ExportDirectory)

Expand Down
1 change: 1 addition & 0 deletions import-export-cli/utils/constants.go
Original file line number Diff line number Diff line change
Expand Up @@ -191,6 +191,7 @@ const SearchAndTag = "&"
// Other
const DefaultTokenValidityPeriod = 3600
const DefaultHttpRequestTimeout = 10000
const DefaultMarketplaceAssistantThreadSize = 3

// TLSRenegotiationNever : never negotiate
const TLSRenegotiationNever = "never"
Expand Down
1 change: 1 addition & 0 deletions import-export-cli/utils/structs.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ type MainConfig struct {

type Config struct {
HttpRequestTimeout int `yaml:"http_request_timeout"`
MarketplaceAssistantThreadSize int `yaml:"marketplace_assistant_thread_count"`
ExportDirectory string `yaml:"export_directory"`
KubernetesMode bool `yaml:"kubernetes_mode"`
TokenType string `yaml:"token_type"`
Expand Down

0 comments on commit 501d506

Please sign in to comment.