68 const int debug_level)
72 creds(std::move(creds_arg)),
102 Info(std::string network_interface_id_arg,
103 std::string route_table_id_arg)
112 std::string subnet_id;
119 q.emplace_back(
"Action",
"DescribeNetworkInterfaces");
120 q.emplace_back(
"Filter.1.Name",
"attachment.instance-id");
122 q.emplace_back(
"Filter.2.Name",
"addresses.private-ip-address");
144 const tinyxml2::XMLElement *item =
Xml::find(&doc,
145 "DescribeNetworkInterfacesResponse",
146 "networkInterfaceSet",
149 OPENVPN_THROW(aws_route_error,
"DescribeNetworkInterfaces: cannot locate <item> tag in returned XML:\n"
155 OPENVPN_THROW(aws_route_error,
"DescribeNetworkInterfaces: cannot locate one of networkInterfaceId, vpcId, or subnetId in returned XML:\n"
165 q.emplace_back(
"Action",
"DescribeRouteTables");
166 q.emplace_back(
"Filter.1.Name",
"vpc-id");
167 q.emplace_back(
"Filter.1.Value.1",
vpc_id);
168 q.emplace_back(
"Filter.2.Name",
"association.subnet-id");
169 q.emplace_back(
"Filter.2.Value.1", subnet_id);
192 "DescribeRouteTablesResponse",
197 OPENVPN_THROW(aws_route_error,
"DescribeRouteTables: cannot locate routeTableId in returned XML:\n"
215 const std::string &network_interface_id,
216 const bool source_dest_check)
218 const std::string sdc = source_dest_check ?
"true" :
"false";
224 q.emplace_back(
"Action",
"DescribeNetworkInterfaceAttribute");
225 q.emplace_back(
"NetworkInterfaceId", network_interface_id);
226 q.emplace_back(
"Attribute",
"sourceDestCheck");
247 const Xml::Document doc(reply,
"DescribeNetworkInterfaceAttribute");
249 "DescribeNetworkInterfaceAttributeResponse",
260 q.emplace_back(
"Action",
"ModifyNetworkInterfaceAttribute");
261 q.emplace_back(
"NetworkInterfaceId", network_interface_id);
262 q.emplace_back(
"SourceDestCheck.Value", sdc);
283 const Xml::Document doc(reply,
"ModifyNetworkInterfaceAttribute");
285 "ModifyNetworkInterfaceAttributeResponse",
287 if (retval !=
"true")
288 OPENVPN_THROW(aws_route_error,
"ModifyNetworkInterfaceAttribute: returned failure status: " <<
'\n'
291 OPENVPN_LOG(
"AWS EC2 ModifyNetworkInterfaceAttribute " << network_interface_id <<
" SourceDestCheck.Value=" << sdc);
296 const std::string &route_table_id,
297 const std::string &cidr,
302 q.emplace_back(
"Action",
"DeleteRoute");
303 q.emplace_back(
ipv6 ?
"DestinationIpv6CidrBlock" :
"DestinationCidrBlock", cidr);
304 q.emplace_back(
"RouteTableId", route_table_id);
327 "DeleteRouteResponse",
329 if (retval !=
"true")
330 OPENVPN_THROW(aws_route_error,
"DeleteRoute: returned failure status: " <<
'\n'
333 OPENVPN_LOG(
"AWS EC2 DeleteRoute " << cidr <<
" -> table " << route_table_id);
338 const std::string &vpc_id,
339 const std::string &name)
341 std::string route_table_id;
346 q.emplace_back(
"Action",
"CreateRouteTable");
347 q.emplace_back(
"VpcId", vpc_id);
367 "CreateRouteTableResponse",
371 OPENVPN_LOG(
"AWS EC2 CreateRouteTable -> RouteTableId " << route_table_id);
377 q.emplace_back(
"Action",
"CreateTags");
378 q.emplace_back(
"ResourceId.1", route_table_id);
379 q.emplace_back(
"Tag.1.Key",
"Name");
380 q.emplace_back(
"Tag.1.Value", name);
399 return route_table_id;
404 const std::string &route_table_id,
405 const std::string &route,
407 const std::string &target_value,
410 std::string target_type_str;
415 target_type_str =
"InstanceId";
419 target_type_str =
"NetworkInterfaceId";
424 "replace_create_route: unknown RouteTargetType " << (
int)target_type);
427 const std::string dest_cidr_block_name =
ipv6 ?
"DestinationCidrIpv6Block" :
"DestinationCidrBlock";
432 q.emplace_back(
"Action",
"ReplaceRoute");
433 q.emplace_back(dest_cidr_block_name, route);
434 q.emplace_back(target_type_str, target_value);
435 q.emplace_back(
"RouteTableId", route_table_id);
440 ctx.
ts->retry_on_http_4xx =
false;
466 "ReplaceRouteResponse",
468 if (retval ==
"true")
470 OPENVPN_LOG(
"AWS EC2 ReplaceRoute " << route <<
" -> table " << route_table_id);
479 q.emplace_back(
"Action",
"CreateRoute");
480 q.emplace_back(dest_cidr_block_name, route);
481 q.emplace_back(target_type_str, target_value);
482 q.emplace_back(
"RouteTableId", route_table_id);
486 ctx.
ts->retry_on_http_4xx =
true;
507 "CreateRouteResponse",
509 if (retval !=
"true")
510 OPENVPN_THROW(aws_route_error,
"CreateRoute: returned failure status: " <<
'\n'
513 OPENVPN_LOG(
"AWS EC2 CreateRoute " << route <<
" -> table " << route_table_id);
520 q.emplace_back(
"Action",
"DescribeRouteTables");
521 q.emplace_back(
"Filter.1.Name",
"tag:Name");
522 q.emplace_back(
"Filter.1.Value.1", name);
544 "DescribeRouteTablesResponse",
549 OPENVPN_LOG(
"AWS EC2 DescribeRouteTables " << name <<
" -> routeTableId " << (route_table_id.empty() ?
"<none>" : route_table_id));
551 return route_table_id;
563 t->req.uri =
ec2_uri(ctx, std::move(q));
564 t->req.method =
"GET";
565 t->ci.keepalive =
true;
566 ctx.
ts->transactions.clear();
567 ctx.
ts->transactions.push_back(std::move(t));
580 qb.
parms = std::move(q);
581 qb.
parms.emplace_back(
"Version",
"2015-10-01");
590 return "ec2." + instance_info.
region +
".amazonaws.com";
StrongRandomAPI * rng() const
DigestFactory & digest_factory() const
static std::string amz_date()
std::string instance_id() const
PCQuery::Info instance_info
WS::ClientSet::TransactionSet::Ptr ts
Context(PCQuery::Info instance_info_arg, Creds creds_arg, StrongRandomAPI::Ptr rng, Stop *async_stop_arg, const int debug_level)
Info(std::string network_interface_id_arg, std::string route_table_id_arg)
std::string network_interface_id
std::string route_table_id
std::string to_string() const
static void delete_route(Context &ctx, const std::string &route_table_id, const std::string &cidr, bool ipv6)
static std::string ec2_uri(const Context &ctx, REST::Query &&q)
static std::string create_route_table(Context &ctx, const std::string &vpc_id, const std::string &name)
static void replace_create_route(Context &ctx, const std::string &route_table_id, const std::string &route, RouteTargetType target_type, const std::string &target_value, bool ipv6)
static void execute_transaction(Context &ctx)
static void set_source_dest_check(Context &ctx, const std::string &network_interface_id, const bool source_dest_check)
static void add_transaction(const Context &ctx, REST::Query &&q)
static std::string get_route_table_by_name(Context &ctx, std::string &name)
OPENVPN_EXCEPTION(aws_route_error)
static std::string ec2_host(const PCQuery::Info &instance_info)
void reset() noexcept
Points this RCPtr<T> to nullptr safely.
static void new_request_synchronous(const TransactionSet::Ptr ts, Stop *stop=nullptr, RandomAPI *prng=nullptr, const bool sps=false)
static const tinyxml2::XMLElement * find(const tinyxml2::XMLNode *node, const T &first, Args... args)
static std::string find_text(const tinyxml2::XMLNode *node, const T &first, Args... args)
#define OPENVPN_THROW(exc, stuff)
#define OPENVPN_LOG(args)
void add_amz_parms(const Creds &creds)
std::string uri_query() const
void add_amz_signature(DigestFactory &digest_factory, const Creds &creds)
bool request_status_success() const
bool http_status_success() const
std::string format_status(const TransactionSet &ts) const
bool comm_status_success() const
std::string content_in_string() const