Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update parsing logic to include sso-session #24

Merged
merged 27 commits into from
Mar 14, 2023
Merged

Conversation

waahm7
Copy link
Contributor

@waahm7 waahm7 commented Feb 28, 2023

Description of changes:
Changed the profiles map to an array of sections map so that we can handle sso-sessions, which are a different type of section.

By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.

@codecov-commenter
Copy link

codecov-commenter commented Feb 28, 2023

Codecov Report

Patch coverage: 91.07% and project coverage change: +0.44 🎉

Comparison is base (c98a341) 67.75% compared to head (4311bee) 68.20%.

Additional details and impacted files
@@            Coverage Diff             @@
##             main      #24      +/-   ##
==========================================
+ Coverage   67.75%   68.20%   +0.44%     
==========================================
  Files           9        9              
  Lines        2562     2585      +23     
==========================================
+ Hits         1736     1763      +27     
+ Misses        826      822       -4     
Impacted Files Coverage Δ
source/aws_profile.c 68.16% <91.07%> (+2.03%) ⬆️

Help us with your feedback. Take ten seconds to tell us how you rate us. Have a feature suggestion? Share it here.

☔ View full report in Codecov by Sentry.
📢 Do you have feedback about the report comment? Let us know in this issue.

@waahm7 waahm7 changed the title WIP | Parse sso-session Update parsing logic to include sso-session Mar 1, 2023
@waahm7 waahm7 marked this pull request as ready for review March 1, 2023 17:38
AWS_SDKUTILS_API
const struct aws_profile *aws_profile_collection_get_sso_session(
const struct aws_profile_collection *profile_collection,
const struct aws_string *profile_name);
Copy link
Contributor

@graebm graebm Mar 6, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

profile_name
name, session_name, identifier, id, session_id ???

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks, I have updated it to a generic function.

source/aws_profile.c Outdated Show resolved Hide resolved
source/aws_profile.c Outdated Show resolved Hide resolved
source/aws_profile.c Show resolved Hide resolved
source/aws_profile.c Show resolved Hide resolved
* Returns the number of sso-sessions in a collection
*/
AWS_SDKUTILS_API
size_t aws_profile_collection_get_sso_session_count(const struct aws_profile_collection *profile_collection);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should we have a generic api that can return map of all values for a given section type and name?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks, fixed.

source/aws_profile.c Show resolved Hide resolved

if (element == NULL) {
struct aws_hash_element *profile = NULL;
aws_hash_table_find(&collection->sections, profile_name, &profile);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: hash table find seems inconsistent. first one checks for error, second one ignores it

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks, fixed by refactor.

source/aws_profile.c Outdated Show resolved Hide resolved
@@ -895,6 +991,16 @@ static bool s_parse_profile_declaration(
return true;
}

s_parse_by_character_predicate(&profile_cursor, s_is_whitespace, NULL, 0);
} else if (has_sso_session_prefix) {
if (context->profile_collection->profile_source == AWS_PST_CREDENTIALS) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if we dont allow profiles or other section types in cred files, do we need to have that check inside of specific section type if

Copy link
Contributor Author

@waahm7 waahm7 Mar 7, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure how to improve this, as a profile can be valid without any prefix. This is only invalid if there was a prefix other than profile, and the source is CREDENTIALS.

Copy link
Contributor

@graebm graebm left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fix & ship

Comment on lines 116 to 119
const struct aws_profile *aws_profile_collection_get_section(
const struct aws_profile_collection *profile_collection,
const struct aws_string *section_name,
const enum aws_profile_section_type section_type);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

trivial: put type before name. It just makes more sense

Suggested change
const struct aws_profile *aws_profile_collection_get_section(
const struct aws_profile_collection *profile_collection,
const struct aws_string *section_name,
const enum aws_profile_section_type section_type);
const struct aws_profile *aws_profile_collection_get_section(
const struct aws_profile_collection *profile_collection,
const enum aws_profile_section_type section_type,
const struct aws_string *section_name);

@@ -99,12 +109,29 @@ const struct aws_profile *aws_profile_collection_get_profile(
const struct aws_profile_collection *profile_collection,
const struct aws_string *profile_name);

/*
* Retrieves a reference to a section with the specified name and type, if it exists, from the profile collection.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

mention somewhere that you can get the "default" profile by passing AWS_PROFILE_SECTION_TYPE_PROFILE, "default"

source/aws_profile.c Outdated Show resolved Hide resolved
@@ -620,7 +641,8 @@ static int s_profile_collection_add_profile(
const struct aws_byte_cursor *profile_name,
bool has_prefix,
const struct profile_file_parse_context *context,
struct aws_profile **current_profile_out) {
struct aws_profile **current_profile_out,
const enum aws_profile_section_type section_type) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

similar to earlier comment, move section_type arg so that it comes before profile_name

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

also, debatable, but does it make to code more clear going forward if we change profile_name -> section_name or name?

Copy link
Contributor Author

@waahm7 waahm7 Mar 14, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it would be better to stick to one naming scheme instead of mixing and matching.

waahm7 and others added 3 commits March 14, 2023 12:21
Co-authored-by: Michael Graeb <graebm@amazon.com>
@waahm7 waahm7 merged commit 9de5923 into main Mar 14, 2023
@waahm7 waahm7 deleted the sso-session-parsing branch March 14, 2023 20:35
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants