Skip to content

Commit

Permalink
Merge pull request #21 from cmars/feat/component-remove-tenant-support
Browse files Browse the repository at this point in the history
feat: add --tenant support to component and remove commands
  • Loading branch information
EricFernandezSnyk authored Sep 21, 2023
2 parents 65f2f51 + 0abb66a commit 4f76a37
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 1 deletion.
18 changes: 17 additions & 1 deletion snyk_tags/component.py
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,10 @@ def tag(
default=FormatType.log,
help="Output format, one of: log, csv, json",
),
tenant: str = typer.Option(
"", # Default value of comamand
help=f"Defaults to US tenant, add 'eu' or 'au' to use EU or AU tenant, use --tenant to change tenant.",
),
):
if format == "csv":
fmtr = CsvFormatter()
Expand All @@ -157,7 +161,19 @@ def tag(
with open(rules, "r") as f:
rules_doc = parse_rules(f)
(match_fn, context) = project_matcher(rules_doc)
client = Api(snyktkn)
client = Api(
snyktkn,
v1_url=(
f"https://api.{tenant}.snyk.io/v1"
if tenant in ["eu", "au"]
else "https://api.snyk.io/v1"
),
rest_url=(
f"https://api.{tenant}.snyk.io/rest"
if tenant in ["eu", "au"]
else "https://api.snyk.io/rest"
),
)
for project in client.org_projects(org_id):
# Extract and transform project and target data from API response
# for rule input. Rules operate over project attributes, extended
Expand Down
2 changes: 2 additions & 0 deletions snyk_tags/remove.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ def remove_tags_from_projects(
project_id=project["id"],
tag=tag,
key=key,
tenant=tenant,
project_name=project["attributes"]["name"],
)
else:
Expand Down Expand Up @@ -83,6 +84,7 @@ def remove_tags_from_projects_by_name(
tag=tag,
key=key,
project_name=project["attributes"]["name"],
tenant=tenant,
)


Expand Down

0 comments on commit 4f76a37

Please sign in to comment.