Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,14 @@ func main() {
global.Logger = logging.SetupLogging()
logging.WriteBackintInfo(global.Logger)

// Checking if the input file contains TOOLOPTION
if config.InputFileContainsTooloption(global.InputFileContent) {
global.Logger.Warning(fmt.Sprintf(
"%s specified in input file."+
" Option is not supported by backint agent.", config.TOOLOPTION,
))
}

// Initializing the variable which holds the messages to print out
// These messages must have a pre-defined format for the HANA system
// to recognize the results of the functions.
Expand Down
6 changes: 6 additions & 0 deletions utils/backint/inquire.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import (
"sort"
"strings"

"github.com/ibm-cloud/ibm-sap-hana-backint-cos/utils/config"
"github.com/ibm-cloud/ibm-sap-hana-backint-cos/utils/cos"
"github.com/ibm-cloud/ibm-sap-hana-backint-cos/utils/global"
"github.com/ibm-cloud/ibm-sap-hana-backint-cos/utils/logging"
Expand Down Expand Up @@ -96,6 +97,11 @@ func Inquire(
)
}
}

case config.TOOLOPTION:
// Ignoring TOOLOPTION
continue

default:
// Wrong keyword specified in input file
global.Logger.Error(
Expand Down
31 changes: 14 additions & 17 deletions utils/config/builder.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,6 @@ func buildBasicConfig(
configFilename string,
) []Default {
configParms := readConfigfile(configFilename)
configParms = addConfigParmsFromTooloption(configParms)
configuration := updateWithConfigValues(configParms)
return configuration
}
Expand Down Expand Up @@ -99,22 +98,6 @@ func readConfigfile(filename string) []ConfigParameter {
return validateKeysInSections(parmsFromConfig)
}

/*
Adding config parm from input file if TOOLOPTION is used as keyword
*/
func addConfigParmsFromTooloption(
parmsFromConfig []ConfigParameter,
) []ConfigParameter {

for _, inputKeyword := range global.InputFileContent {
if inputKeyword.Keyword != "TOOLOPTION" {
continue
}
// TODO -> issue #20
}
return parmsFromConfig
}

/*
Updating the internal configuration with the values from config file
*/
Expand Down Expand Up @@ -233,3 +216,17 @@ func getChunksizeSizeAndUnit(chunksize string) (string, string) {

return size, unitU
}

/*
Checking if TOOLOPTION is specified in input file
*/
func InputFileContainsTooloption(
inputFileContent []global.InputFileContentT,
) bool {
for _, inputKeyword := range inputFileContent {
if inputKeyword.Keyword == TOOLOPTION {
return true
}
}
return false
}
11 changes: 11 additions & 0 deletions utils/config/constants.go
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,11 @@ const (
AUTH_APIKEY string = "apikey"
)

// Unsupported keywords in inputfile
const (
TOOLOPTION = "TOOLOPTION"
)

// File validation values
const (
FILEOK = 0
Expand All @@ -84,3 +89,9 @@ const (
FILEMUSTEXIST = true
FILENOTEXIST = false
)

// Validation message prefixes
const (
VALIDATION_OK = "OK"
VALIDATION_ERROR = "ERROR"
)
48 changes: 34 additions & 14 deletions utils/config/validation.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,14 @@ func CheckParameters() int {
)

for _, m := range checkParmMessages {
// In some cases (unknown key or key in wrong section) the validation during a
// hdbbackint agent call does not produce an error. These keys and their values are ignored.
// In case of argument -check the agent should return an error.
// To prevent side effects regarding the backint functionality we
// check here the output of the validation process.
if strings.Contains(m, VALIDATION_ERROR) {
success = false
}
fmt.Println(m)
}

Expand Down Expand Up @@ -104,17 +112,18 @@ func validateSections(sections []string) {
found = true
if global.Args.CheckParms {
checkParmMessages = append(checkParmMessages,
fmt.Sprintf("\tOK: Section %s is valid.", section),
fmt.Sprintf("\t%s: Section %s is valid.", VALIDATION_OK, section),
)
}
}
}

if !found {
errMsg := fmt.Sprintf(
"ERROR: You specified the section '%s',"+
"%s: You specified the section '%s',"+
" but it is not part of the hdbbackint configuration. "+
"All parameters specified in this section are ignored.",
VALIDATION_ERROR,
section,
)
if global.Args.CheckParms {
Expand Down Expand Up @@ -147,9 +156,10 @@ func validateKeysInSections(parms []ConfigParameter) []ConfigParameter {
if keyFromFile == d.key {
found = true
if sectionFromFile != d.section {
errMsg := fmt.Sprintf("ERROR: You specified '%s'"+
errMsg := fmt.Sprintf("%s: You specified '%s'"+
" in section '%s', but key belongs to section %s."+
" The value of '%s' will be ignored.",
VALIDATION_ERROR,
keyFromFile,
sectionFromFile,
d.section,
Expand All @@ -167,7 +177,8 @@ func validateKeysInSections(parms []ConfigParameter) []ConfigParameter {
checkParmMessages = append(
checkParmMessages,
fmt.Sprintf(
"\tOK: '%s' specified in correct section",
"\t%s: '%s' specified in correct section",
VALIDATION_OK,
keyFromFile),
)
}
Expand All @@ -176,9 +187,10 @@ func validateKeysInSections(parms []ConfigParameter) []ConfigParameter {
}
}
if !found {
errMsg := fmt.Sprintf("ERROR: You specified '%s'"+
errMsg := fmt.Sprintf("%s: You specified '%s'"+
" in section '%s', but the key is unknown."+
" The value of '%s' will be ignored.",
VALIDATION_ERROR,
keyFromFile,
sectionFromFile,
keyFromFile,
Expand Down Expand Up @@ -221,7 +233,8 @@ func (cp Default) validateMandatory() {
if global.Args.CheckParms {
checkParmMessages = append(checkParmMessages,
fmt.Sprintf(
"\tOK: Mandatory parameter '%s' exists.",
"\t%s: Mandatory parameter '%s' exists.",
VALIDATION_OK,
cp.key,
))
}
Expand Down Expand Up @@ -495,15 +508,19 @@ Validating object lock retention
func validateLockRetention(basicConfig []Default) {
if isObjectLockRetentionMode(basicConfig) {
if !isObjectLockRetentionPeriod(basicConfig) {
message := "ERROR: You specified 'object_lock_retention_mode = cmp', "
message += "but no 'object_lock_retention_period' is specified."
message := fmt.Sprintf("%s: You specified 'object_lock_retention_mode = cmp', "+
"but no 'object_lock_retention_period' is specified.",
VALIDATION_ERROR,
)
Default{}.addInvalidValueMsg(message)
}
} else {
if isObjectLockRetentionPeriod(basicConfig) {
message := "ERROR: You did not specify 'object_lock_retention_mode' "
message += "or 'object_lock_retention_mode' is set to 'None', "
message += "but 'object_lock_retention_period' is specified.\n"
message := fmt.Sprintf("%s: You did not specify 'object_lock_retention_mode' "+
"or 'object_lock_retention_mode' is set to 'None', "+
"but 'object_lock_retention_period' is specified.\n",
VALIDATION_ERROR,
)
Default{}.addInvalidValueMsg(message)
}
}
Expand Down Expand Up @@ -566,9 +583,10 @@ func isValueInRange(value int, min int, max int) bool {
Adding error message for missing mandatory parameter
*/
func (cp Default) addMissingMandatoryMsg() {
message := fmt.Sprintf("ERROR: You did not specify a value"+
message := fmt.Sprintf("%s: You did not specify a value"+
" for the mandatory parameter"+
" '%s'.",
VALIDATION_ERROR,
cp.key,
)
if global.Args.CheckParms {
Expand All @@ -588,7 +606,8 @@ func (cp Default) addInvalidValueMsg(msg string) {
message := ""
if cp.configValue != "" && cp.key != "" {
message = fmt.Sprintf(
"ERROR: '%s': the value '%s' you specified is invalid. ",
"%s: '%s': the value '%s' you specified is invalid. ",
VALIDATION_ERROR,
cp.key,
cp.configValue,
)
Expand All @@ -611,8 +630,9 @@ func addOkMessage(key string) {

checkParmMessages = append(checkParmMessages,
fmt.Sprintf(
"\tOK: Parameter '%s' exists"+
"\t%s: Parameter '%s' exists"+
" and its value is valid.",
VALIDATION_OK,
key,
))
}
Expand Down