jeremyschulman / netcfgbu

Network Configuration Backup
Apache License 2.0
105 stars 15 forks source link

Git repo URL cannot be set as an environment variable #88

Open saparikh opened 4 years ago

saparikh commented 4 years ago

When I use an environment variable for the Git repo URL, I get the following error:

(cfgbu) samir-mbp15:cicd_book saparikh$ echo $GIT_REPO
git@github.com:saparikh/cfg-backup.git

(cfgbu) samir-mbp15:cicd_book saparikh$ netcfgbu login
Usage: netcfgbu login [OPTIONS]
Try 'netcfgbu login --help' for help.

Error: Configuration errors
    File:[/Users/saparikh/git/experimental/samir/cicd_book/netcfgbu.toml]
    Section: [git.0.repo]: Bad repo URL [$GIT_REPO]: expected to start with ('https:', 'git@').

This is the TOML file section:

[[git]]
    # the first entry does not require a name and it will be treated
    # as a default; i.e. when the --name option is omitted.
    repo = "$GIT_REPO"
    deploy_key = "$GIT_DEPLOY_KEY"

If I replace the env var with the URL, everything works:

[[git]]
    # the first entry does not require a name and it will be treated
    # as a default; i.e. when the --name option is omitted.
    repo = "git@github.com:saparikh/cfg-backup.git"
    deploy_key = "$GIT_DEPLOY_KEY"

Running version 0.60

(cfgbu) samir-mbp15:cicd_book saparikh$ netcfgbu --version
netcfgbu, version 0.6.0
saparikh commented 4 years ago

This fixed the issue:

diff --git a/netcfgbu/config_model.py b/netcfgbu/config_model.py
index 1b387e0..f6716b1 100644
--- a/netcfgbu/config_model.py
+++ b/netcfgbu/config_model.py
@@ -115,7 +115,7 @@ class FilePathEnvExpand(FilePath):

 class GitSpec(NoExtraBaseModel):
     name: Optional[str]
-    repo: str
+    repo: EnvExpand
     email: Optional[str]
     username: Optional[EnvExpand]
     password: Optional[EnvExpand]

It was assuming that the repo value was a string

jeremyschulman commented 4 years ago

@saparikh - if you'd like to make a PR I'll bring it into the next build. Thank you!

saparikh commented 4 years ago

I can give that a go. I did a quick hack to make it work locally, but wasn't sure if that was the correct fix given the overall code structure or not.