DescribeConfigRuleResult.cc 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169
  1. /*
  2. * Copyright 2009-2017 Alibaba Cloud All rights reserved.
  3. *
  4. * Licensed under the Apache License, Version 2.0 (the "License");
  5. * you may not use this file except in compliance with the License.
  6. * You may obtain a copy of the License at
  7. *
  8. * http://www.apache.org/licenses/LICENSE-2.0
  9. *
  10. * Unless required by applicable law or agreed to in writing, software
  11. * distributed under the License is distributed on an "AS IS" BASIS,
  12. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13. * See the License for the specific language governing permissions and
  14. * limitations under the License.
  15. */
  16. #include <alibabacloud/config/model/DescribeConfigRuleResult.h>
  17. #include <json/json.h>
  18. using namespace AlibabaCloud::Config;
  19. using namespace AlibabaCloud::Config::Model;
  20. DescribeConfigRuleResult::DescribeConfigRuleResult() :
  21. ServiceResult()
  22. {}
  23. DescribeConfigRuleResult::DescribeConfigRuleResult(const std::string &payload) :
  24. ServiceResult()
  25. {
  26. parse(payload);
  27. }
  28. DescribeConfigRuleResult::~DescribeConfigRuleResult()
  29. {}
  30. void DescribeConfigRuleResult::parse(const std::string &payload)
  31. {
  32. Json::Reader reader;
  33. Json::Value value;
  34. reader.parse(payload, value);
  35. setRequestId(value["RequestId"].asString());
  36. auto configRuleNode = value["ConfigRule"];
  37. if(!configRuleNode["RiskLevel"].isNull())
  38. configRule_.riskLevel = std::stoi(configRuleNode["RiskLevel"].asString());
  39. if(!configRuleNode["InputParameters"].isNull())
  40. configRule_.inputParameters = configRuleNode["InputParameters"].asString();
  41. if(!configRuleNode["ConfigRuleState"].isNull())
  42. configRule_.configRuleState = configRuleNode["ConfigRuleState"].asString();
  43. if(!configRuleNode["MaximumExecutionFrequency"].isNull())
  44. configRule_.maximumExecutionFrequency = configRuleNode["MaximumExecutionFrequency"].asString();
  45. if(!configRuleNode["OrganizationRule"].isNull())
  46. configRule_.organizationRule = configRuleNode["OrganizationRule"].asString() == "true";
  47. if(!configRuleNode["ConfigRuleArn"].isNull())
  48. configRule_.configRuleArn = configRuleNode["ConfigRuleArn"].asString();
  49. if(!configRuleNode["Description"].isNull())
  50. configRule_.description = configRuleNode["Description"].asString();
  51. if(!configRuleNode["ConfigRuleName"].isNull())
  52. configRule_.configRuleName = configRuleNode["ConfigRuleName"].asString();
  53. if(!configRuleNode["ConfigRuleId"].isNull())
  54. configRule_.configRuleId = configRuleNode["ConfigRuleId"].asString();
  55. if(!configRuleNode["ModifiedTimestamp"].isNull())
  56. configRule_.modifiedTimestamp = std::stol(configRuleNode["ModifiedTimestamp"].asString());
  57. if(!configRuleNode["CreateTimestamp"].isNull())
  58. configRule_.createTimestamp = std::stol(configRuleNode["CreateTimestamp"].asString());
  59. auto sourceNode = configRuleNode["Source"];
  60. if(!sourceNode["Owner"].isNull())
  61. configRule_.source.owner = sourceNode["Owner"].asString();
  62. if(!sourceNode["Identifier"].isNull())
  63. configRule_.source.identifier = sourceNode["Identifier"].asString();
  64. auto allSourceDetailsNode = sourceNode["SourceDetails"]["SourceDetailsItem"];
  65. for (auto sourceNodeSourceDetailsSourceDetailsItem : allSourceDetailsNode)
  66. {
  67. ConfigRule::Source::SourceDetailsItem sourceDetailsItemObject;
  68. if(!sourceNodeSourceDetailsSourceDetailsItem["MessageType"].isNull())
  69. sourceDetailsItemObject.messageType = sourceNodeSourceDetailsSourceDetailsItem["MessageType"].asString();
  70. if(!sourceNodeSourceDetailsSourceDetailsItem["EventSource"].isNull())
  71. sourceDetailsItemObject.eventSource = sourceNodeSourceDetailsSourceDetailsItem["EventSource"].asString();
  72. if(!sourceNodeSourceDetailsSourceDetailsItem["MaximumExecutionFrequency"].isNull())
  73. sourceDetailsItemObject.maximumExecutionFrequency = sourceNodeSourceDetailsSourceDetailsItem["MaximumExecutionFrequency"].asString();
  74. configRule_.source.sourceDetails.push_back(sourceDetailsItemObject);
  75. }
  76. auto allSourceConditionsNode = sourceNode["SourceConditions"]["SourceConditionsItem"];
  77. for (auto sourceNodeSourceConditionsSourceConditionsItem : allSourceConditionsNode)
  78. {
  79. ConfigRule::Source::SourceConditionsItem sourceConditionsItemObject;
  80. if(!sourceNodeSourceConditionsSourceConditionsItem["DesiredValue"].isNull())
  81. sourceConditionsItemObject.desiredValue = sourceNodeSourceConditionsSourceConditionsItem["DesiredValue"].asString();
  82. if(!sourceNodeSourceConditionsSourceConditionsItem["Required"].isNull())
  83. sourceConditionsItemObject.required = sourceNodeSourceConditionsSourceConditionsItem["Required"].asString() == "true";
  84. if(!sourceNodeSourceConditionsSourceConditionsItem["Tips"].isNull())
  85. sourceConditionsItemObject.tips = sourceNodeSourceConditionsSourceConditionsItem["Tips"].asString();
  86. if(!sourceNodeSourceConditionsSourceConditionsItem["Operator"].isNull())
  87. sourceConditionsItemObject._operator = sourceNodeSourceConditionsSourceConditionsItem["Operator"].asString();
  88. if(!sourceNodeSourceConditionsSourceConditionsItem["Name"].isNull())
  89. sourceConditionsItemObject.name = sourceNodeSourceConditionsSourceConditionsItem["Name"].asString();
  90. if(!sourceNodeSourceConditionsSourceConditionsItem["SelectPath"].isNull())
  91. sourceConditionsItemObject.selectPath = sourceNodeSourceConditionsSourceConditionsItem["SelectPath"].asString();
  92. configRule_.source.sourceConditions.push_back(sourceConditionsItemObject);
  93. }
  94. auto managedRuleNode = configRuleNode["ManagedRule"];
  95. if(!managedRuleNode["HelpUrl"].isNull())
  96. configRule_.managedRule.helpUrl = managedRuleNode["HelpUrl"].asString();
  97. if(!managedRuleNode["Description"].isNull())
  98. configRule_.managedRule.description = managedRuleNode["Description"].asString();
  99. if(!managedRuleNode["Identifier"].isNull())
  100. configRule_.managedRule.identifier = managedRuleNode["Identifier"].asString();
  101. if(!managedRuleNode["OptionalInputParameterDetails"].isNull())
  102. configRule_.managedRule.optionalInputParameterDetails = managedRuleNode["OptionalInputParameterDetails"].asString();
  103. if(!managedRuleNode["ManagedRuleName"].isNull())
  104. configRule_.managedRule.managedRuleName = managedRuleNode["ManagedRuleName"].asString();
  105. if(!managedRuleNode["CompulsoryInputParameterDetails"].isNull())
  106. configRule_.managedRule.compulsoryInputParameterDetails = managedRuleNode["CompulsoryInputParameterDetails"].asString();
  107. auto allSourceDetails1Node = managedRuleNode["SourceDetails"]["SourceDetailsItem"];
  108. for (auto managedRuleNodeSourceDetailsSourceDetailsItem : allSourceDetails1Node)
  109. {
  110. ConfigRule::ManagedRule::SourceDetailsItem2 sourceDetailsItem2Object;
  111. if(!managedRuleNodeSourceDetailsSourceDetailsItem["MessageType"].isNull())
  112. sourceDetailsItem2Object.messageType = managedRuleNodeSourceDetailsSourceDetailsItem["MessageType"].asString();
  113. if(!managedRuleNodeSourceDetailsSourceDetailsItem["EventSource"].isNull())
  114. sourceDetailsItem2Object.eventSource = managedRuleNodeSourceDetailsSourceDetailsItem["EventSource"].asString();
  115. if(!managedRuleNodeSourceDetailsSourceDetailsItem["MaximumExecutionFrequency"].isNull())
  116. sourceDetailsItem2Object.maximumExecutionFrequency = managedRuleNodeSourceDetailsSourceDetailsItem["MaximumExecutionFrequency"].asString();
  117. configRule_.managedRule.sourceDetails1.push_back(sourceDetailsItem2Object);
  118. }
  119. auto allLabels = managedRuleNode["Labels"]["Labels"];
  120. for (auto value : allLabels)
  121. configRule_.managedRule.labels.push_back(value.asString());
  122. auto createByNode = configRuleNode["CreateBy"];
  123. if(!createByNode["ConfigRuleSceneId"].isNull())
  124. configRule_.createBy.configRuleSceneId = createByNode["ConfigRuleSceneId"].asString();
  125. if(!createByNode["CreatorName"].isNull())
  126. configRule_.createBy.creatorName = createByNode["CreatorName"].asString();
  127. if(!createByNode["CreatorType"].isNull())
  128. configRule_.createBy.creatorType = createByNode["CreatorType"].asString();
  129. if(!createByNode["CreatorId"].isNull())
  130. configRule_.createBy.creatorId = createByNode["CreatorId"].asString();
  131. if(!createByNode["ConfigRuleSceneName"].isNull())
  132. configRule_.createBy.configRuleSceneName = createByNode["ConfigRuleSceneName"].asString();
  133. auto scopeNode = configRuleNode["Scope"];
  134. if(!scopeNode["ComplianceResourceId"].isNull())
  135. configRule_.scope.complianceResourceId = scopeNode["ComplianceResourceId"].asString();
  136. auto allComplianceResourceTypes = scopeNode["ComplianceResourceTypes"]["ComplianceResourceTypes"];
  137. for (auto value : allComplianceResourceTypes)
  138. configRule_.scope.complianceResourceTypes.push_back(value.asString());
  139. auto configRuleEvaluationStatusNode = configRuleNode["ConfigRuleEvaluationStatus"];
  140. if(!configRuleEvaluationStatusNode["LastErrorCode"].isNull())
  141. configRule_.configRuleEvaluationStatus.lastErrorCode = configRuleEvaluationStatusNode["LastErrorCode"].asString();
  142. if(!configRuleEvaluationStatusNode["LastSuccessfulEvaluationTimestamp"].isNull())
  143. configRule_.configRuleEvaluationStatus.lastSuccessfulEvaluationTimestamp = std::stol(configRuleEvaluationStatusNode["LastSuccessfulEvaluationTimestamp"].asString());
  144. if(!configRuleEvaluationStatusNode["FirstActivatedTimestamp"].isNull())
  145. configRule_.configRuleEvaluationStatus.firstActivatedTimestamp = std::stol(configRuleEvaluationStatusNode["FirstActivatedTimestamp"].asString());
  146. if(!configRuleEvaluationStatusNode["FirstEvaluationStarted"].isNull())
  147. configRule_.configRuleEvaluationStatus.firstEvaluationStarted = configRuleEvaluationStatusNode["FirstEvaluationStarted"].asString() == "true";
  148. if(!configRuleEvaluationStatusNode["LastSuccessfulInvocationTimestamp"].isNull())
  149. configRule_.configRuleEvaluationStatus.lastSuccessfulInvocationTimestamp = std::stol(configRuleEvaluationStatusNode["LastSuccessfulInvocationTimestamp"].asString());
  150. if(!configRuleEvaluationStatusNode["LastErrorMessage"].isNull())
  151. configRule_.configRuleEvaluationStatus.lastErrorMessage = configRuleEvaluationStatusNode["LastErrorMessage"].asString();
  152. if(!configRuleEvaluationStatusNode["LastFailedEvaluationTimestamp"].isNull())
  153. configRule_.configRuleEvaluationStatus.lastFailedEvaluationTimestamp = std::stol(configRuleEvaluationStatusNode["LastFailedEvaluationTimestamp"].asString());
  154. if(!configRuleEvaluationStatusNode["LastFailedInvocationTimestamp"].isNull())
  155. configRule_.configRuleEvaluationStatus.lastFailedInvocationTimestamp = std::stol(configRuleEvaluationStatusNode["LastFailedInvocationTimestamp"].asString());
  156. }
  157. DescribeConfigRuleResult::ConfigRule DescribeConfigRuleResult::getConfigRule()const
  158. {
  159. return configRule_;
  160. }