return std::string(buf);
}
-bool CheckPrivileges(pid_t pid, uid_t uid,
- const std::vector<std::string>& privileges) {
+bool CheckPrivileges(pid_t pid,
+ uid_t uid,
+ const std::vector<std::string>& privileges) {
std::string pkgid = GetPkgId(pid, uid);
if (pkgid.empty()) {
// bypass
}
std::unordered_set<std::string> privs(privileges.begin(), privileges.end());
- ret = pkgmgrinfo_pkginfo_foreach_privilege(handle,
+ ret = pkgmgrinfo_pkginfo_foreach_privilege(
+ handle,
[](const char* priv, void* user_data) -> int {
auto set = static_cast<std::unordered_set<std::string>*>(user_data);
set->erase(priv);
return 0;
- }, &privs);
+ },
+ &privs);
pkgmgrinfo_pkginfo_destroy_pkginfo(handle);
if (ret != PMINFO_R_OK) {
LOG(ERROR) << "Failed to get privileges";
actionparams.push_back(param);
}
action.Setparameters(std::move(actionparams));
+
+ std::vector<rpc::Result> actionreturns;
+ auto returns = schema.GetReturns();
+ for (auto const& iter : returns) {
+ auto return_param = rpc::Result(
+ iter.GetName(), GetStringFromParameterType(iter.GetType()),
+ iter.GetDescription());
+
+ actionreturns.push_back(std::move(return_param));
+ }
+
+ action.Setresults(std::move(actionreturns));
action.Setprivileges(schema.GetPrivileges());
action.Setjson(schema.GetJsonString());
ActionParameter::ActionParameter() : type_(ParameterType::InvalidType), is_required_(false) {}
-ActionParameter::ActionParameter(std::string name, ParameterType type, std::string value, std::string description, bool is_required)
- : name_(std::move(name)), type_(type), value_(std::move(value)), description_(std::move(description)), is_required_(is_required) {
+ActionParameter::ActionParameter(std::string name, ParameterType type, std::string description, bool is_required)
+ : name_(std::move(name)), type_(type), description_(std::move(description)), is_required_(is_required) {
}
const std::string& ActionParameter::GetName() const {
type_ = type;
}
-const std::string& ActionParameter::GetValue() const {
- return value_;
-}
-
-void ActionParameter::SetValue(std::string value) {
- value_ = std::move(value);
-}
-
const std::string& ActionParameter::GetDescription() const {
return description_;
}
class ActionParameter {
public:
ActionParameter();
- ActionParameter(std::string name, ParameterType type, std::string value, std::string description, bool is_required);
+ ActionParameter(std::string name, ParameterType type, std::string description, bool is_required);
const std::string& GetName() const;
void SetName(std::string name);
const ParameterType GetType() const;
void SetType(ParameterType type);
- const std::string& GetValue() const;
- void SetValue(std::string value);
-
const std::string& GetDescription() const;
void SetDescription(std::string description);
private:
std::string name_;
ParameterType type_;
- std::string value_;
std::string description_;
bool is_required_;
};
is_required = false;
}
- parameters_.emplace_back(name, type, "", description, is_required);
+ parameters_.emplace_back(name, type, description, is_required);
}
// returns
SafeJson::get<std::string>(*value, "type"));
std::string description = SafeJson::get<std::string>(*value, "desc");
// ActionParameterType -> another class???
- returns_.emplace_back(name, type, "", description, false);
+ returns_.emplace_back(name, type, description, false);
}
try {
class ActionParameterTest : public ::testing::Test {
protected:
void SetUp() override {
- param_ = new ActionParameter("test_name", ParameterType::StringType, "test_value", "test_description", true);
+ param_ = new ActionParameter("test_name", ParameterType::StringType, "test_description", true);
}
void TearDown() override {
EXPECT_EQ(param_->GetType(), ParameterType::IntType);
}
-TEST_F(ActionParameterTest, GetValueTest) {
- EXPECT_EQ(param_->GetValue(), "test_value");
-}
-
-TEST_F(ActionParameterTest, SetValueTest) {
- param_->SetValue("new_value");
- EXPECT_EQ(param_->GetValue(), "new_value");
-}
-
TEST_F(ActionParameterTest, GetDescriptionTest) {
EXPECT_EQ(param_->GetDescription(), "test_description");
}
struct Result {
string key;
string type;
+ string description;
}
struct ActionSchema {
_D("- required: %s\n", parameter.Getis_requied() ? "true" : "false");
}
}
+
+ if (!action.Getresults().empty()) {
+ _D("results:");
+ for (const auto& result : action.Getresults()) {
+ _D("- key: %s", result.Getkey().c_str());
+ _D("- type: %s", result.Gettype().c_str());
+ _D("- description: %s", result.Getdescription().c_str());
+ }
+ }
} catch (...) {
_E("GetAction Failed");
return -1;