Skip to content

Incorrect logic used in the naming convention function #1834

@TejasRGitHub

Description

@TejasRGitHub

Describe the bug

The function used here -

def build_compliant_name(self) -> str:

build_compliant_name uses the following logic

 regex = NamingConventionPattern[self.service].value['regex']
        separator = NamingConventionPattern[self.service].value['separator']
        max_length = NamingConventionPattern[self.service].value['max_length']
        suffix = f'-{self.target_uri}' if len(self.target_uri) else ''
        return f'{slugify(self.resource_prefix + "-" + self.target_label[: (max_length - len(self.resource_prefix + self.target_uri))] + suffix, regex_pattern=rf"{regex}", separator=separator, lowercase=True)}'

Inside this logic the characters which should be extracted from target_label - max_length - len(self.resource_prefix + self.target_uri) depend on len(self.resource_prefix + self.target_uri).
The suffix contains an extra character - "-" and there is another extra character "-" between the resource_prefix and the target_label.

These 2 extra characters are not considered while extracting the target_label. This leads to string being greater than the desired length

How to Reproduce

Create a bucket with 51 characters and check the length of generated S3 bucket, IAM role, etc

Expected behavior

No response

Your project

No response

Screenshots

No response

OS

mac

Python version

3.9

AWS data.all version

2.7.0

Additional context

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions