Skip to content

Commit

Permalink
format
Browse files Browse the repository at this point in the history
  • Loading branch information
DmitriyMusatkin committed Jul 30, 2024
1 parent fb2861b commit 9e3173f
Show file tree
Hide file tree
Showing 7 changed files with 54 additions and 37 deletions.
7 changes: 5 additions & 2 deletions include/aws/sdkutils/endpoints_rule_engine.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,11 @@ struct aws_endpoints_resolved_endpoint;
struct aws_endpoints_request_context;
struct aws_hash_table;

enum aws_endpoints_parameter_type { AWS_ENDPOINTS_PARAMETER_STRING, AWS_ENDPOINTS_PARAMETER_BOOLEAN, AWS_ENDPOINTS_PARAMETER_STRING_ARRAY };
enum aws_endpoints_parameter_type {
AWS_ENDPOINTS_PARAMETER_STRING,
AWS_ENDPOINTS_PARAMETER_BOOLEAN,
AWS_ENDPOINTS_PARAMETER_STRING_ARRAY
};
enum aws_endpoints_resolved_endpoint_type { AWS_ENDPOINTS_RESOLVED_ENDPOINT, AWS_ENDPOINTS_RESOLVED_ERROR };

AWS_EXTERN_C_BEGIN
Expand Down Expand Up @@ -243,7 +247,6 @@ AWS_SDKUTILS_API int aws_endpoints_request_context_add_string_array(
struct aws_byte_cursor *values,
size_t len);


