diff --git a/openapi/owanalytics.yaml b/openapi/owanalytics.yaml index b7ccb84..d8db87a 100644 --- a/openapi/owanalytics.yaml +++ b/openapi/owanalytics.yaml @@ -27,71 +27,13 @@ components: responses: NotFound: - description: The specified resource was not found. - content: - application/json: - schema: - properties: - ErrorCode: - type: integer - ErrorDetails: - type: string - ErrorDescription: - type: string - + $ref: 'https://github.com/Telecominfraproject/wlan-cloud-ucentralsec/blob/main/openpapi/owsec.yaml#/components/responses/NotFound' Unauthorized: - description: The requested does not have sufficient rights to perform the operation. - content: - application/json: - schema: - properties: - ErrorCode: - type: integer - enum: - - 0 # Success - - 1 # PASSWORD_CHANGE_REQUIRED, - - 2 # INVALID_CREDENTIALS, - - 3 # PASSWORD_ALREADY_USED, - - 4 # USERNAME_PENDING_VERIFICATION, - - 5 # PASSWORD_INVALID, - - 6 # INTERNAL_ERROR, - - 7 # ACCESS_DENIED, - - 8 # INVALID_TOKEN - - 9 # EXPIRED_TOKEN - - 10 # RATE_LIMIT_EXCEEDED - - 11 # BAD_MFA_TRANSACTION - - 12 # MFA_FAILURE - - 13 # SECURITY_SERVICE_UNREACHABLE - ErrorDetails: - type: string - ErrorDescription: - type: string - + $ref: 'https://github.com/Telecominfraproject/wlan-cloud-ucentralsec/blob/main/openpapi/owsec.yaml#/components/responses/Unauthorized' Success: - description: The requested operation was performed. - content: - application/json: - schema: - properties: - Operation: - type: string - Details: - type: string - Code: - type: integer - + $ref: 'https://github.com/Telecominfraproject/wlan-cloud-ucentralsec/blob/main/openpapi/owsec.yaml#/components/responses/Success' BadRequest: - description: The requested operation failed. - content: - application/json: - schema: - properties: - ErrorCode: - type: integer - ErrorDetails: - type: string - ErrorDescription: - type: integer + $ref: 'https://github.com/Telecominfraproject/wlan-cloud-ucentralsec/blob/main/openpapi/owsec.yaml#/components/responses/BadRequest' schemas: ObjectInfo: diff --git a/src/framework/MicroService.h b/src/framework/MicroService.h index 8447a5e..85dcf5d 100644 --- a/src/framework/MicroService.h +++ b/src/framework/MicroService.h @@ -27,6 +27,11 @@ namespace OpenWifi { inline uint64_t Now() { return std::time(nullptr); }; } +namespace OpenWifi::Utils { + std::vector base64decode(const std::string& input); + std::string base64encode(const unsigned char *input, uint32_t size); +} + using namespace std::chrono_literals; #include "Poco/Util/Application.h" @@ -238,6 +243,11 @@ namespace OpenWifi::RESTAPI_utils { Obj.set(Field,Value); } + inline void field_to_json(Poco::JSON::Object &Obj, const char *Field, const Poco::Data::BLOB &Value) { + auto Result = Utils::base64encode((const unsigned char *)Value.rawContent(),Value.size()); + Obj.set(Field,Result); + } + inline void field_to_json(Poco::JSON::Object &Obj, const char *Field, const Types::StringPairVec & S) { Poco::JSON::Array Array; for(const auto &i:S) { @@ -334,12 +344,12 @@ namespace OpenWifi::RESTAPI_utils { inline void field_from_json(const Poco::JSON::Object::Ptr &Obj, const char *Field, double & Value) { if(Obj->has(Field) && !Obj->isNull(Field)) - Value = (double) Obj->get(Field); + Value = (double)Obj->get(Field); } inline void field_from_json(const Poco::JSON::Object::Ptr &Obj, const char *Field, float & Value) { if(Obj->has(Field) && !Obj->isNull(Field)) - Value = (float) Obj->get(Field); + Value = (float)Obj->get(Field); } inline void field_from_json(const Poco::JSON::Object::Ptr &Obj, const char *Field, bool &Value) { @@ -374,7 +384,14 @@ namespace OpenWifi::RESTAPI_utils { inline void field_from_json(const Poco::JSON::Object::Ptr &Obj, const char *Field, uint64_t &Value) { if(Obj->has(Field) && !Obj->isNull(Field)) - Value = (uint64_t ) Obj->get(Field); + Value = (uint64_t)Obj->get(Field); + } + + inline void field_from_json(const Poco::JSON::Object::Ptr &Obj, const char *Field, Poco::Data::BLOB &Value) { + if(Obj->has(Field) && !Obj->isNull(Field)) { + auto Result = Utils::base64decode(Obj->get(Field).toString()); + Value.assignRaw((const unsigned char *)&Result[0],Result.size()); + } } inline void field_from_json(const Poco::JSON::Object::Ptr &Obj, const char *Field, Types::StringPairVec &Vec) { @@ -2064,6 +2081,17 @@ namespace OpenWifi { return false; } + static inline bool AssignIfPresent(const Poco::JSON::Object::Ptr &O, const std::string &Field, Poco::Data::BLOB &Value) { + if(O->has(Field)) { + std::string Content = O->get(Field).toString(); + auto DecodedBlob = Utils::base64decode(Content); + Value.assignRaw((const unsigned char *)&DecodedBlob[0],DecodedBlob.size()); + return true; + } + return false; + } + + template bool AssignIfPresent(const Poco::JSON::Object::Ptr &O, const std::string &Field, const T &value, T & assignee) { if(O->has(Field)) { assignee = value; diff --git a/src/framework/orm.h b/src/framework/orm.h index 7b358a9..4fc8a15 100644 --- a/src/framework/orm.h +++ b/src/framework/orm.h @@ -133,6 +133,37 @@ namespace ORM { return R; } + inline std::string WHERE_AND_(std::string Result) { + return Result; + } + + template std::string WHERE_AND_(std::string Result, const char *fieldName, const T &Value, Args... args) { + if constexpr(std::is_same_v) + { + if(!Value.empty()) { + if(!Result.empty()) + Result += " and "; + Result += fieldName; + Result += '='; + Result += "'"; + Result += Escape(Value); + Result += "'"; + } + } else { + if(!Result.empty()) + Result += " and "; + Result += fieldName ; + Result += '='; + Result += std::to_string(Value); + } + return WHERE_AND_(Result,args...); + } + + template std::string WHERE_AND(Args... args) { + std::string Result; + return WHERE_AND_(Result, args...); + } + enum SqlComparison { EQ = 0, NEQ, LT, LTE, GT, GTE }; enum SqlBinaryOp { AND = 0 , OR };