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

Support for aws codecommit private git repository #654

Open
amitkewal opened this issue Oct 19, 2022 · 1 comment
Open

Support for aws codecommit private git repository #654

amitkewal opened this issue Oct 19, 2022 · 1 comment

Comments

@amitkewal
Copy link

Support for aws codecommit private git repository

When I ran terraform-compliance on the repository present in the aws codecommit , the terraform-compliance throws the error:

File "C:\Users\AKewal\AppData\Local\Programs\Python\Python310\lib\site-packages\terraform_compliance\main.py", line 95, in cli
   raise ValueError("Bad feature directory:" + args.features)
ValueError: Bad feature directory:https://git-codecommit.us-east-1.amazonaws.com/v1/repos/MY_REPO

Suggested Solution description ( if you have any ):
I have looked over the code and found out it supports only URL ending with *.git


 if args.features.startswith(('http', 'https', 'ssh')):
        # Default to master branch and full repository
        if args.features.endswith('.git'):
            features_git_repo = args.features
            features_git_branch = "master"

        # Optionally allow for directory and branch
        elif '.git//' in args.features and '?ref=' in args.features:
            # Split on .git/
            features_git_list = args.features.split('.git/', 1)
            # Everything up to .git is the repository
            features_git_repo = features_git_list[0] + '.git'

            # Split the directory and branch ref
            features_git_list = features_git_list[1].split('?ref=', 1)
            features_dir = features_git_list[0]
            features_git_branch = features_git_list[1]

        else:  # invalid
            raise ValueError("Bad feature directory:" + args.features)

AWS Codecommit git URL sample: https://git-codecommit.us-east-1.amazonaws.com/v1/repos/MY_REPO.
I tweaked the code and didn't filter this url based on .git ending and was able to clone the repo and run the terraform compliance command successfully.

Sharing code snippet here

    if args.features.startswith(('http', 'https', 'ssh')):
        # Default to master branch and full repository
        features_codecommit_list = 

> args.features.split('//', 2)

        if args.features.endswith('.git'):
            features_git_repo = args.features
            features_git_branch = 'master'

        # Optionally allow for directory and branch
        elif '.git//' in args.features and '?ref=' in args.features:
            # Split on .git/
            features_git_list = args.features.split('.git/', 1)
            # Everything up to .git is the repository
            features_git_repo = features_git_list[0] + '.git'

            # Split the directory and branch ref
            features_git_list = features_git_list[1].split('?ref=', 1)
            features_dir = features_git_list[0]
            features_git_branch = features_git_list[1]

 

>        elif len(features_codecommit_list) == 3:
>             features_split_list = features_codecommit_list[2].split('?ref=',1)
>             if '?ref=' in args.features:
>                 features_dir = features_split_list[0]
>                 features_git_branch = features_split_list[1]
>                 features_git_repo = features_codecommit_list[0] + '//' + features_codecommit_list[1] #args.feaures
>             else:
>                 features_dir = features_split_list[0]
>                 features_git_repo = features_codecommit_list[0] + '//' + features_codecommit_list[1] #args.feaures
> 
>         elif len(features_codecommit_list) == 2:
>             features_split_list = args.features.split('?ref=',1)
>             if '?ref=' in args.features:
>                 features_git_branch = features_split_list[1]
>                 features_git_repo = features_split_list[0] #args.feaures
>             else:
>                 features_git_repo = features_split_list[0] #args.feaures

        
        else:  # invalid

            raise ValueError("Bad feature directory:" + args.features)
@chrisdaish
Copy link

Can confirm this issue also occurs with Azure DevOps when using https:// with git.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants