Skip to content

Commit

Permalink
Merge pull request #4 from industrydive/2023-05-23-updates
Browse files Browse the repository at this point in the history
Update packages, authorization method, and added --include-containers
  • Loading branch information
echan217 authored Jun 14, 2023
2 parents 2bab5b5 + 5768d56 commit afc4753
Show file tree
Hide file tree
Showing 7 changed files with 563 additions and 457 deletions.
1 change: 1 addition & 0 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ Versioning
Authors
=======
- Colin Burr - Initial work - `sw3dish <https://github.com/sw3dish>`_
- Eric Chan - Contributor - `echan217 <https://github.com/echan217>`_

License
=======
Expand Down
968 changes: 531 additions & 437 deletions poetry.lock

Large diffs are not rendered by default.

7 changes: 6 additions & 1 deletion proper_gator/authentication.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,12 @@ def get_credentials():
flow = InstalledAppFlow.from_client_secrets_file(
"client_secrets.json", SCOPES
)
credentials = flow.run_console()
credentials = flow.run_local_server(
host='localhost',
port=8888, # temporarily change to unused local port if needed
authorization_prompt_message='Please visit this URL: {url}',
success_message='The auth flow is complete; you may close this window.',
open_browser=True)
# Save the credentials for the next run
with open("token.json", "w") as token:
token.write(credentials.to_json())
Expand Down
24 changes: 12 additions & 12 deletions proper_gator/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,12 @@ def cli():
help="Containers to exclude from the cloning process."
"Format names of containers separated with commas.",
)
@click.option(
"--include-containers",
default=None,
help="The only containers to include for the cloning process."
"Format names of containers separated with commas.",
)
@click.option(
"--target-workspace",
default="proper_gator_staging",
Expand All @@ -59,21 +65,12 @@ def cli():
)
@click.option(
"--target-container",
default="Biopharma Dive",
default="BioPharma Dive",
show_default=True,
help="The container to clone from",
)
def clone(
target_container,
target_workspace,
exclude_containers,
exclude_variables,
exclude_triggers,
exclude_tags,
only_variables,
only_triggers,
only_tags,
):
def clone(target_container, target_workspace, exclude_containers, include_containers, exclude_variables,
exclude_triggers, exclude_tags, only_variables, only_triggers, only_tags):
"""
Clone tags from the target container to other containers in the same account
"""
Expand All @@ -83,6 +80,8 @@ def split_and_trim(str):

if exclude_containers:
exclude_containers = split_and_trim(exclude_containers)
if include_containers:
include_containers = split_and_trim(include_containers)
if exclude_variables:
exclude_variables = split_and_trim(exclude_variables)
if exclude_triggers:
Expand All @@ -100,6 +99,7 @@ def split_and_trim(str):
target_container,
target_workspace,
exclude_containers,
include_containers,
exclude_variables,
exclude_triggers,
exclude_tags,
Expand Down
11 changes: 8 additions & 3 deletions proper_gator/containers.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ def find_target_container(container_wrapper, container_name):


def find_destination_containers(
container_wrapper, target_container, exclude_containers=None
container_wrapper, target_container, exclude_containers=None, include_containers=None
):
"""Search through a collection of containers and return all containers
other than the given container
Expand All @@ -47,6 +47,7 @@ def find_destination_containers(
returned list
:type target_container: dict
:param exclude_containers: A list of containers to exclude from being cloned to
:param include_containers: A list of containers to include from being cloned to
:type exclude_containers: list
:return: A list of Google Tag Manager container objects
:rtype: list
Expand All @@ -55,9 +56,13 @@ def find_destination_containers(
exclude_containers = []
destination_containers = []
for container in container_wrapper["container"]:
container_is_target_container = container["containerId"] == target_container["containerId"]
container_is_included = container["name"] in include_containers if include_containers else True
container_is_excluded = container["name"] in exclude_containers
if (
not container["containerId"] == target_container["containerId"]
and container["name"] not in exclude_containers
not container_is_target_container
and container_is_included
and not container_is_excluded
):
destination_containers.append(container)
return destination_containers
5 changes: 3 additions & 2 deletions proper_gator/proper_gator.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,10 @@


def clone(
container_name="Biopharma Dive",
container_name="BioPharma Dive",
workspace_name="proper_gator_staging",
exclude_containers=None,
include_containers=None,
exclude_variables=None,
exclude_triggers=None,
exclude_tags=None,
Expand All @@ -40,7 +41,7 @@ def clone(
containers = get_containers(service, ACCOUNT_ID)
target_container = find_target_container(containers, container_name)
destination_containers = find_destination_containers(
containers, target_container, exclude_containers
containers, target_container, exclude_containers, include_containers
)

target_container_workspaces = get_workspaces(service, target_container)
Expand Down
4 changes: 2 additions & 2 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
[tool.poetry]
name = "proper-gator"
version = "0.2.0"
version = "0.3.0"
description = ""
authors = ["Colin Burr <cburr@industrydive.com>"]
authors = ["Colin Burr <cburr@industrydive.com>", "Eric Chan <echan@industrydive.com>"]

[tool.poetry.dependencies]
python = "^3.7"
Expand Down

0 comments on commit afc4753

Please sign in to comment.