/*
* Resolve an endpoint given request context.
* Resolved endpoint is returned through out_resolved_endpoint.
Expand Down
31 changes: 13 additions & 18 deletions source/endpoints_rule_engine.c
Original file line number Diff line number Diff line change
Expand Up @@ -188,20 +188,12 @@ static int s_init_top_level_scope(
switch (value->type) {
case AWS_ENDPOINTS_PARAMETER_STRING:
case AWS_ENDPOINTS_PARAMETER_BOOLEAN:
case AWS_ENDPOINTS_PARAMETER_STRING_ARRAY:
val->value = value->default_value;
val->value.is_shallow = true;
AWS_LOGF_DEBUG(0, "assigned default");
break;
break;
case AWS_ENDPOINTS_PARAMETER_STRING_ARRAY:
{
size_t len = aws_array_list_length(&value->default_value.v.array);
aws_array_list_init_dynamic(&val->value.v.array, allocator, len, sizeof(struct aws_endpoints_value));
for (int i = 0; i < len; ++i) {
struct aws_endpoints_value *elem;
aws_array_list_get_at_ptr(&value->default_value.v.array, (void**)&elem, i);
aws_array_list_set_at(&val->value.v.array, elem, i);
}
val->value.type = AWS_ENDPOINTS_VALUE_ARRAY;
}
break;
default:
AWS_LOGF_ERROR(AWS_LS_SDKUTILS_ENDPOINTS_RESOLVE, "Unexpected parameter type.");
goto on_error;
Expand Down Expand Up @@ -333,7 +325,7 @@ static int s_resolve_expr(
goto on_error;
}
aws_array_list_set_at(&out_value->v.array, &val, i);
}
}
}
break;
}
Expand All @@ -348,7 +340,7 @@ static int s_resolve_expr(
out_value->type = AWS_ENDPOINTS_VALUE_NONE;
} else {
struct aws_endpoints_scope_value *aws_endpoints_scope_value = element->value;

*out_value = aws_endpoints_scope_value->value;
out_value->is_shallow = true;
}
Expand Down Expand Up @@ -491,6 +483,7 @@ int aws_endpoints_path_through_array(
}

*out_value = *val;
out_value->is_shallow = true;

return AWS_OP_SUCCESS;

Expand Down Expand Up @@ -609,7 +602,10 @@ static int s_resolve_templated_value_with_pathing(
goto on_error;
}
} else {
AWS_LOGF_ERROR(AWS_LS_SDKUTILS_ENDPOINTS_RESOLVE, "Invalid value type for pathing through. type %d", scope_value->value.type);
AWS_LOGF_ERROR(
AWS_LS_SDKUTILS_ENDPOINTS_RESOLVE,
"Invalid value type for pathing through. type %d",
scope_value->value.type);
goto on_error;
}

Expand Down Expand Up @@ -759,12 +755,11 @@ int aws_endpoints_request_context_add_string_array(
struct aws_endpoints_scope_value *val = aws_endpoints_scope_value_new(allocator, name);
val->value.type = AWS_ENDPOINTS_VALUE_ARRAY;
aws_array_list_init_dynamic(&val->value.v.array, allocator, len, sizeof(struct aws_endpoints_value));

for (size_t i = 0; i < len; ++i) {
struct aws_endpoints_value elem = {
.type = AWS_ENDPOINTS_VALUE_STRING,
.v.owning_cursor_object = aws_endpoints_owning_cursor_from_cursor(allocator, values[i])
};
.v.owning_cursor_object = aws_endpoints_owning_cursor_from_cursor(allocator, values[i])};

aws_array_list_set_at(&val->value.v.array, &elem, i);
}
Expand Down
17 changes: 9 additions & 8 deletions source/endpoints_ruleset.c
Original file line number Diff line number Diff line change
Expand Up @@ -454,19 +454,21 @@ static int s_on_parameter_key(
aws_json_value_get_string(default_node, &cur);
parameter->default_value.type = AWS_ENDPOINTS_VALUE_STRING;
parameter->default_value.v.owning_cursor_string = aws_endpoints_non_owning_cursor_create(cur);
AWS_LOGF_DEBUG(0, "foo " PRInSTR, AWS_BYTE_CURSOR_PRI(cur));
} else if (type == AWS_ENDPOINTS_PARAMETER_BOOLEAN && aws_json_value_is_boolean(default_node)) {
parameter->default_value.type = AWS_ENDPOINTS_VALUE_BOOLEAN;
parameter->default_value.type = AWS_ENDPOINTS_VALUE_BOOLEAN;
aws_json_value_get_boolean(default_node, &parameter->default_value.v.boolean);
AWS_LOGF_DEBUG(0, "bar %d", parameter->default_value.v.boolean);
} else if (type == AWS_ENDPOINTS_PARAMETER_STRING_ARRAY && aws_json_value_is_array(default_node)) {
parameter->default_value.type = AWS_ENDPOINTS_VALUE_ARRAY;
size_t len = aws_json_get_array_size(default_node);
aws_array_list_init_dynamic(&parameter->default_value.v.array, wrapper->allocator, len, sizeof(struct aws_endpoints_value));
aws_array_list_init_dynamic(
&parameter->default_value.v.array, wrapper->allocator, len, sizeof(struct aws_endpoints_value));
for (size_t i = 0; i < len; ++i) {
struct aws_json_value *element = aws_json_get_array_element(default_node, i);
if (!aws_json_value_is_string(element)) {
AWS_LOGF_ERROR(AWS_LS_SDKUTILS_ENDPOINTS_PARSING,
"Unexpected type for default parameter value. String array parameter must have string elements");
AWS_LOGF_ERROR(
AWS_LS_SDKUTILS_ENDPOINTS_PARSING,
"Unexpected type for default parameter value. String array parameter must have string "
"elements");
goto on_error;
}

Expand All @@ -475,8 +477,7 @@ static int s_on_parameter_key(

struct aws_endpoints_value val = {
.type = AWS_ENDPOINTS_VALUE_STRING,
.v.owning_cursor_string = aws_endpoints_non_owning_cursor_create(cur)
};
.v.owning_cursor_string = aws_endpoints_non_owning_cursor_create(cur)};

aws_array_list_set_at(&parameter->default_value.v.array, &val, i);
}
Expand Down
4 changes: 2 additions & 2 deletions source/endpoints_standard_lib.c
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,6 @@ static int s_resolve_fn_get_attr(
struct aws_byte_cursor path_cur = argv_path.v.owning_cursor_string.cur;
AWS_LOGF_DEBUG(0, "foo type %d", argv_value.type);


if (argv_value.type == AWS_ENDPOINTS_VALUE_OBJECT) {
if (aws_endpoints_path_through_object(allocator, &argv_value, path_cur, out_value)) {
AWS_LOGF_ERROR(AWS_LS_SDKUTILS_ENDPOINTS_RESOLVE, "Failed to path through object.");
Expand All @@ -97,7 +96,8 @@ static int s_resolve_fn_get_attr(
goto on_done;
}
} else {
AWS_LOGF_ERROR(AWS_LS_SDKUTILS_ENDPOINTS_RESOLVE, "Invalid value type for pathing through. type: %d", argv_value.type);
AWS_LOGF_ERROR(
AWS_LS_SDKUTILS_ENDPOINTS_RESOLVE, "Invalid value type for pathing through. type: %d", argv_value.type);
result = aws_raise_error(AWS_ERROR_SDKUTILS_ENDPOINTS_RESOLVE_FAILED);
goto on_done;
}
Expand Down
23 changes: 20 additions & 3 deletions source/endpoints_types_impl.c
Original file line number Diff line number Diff line change
Expand Up @@ -204,10 +204,12 @@ void aws_endpoints_value_clean_up(struct aws_endpoints_value *aws_endpoints_valu
AWS_PRECONDITION(aws_endpoints_value);

if (aws_endpoints_value->is_shallow) {
return;
goto on_done;
}

if (aws_endpoints_value->type == AWS_ENDPOINTS_VALUE_STRING) {
AWS_LOGF_DEBUG(
0, "aaaa " PRInSTR " bbbb", AWS_BYTE_CURSOR_PRI(aws_endpoints_value->v.owning_cursor_string.cur));
aws_string_destroy(aws_endpoints_value->v.owning_cursor_string.string);
}

Expand All @@ -216,15 +218,17 @@ void aws_endpoints_value_clean_up(struct aws_endpoints_value *aws_endpoints_valu
}

if (aws_endpoints_value->type == AWS_ENDPOINTS_VALUE_ARRAY) {
AWS_LOGF_DEBUG(0, "foo %d ", aws_array_list_length(&aws_endpoints_value->v.array));
aws_array_list_deep_clean_up(&aws_endpoints_value->v.array, aws_endpoints_value_clean_up_cb);
}

on_done:
AWS_ZERO_STRUCT(*aws_endpoints_value);
}

void aws_endpoints_value_clean_up_cb(void *value) {
struct aws_endpoints_value *aws_endpoints_value = value;
AWS_LOGF_DEBUG(0, "haha");
AWS_LOGF_DEBUG(0, "haha %d", aws_endpoints_value->is_shallow);
aws_endpoints_value_clean_up(aws_endpoints_value);
}

Expand All @@ -234,11 +238,24 @@ int aws_endpoints_deep_copy_parameter_value(
struct aws_endpoints_value *to) {

to->type = from->type;
AWS_LOGF_DEBUG(0, "haha boo %d", from->type);

if (to->type == AWS_ENDPOINTS_VALUE_STRING) {
to->v.owning_cursor_string = aws_endpoints_owning_cursor_create(allocator, from->v.owning_cursor_string.string);
to->v.owning_cursor_string =
aws_endpoints_owning_cursor_from_cursor(allocator, from->v.owning_cursor_string.cur);
} else if (to->type == AWS_ENDPOINTS_VALUE_BOOLEAN) {
to->v.boolean = from->v.boolean;
} else if (to->type == AWS_ENDPOINTS_VALUE_ARRAY) {
size_t len = aws_array_list_length(&from->v.array);
aws_array_list_init_dynamic(&to->v.array, allocator, len, sizeof(struct aws_endpoints_value));
for (size_t i = 0; i < len; ++i) {
struct aws_endpoints_value val;
aws_array_list_get_at(&from->v.array, &val, i);

struct aws_endpoints_value to_val;
aws_endpoints_deep_copy_parameter_value(allocator, &val, &to_val);
aws_array_list_set_at(&to->v.array, &to_val, i);
}
} else {
AWS_LOGF_ERROR(AWS_LS_SDKUTILS_ENDPOINTS_RESOLVE, "Unexpected value type.");
return aws_raise_error(AWS_ERROR_INVALID_STATE);
Expand Down
7 changes: 4 additions & 3 deletions tests/endpoints_rule_engine_tests.c
Original file line number Diff line number Diff line change
Expand Up @@ -141,13 +141,14 @@ static int s_on_parameter_key(
} else if (aws_json_value_is_array(value)) {
struct aws_byte_cursor strings[MAX_STRING_ARRAY_ELEMENTS];
size_t len = aws_json_get_array_size(value);
ASSERT_TRUE(len < MAX_STRING_ARRAY_ELEMENTS);
ASSERT_TRUE(len <= MAX_STRING_ARRAY_ELEMENTS);
for (size_t i = 0; i < len; ++i) {
struct aws_json_value *str = aws_json_get_array_element(value, i);
ASSERT_SUCCESS(aws_json_value_get_string(str, &strings[i]));
}
ASSERT_SUCCESS(aws_endpoints_request_context_add_string_array(wrapper->allocator,
wrapper->context, *key, strings, len));
ASSERT_SUCCESS(
aws_endpoints_request_context_add_string_array(wrapper->allocator, wrapper->context, *key, strings, len));
return AWS_OP_SUCCESS;
}

AWS_LOGF_DEBUG(0, "bar");
Expand Down
2 changes: 1 addition & 1 deletion tests/resources/test-cases/string_array.json
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
{
"documentation": "bound value from input",
"params": {
"stringArrayParam": ["key1"]
"stringArrayParam": ["key1", "key2", "key3", "key4"]
},
"expect": {
"endpoint": {
Expand Down

0 comments on commit 9e3173f

Please sign in to comment.