From 07d0e2bf58a2ae4cb18ded218979b18fb4ea6f57 Mon Sep 17 00:00:00 2001 From: Palaniappan R Date: Sat, 1 Feb 2025 03:38:01 +0530 Subject: [PATCH] ora: simplify consent and mode validation by removing redundant checks Signed-off-by: Palaniappan R --- src/ora/src/Ora.cc | 9 ++------- src/ora/src/Ora.tcl | 13 +++++++------ 2 files changed, 9 insertions(+), 13 deletions(-) diff --git a/src/ora/src/Ora.cc b/src/ora/src/Ora.cc index a7988093efc..4b326a05312 100644 --- a/src/ora/src/Ora.cc +++ b/src/ora/src/Ora.cc @@ -301,13 +301,7 @@ void Ora::setConsent(const char* consent) std::string consentFilePath = localDirPath + "/orassistant_consent.txt"; std::ofstream consentFile(consentFilePath); - // check if consent is y or n - if (std::string(consent) != "y" && std::string(consent) != "n") { - logger_->error( - utl::ORA, 115, "{} : Invalid consent value. Use 'y' or 'n'.", consent); - return; - } - + // the consent string is validated in Ora.i if (consentFile.is_open()) { consentFile << "consent: " << consent << "\n"; consentFile << "consent_version: " << consentVersion << "\n"; @@ -337,6 +331,7 @@ void Ora::setMode(const char* mode) std::string modeFilePath = localDirPath + "/orassistant_mode.txt"; std::ofstream modeFile(modeFilePath); + // the mode is validated in Ora.i if (modeFile.is_open()) { modeFile << mode; modeFile.close(); diff --git a/src/ora/src/Ora.tcl b/src/ora/src/Ora.tcl index 0b34f347c55..70738bcad3a 100644 --- a/src/ora/src/Ora.tcl +++ b/src/ora/src/Ora.tcl @@ -25,20 +25,21 @@ proc askbot { args } { ora::askbot [lindex $args 0] } - proc ora_init {arg1 {arg2 ""}} { if {$arg1 ni {"local" "cloud"}} { puts "ERROR: Invalid mode '$arg1'. Use 'local' or 'cloud'." - return; + return } ora::set_mode $arg1 - + if {$arg1 eq "cloud"} { + if {$arg2 ni {"y" "n"}} { + puts "ERROR: Invalid consent value '$arg2'. Use 'y' or 'n'." + return + } ora::set_consent $arg2 } elseif {$arg1 eq "local"} { ora::set_bothost $arg2 - } else { - puts "Invalid mode: $arg1" } -} +} \ No newline at end of file