@@ -81,12 +81,15 @@ function parse_max_items(input_max_items) {
8181}
8282
8383/**
84- * validate_params will call the aquivalent function in user or access key
84+ * validate_params will call the aquivalent function in user, access key, or tagging
85+ * Note: The order of conditions matters - check 'tag' before 'user' to avoid misrouting
8586 * @param {string } action
8687 * @param {object } params
8788 */
8889function validate_params ( action , params ) {
89- if ( action . includes ( 'policy' ) || action . includes ( 'policies' ) ) {
90+ if ( action . includes ( 'tag' ) ) {
91+ validate_tagging_params ( action , params ) ;
92+ } else if ( action . includes ( 'policy' ) || action . includes ( 'policies' ) ) {
9093 validate_policy_params ( action , params ) ;
9194 } else if ( action . includes ( 'user' ) ) {
9295 validate_user_params ( action , params ) ;
@@ -151,6 +154,27 @@ function validate_access_keys_params(action, params) {
151154 }
152155}
153156
157+ /**
158+ * validate_tagging_params will call the aquivalent function for each action in tagging API
159+ * @param {string } action
160+ * @param {object } params
161+ */
162+ function validate_tagging_params ( action , params ) {
163+ switch ( action ) {
164+ case iam_constants . IAM_ACTIONS . TAG_USER :
165+ validate_tag_user_params ( params ) ;
166+ break ;
167+ case iam_constants . IAM_ACTIONS . UNTAG_USER :
168+ validate_untag_user_params ( params ) ;
169+ break ;
170+ case iam_constants . IAM_ACTIONS . LIST_USER_TAGS :
171+ validate_list_user_tags_params ( params ) ;
172+ break ;
173+ default :
174+ throw new RpcError ( 'INTERNAL_ERROR' , `${ action } is not supported` ) ;
175+ }
176+ }
177+
154178/**
155179 * validate_policy_params will call the aquivalent function for each action in user policy API
156180 * @param {string } action
@@ -581,6 +605,92 @@ function translate_rpc_error(err) {
581605 throw err ;
582606}
583607
608+ /**
609+ * parse_indexed_members parses indexed array members
610+ * generic parser for AWS-style indexed request parameters
611+ * @param {object } body - request body
612+ * @param {string } base_key - the base key pattern (e.g., 'tags_member_{index}_key)
613+ * @param {Function } [mapper] - optional function to convert each item
614+ */
615+ function parse_indexed_members ( body , base_key , mapper ) {
616+ const result = [ ] ;
617+ let index = 1 ;
618+ let check_key = base_key . replace ( '{index}' , String ( index ) ) ;
619+
620+ while ( body [ check_key ] !== undefined ) {
621+ result . push ( mapper ? mapper ( body , index ) : body [ check_key ] ) ;
622+ index += 1 ;
623+ check_key = base_key . replace ( '{index}' , String ( index ) ) ;
624+ }
625+ return result ;
626+ }
627+
628+ /**
629+ * parse_tags_from_request_body parses tags from request body
630+ * @param {object } body - request body
631+ */
632+ function parse_tags_from_request_body ( body ) {
633+ return parse_indexed_members (
634+ body ,
635+ 'tags_member_{index}_key' ,
636+ ( req_body , index ) => ( {
637+ key : req_body [ `tags_member_${ index } _key` ] ,
638+ value : req_body [ `tags_member_${ index } _value` ] || ''
639+ } )
640+ ) ;
641+ }
642+
643+ /**
644+ * parse_tag_keys_from_request_body parses tag keys from request body
645+ * @param {object } body - request body
646+ */
647+ function parse_tag_keys_from_request_body ( body ) {
648+ return parse_indexed_members ( body , 'tag_keys_member_{index}' ) ;
649+ }
650+
651+ /**
652+ * validate_tag_user_params checks the params for tag_user action
653+ * @param {object } params
654+ */
655+ function validate_tag_user_params ( params ) {
656+ try {
657+ check_required_username ( params ) ;
658+ validation_utils . validate_username ( params . username , iam_constants . IAM_PARAMETER_NAME . USERNAME ) ;
659+ validation_utils . validate_iam_tags ( params . tags ) ;
660+ } catch ( err ) {
661+ translate_rpc_error ( err ) ;
662+ }
663+ }
664+
665+ /**
666+ * validate_untag_user_params checks the params for untag_user action
667+ * @param {object } params
668+ */
669+ function validate_untag_user_params ( params ) {
670+ try {
671+ check_required_username ( params ) ;
672+ validation_utils . validate_username ( params . username , iam_constants . IAM_PARAMETER_NAME . USERNAME ) ;
673+ validation_utils . validate_iam_tag_keys ( params . tag_keys ) ;
674+ } catch ( err ) {
675+ translate_rpc_error ( err ) ;
676+ }
677+ }
678+
679+ /**
680+ * validate_list_user_tags_params checks the params for list_user_tags action
681+ * @param {object } params
682+ */
683+ function validate_list_user_tags_params ( params ) {
684+ try {
685+ check_required_username ( params ) ;
686+ validation_utils . validate_username ( params . username , iam_constants . IAM_PARAMETER_NAME . USERNAME ) ;
687+ validate_marker ( params . marker ) ;
688+ validate_max_items ( params . max_items ) ;
689+ } catch ( err ) {
690+ translate_rpc_error ( err ) ;
691+ }
692+ }
693+
584694// EXPORTS
585695exports . format_iam_xml_date = format_iam_xml_date ;
586696exports . create_arn_for_user = create_arn_for_user ;
@@ -593,4 +703,10 @@ exports.validate_iam_path = validate_iam_path;
593703exports . validate_marker = validate_marker ;
594704exports . validate_access_key_id = validate_access_key_id ;
595705exports . validate_status = validate_status ;
706+ exports . parse_indexed_members = parse_indexed_members ;
707+ exports . parse_tags_from_request_body = parse_tags_from_request_body ;
708+ exports . parse_tag_keys_from_request_body = parse_tag_keys_from_request_body ;
709+ exports . validate_tag_user_params = validate_tag_user_params ;
710+ exports . validate_untag_user_params = validate_untag_user_params ;
711+ exports . validate_list_user_tags_params = validate_list_user_tags_params ;
596712
0 commit comments