-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #15 from rwxd/fix/pre-commit
fix(*): typing, linting and moved configs to own model
- Loading branch information
Showing
10 changed files
with
168 additions
and
119 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,5 +6,5 @@ def main() -> int: | |
return 0 | ||
|
||
|
||
if __name__ == "__main__": | ||
if __name__ == '__main__': | ||
raise SystemExit(main()) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,20 +1,22 @@ | ||
from pathlib import Path | ||
from pydantic import BaseModel | ||
|
||
import yaml | ||
from ipams.netbox import NetBoxConnector | ||
from ipams.phpipam import PhpIpamConnector | ||
from pydantic import BaseModel | ||
|
||
from ipams.netbox import NetBoxConfig | ||
from ipams.phpipam import PhpIpamConfig | ||
|
||
|
||
class Config(BaseModel): | ||
netboxes: list[NetBoxConnector] = [] | ||
phpipams: list[PhpIpamConnector] = [] | ||
netboxes: list[NetBoxConfig] = [] | ||
phpipams: list[PhpIpamConfig] = [] | ||
|
||
|
||
def parse_config(config: Path) -> Config: | ||
'''Supports json or yaml config files''' | ||
if not config.exists(): | ||
raise FileNotFoundError(f"Config file {config} does not exist") | ||
if config.suffix in [".yaml", ".yml"]: | ||
raise FileNotFoundError(f'Config file {config} does not exist') | ||
if config.suffix in ['.yaml', '.yml']: | ||
with open(config, 'r') as f: | ||
return Config.parse_obj(yaml.safe_load(f)) | ||
return Config.parse_file(config) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.