Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
85 changes: 85 additions & 0 deletions .github/workflows/update_connection.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
name: update_connection

on:
workflow_dispatch:
inputs:
env_url:
description: "Select source and target env's"
type: choice
default: "Source: SANDBOX, Target: PRODUCTION"
options:
- "Source: SANDBOX, Target: PRODUCTION"
- "Source: SANDBOX, Target: SANDBOX"
- "Source: PRODUCTION, Target: PRODUCTION"
- "Source: PRODUCTION, Target: SANDBOX"
source_connection_id:
description: "Source Connection ID"
required: false
target_connection_id:
description: "Target Connection ID"
required: true
source_account_access_token:
description: "Access token of the Source Account"
required: false
target_account_access_token:
description: "Access token of the Target Account"
required: true
source_account_id:
description: "Source Account ID. If not provided, will use the repository variable"
required: false
target_account_id:
description: "Target Account ID. If not provided, will use the repository variable"
required: false


jobs:
execute-update-connection-script:
runs-on: ubuntu-latest

steps:
- name: Checkout code
uses: actions/checkout@v4

- name: Set up Python
uses: actions/setup-python@v5
with:
python-version: "3.x"

- name: Install dependencies
run: pip install requests

- name: Parse and map environment URLs
id: map_envs
shell: bash
run: |
input="${{ github.event.inputs.env_url }}"

source_name=$(echo "$input" | sed -n 's/Source: \([^,]*\),.*/\1/p' | xargs)
target_name=$(echo "$input" | sed -n 's/.*Target: \(.*\)/\1/p' | xargs)

get_env_url() {
case "$1" in
SANDBOX) echo "https://manage.skyflowapis-preview.com" ;;
PRODUCTION) echo "https://manage.skyflowapis.com" ;;
*) echo "Invalid environment: $1" >&2; exit 1 ;;
esac
}

# Resolve URLs
source_url=$(get_env_url "$source_name")
target_url=$(get_env_url "$target_name")

echo "source_url=$source_url" >> $GITHUB_OUTPUT
echo "target_url=$target_url" >> $GITHUB_OUTPUT

- name: Run Python script
env:
SOURCE_CONNECTION_ID: ${{ github.event.inputs.source_connection_id }}
TARGET_CONNECTION_ID: ${{ github.event.inputs.target_connection_id }}
SOURCE_ACCOUNT_AUTH: ${{ github.event.inputs.source_account_access_token }}
TARGET_ACCOUNT_AUTH: ${{ github.event.inputs.target_account_access_token }}
SOURCE_ACCOUNT_ID: ${{ github.event.inputs.source_account_id != '' && github.event.inputs.source_account_id || vars.SOURCE_ACCOUNT_ID }}
TARGET_ACCOUNT_ID: ${{ github.event.inputs.target_account_id != '' && github.event.inputs.target_account_id || vars.TARGET_ACCOUNT_ID }}
SOURCE_ENV_URL: ${{ steps.map_envs.outputs.source_url }}
TARGET_ENV_URL: ${{ steps.map_envs.outputs.target_url }}
run: python3 update_connection.py
4 changes: 2 additions & 2 deletions migrate_connections.py
Original file line number Diff line number Diff line change
Expand Up @@ -128,10 +128,10 @@ def main(connection_ids=None):
print(
f"-- migrate_connections HTTP error: {http_err.response.content.decode()} --"
)
raise http_err
exit(1)
except Exception as err:
print(f"-- migrate_connections other error: {err} --")
raise err
exit(1)


if __name__ == "__main__":
Expand Down
4 changes: 2 additions & 2 deletions migrate_pipelines.py
Original file line number Diff line number Diff line change
Expand Up @@ -219,10 +219,10 @@ def main(pipeline_id: str) -> None:
print(
f"-- migrate_pipelines HTTP error: {http_err.response.content.decode()} --"
)
raise http_err
exit(1)
except Exception as err:
print(f"-- migrate_pipelines other error: {err} --")
raise err
exit(1)


if __name__ == "__main__":
Expand Down
4 changes: 2 additions & 2 deletions migrate_policies.py
Original file line number Diff line number Diff line change
Expand Up @@ -111,10 +111,10 @@ def main(policy_ids=None):
return policies_created
except requests.exceptions.HTTPError as http_err:
print(f'-- migrate_policies HTTP error: {http_err.response.content.decode()} --')
raise http_err
exit(1)
except Exception as err:
print(f"-- migrate_policies error: {err} --")
raise err
exit(1)


if __name__ == "__main__":
Expand Down
8 changes: 4 additions & 4 deletions migrate_roles.py
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@ def main(role_ids=None):
roles_created.append({"ID" : role_response["roles"][0]["ID"]})
else:
print("-- Role does not exist --")
if(should_create_role):
if should_create_role:
role_payload = transform_role_payload(role_info)
print(f"-- Creating role: {role_name} --")
new_role = create_role(role_payload)
Expand All @@ -160,7 +160,7 @@ def main(role_ids=None):
role_policies = get_role_policies(role_id)
policy_ids = [policy["ID"] for policy in role_policies["policies"]]
no_of_policies = len(policy_ids)
if(no_of_policies == 0):
if no_of_policies == 0:
print('-- No policies found for the given role --')
else:
print(f"-- Working on policies migration. No. of policies found for given role: {no_of_policies} --")
Expand All @@ -173,10 +173,10 @@ def main(role_ids=None):
except requests.exceptions.HTTPError as http_err:
print(f'-- Role creation failed for {role_name if role_name else ""}, ID: {role_id}. --')
print(f'-- migrate_roles HTTP error: {http_err.response.content.decode()} --')
raise http_err
exit(1)
except Exception as err:
print(f'-- migrate_roles error: {err} --')
raise err
exit(1)

if __name__ == "__main__":
main()
4 changes: 2 additions & 2 deletions migrate_service_accounts.py
Original file line number Diff line number Diff line change
Expand Up @@ -124,10 +124,10 @@ def main(service_accounts_ids=None):
print(
f"-- migrate_service_accounts HTTP error: {http_err.response.content.decode()} --"
)
raise http_err
exit(1)
except Exception as err:
print(f"-- migrate_service_accounts other error: {err} --")
raise err
exit(1)


if __name__ == "__main__":
Expand Down
2 changes: 1 addition & 1 deletion pytest.ini
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
[pytest]
addopts = -q --cov=. --cov-report=term-missing --cov-fail-under=95
addopts = -q --cov=. --cov-report=term-missing --cov-fail-under=98
testpaths = tests
6 changes: 4 additions & 2 deletions tests/test_migrate_connections.py
Original file line number Diff line number Diff line change
Expand Up @@ -104,8 +104,9 @@ def raise_err(*args, **kwargs):
monkeypatch.setattr(mc, "SOURCE_ENV_URL", "https://s")
mock_get.side_effect = raise_err

with pytest.raises(requests.exceptions.HTTPError):
with pytest.raises(SystemExit) as excinfo:
mc.main()
assert excinfo.value.code == 1


def test_main_migrate_all_with_source_calls_list(monkeypatch):
Expand All @@ -132,8 +133,9 @@ def boom(_):
raise Exception("boom")

monkeypatch.setattr(mc, "get_connection", boom)
with pytest.raises(Exception):
with pytest.raises(SystemExit) as excinfo:
mc.main()
assert excinfo.value.code == 1


def test_run_as_script_config_file(monkeypatch):
Expand Down
6 changes: 4 additions & 2 deletions tests/test_migrate_pipelines.py
Original file line number Diff line number Diff line change
Expand Up @@ -361,8 +361,9 @@ def raise_http_error(_):

monkeypatch.setattr(module, "get_pipeline", raise_http_error)

with pytest.raises(requests.exceptions.HTTPError):
with pytest.raises(SystemExit) as excinfo:
module.main("pipeline-http-error")
assert excinfo.value.code == 1

stdout = capsys.readouterr().out
assert "HTTP error" in stdout
Expand All @@ -378,8 +379,9 @@ def boom(_payload):

monkeypatch.setattr(module, "create_pipeline", boom)

with pytest.raises(RuntimeError):
with pytest.raises(SystemExit) as excinfo:
module.main("pipeline-other-error")
assert excinfo.value.code == 1

stdout = capsys.readouterr().out
assert "other error" in stdout
Expand Down
6 changes: 4 additions & 2 deletions tests/test_migrate_policies.py
Original file line number Diff line number Diff line change
Expand Up @@ -110,8 +110,9 @@ def raise_err(_):
raise err

monkeypatch.setattr(mp, "get_policy", raise_err)
with pytest.raises(requests.exceptions.HTTPError):
with pytest.raises(SystemExit) as excinfo:
mp.main(policy_ids=["p1"])
assert excinfo.value.code == 1


def test_main_generic_exception(monkeypatch):
Expand All @@ -121,8 +122,9 @@ def test_main_generic_exception(monkeypatch):
"transform_policy_payload",
lambda _: (_ for _ in ()).throw(Exception("boom")),
)
with pytest.raises(Exception):
with pytest.raises(SystemExit) as excinfo:
mp.main(policy_ids=["p1"])
assert excinfo.value.code == 1


def test_run_as_script(monkeypatch):
Expand Down
12 changes: 8 additions & 4 deletions tests/test_migrate_roles.py
Original file line number Diff line number Diff line change
Expand Up @@ -175,8 +175,9 @@ def raise_err(*args, **kwargs):
monkeypatch.setattr(mr, "TARGET_ENV_URL", "https://t")
monkeypatch.setattr(mr, "get_role", lambda _id: role_resp.json())
monkeypatch.setattr(mr, "get_system_role", raise_err)
with pytest.raises(requests.exceptions.HTTPError):
with pytest.raises(SystemExit) as excinfo:
mr.main()
assert excinfo.value.code == 1


@patch("migrate_roles.requests.post")
Expand All @@ -186,8 +187,9 @@ def test_migrate_all_missing_source_prints(mock_get, mock_post, monkeypatch):
monkeypatch.setattr(mr, "SOURCE_VAULT_ID", None, raising=False)
monkeypatch.setattr(mr, "ROLE_IDS", "[]", raising=False)
# Function prints a message then later attempts to iterate None; assert it errors predictably
with pytest.raises(TypeError):
with pytest.raises(SystemExit) as excinfo:
mr.main()
assert excinfo.value.code == 1


@patch("migrate_roles.requests.post")
Expand Down Expand Up @@ -251,8 +253,9 @@ def raise_err(*args, **kwargs):

mock_post.side_effect = raise_err

with pytest.raises(requests.exceptions.HTTPError):
with pytest.raises(SystemExit) as excinfo:
mr.main()
assert excinfo.value.code == 1


@patch("migrate_roles.requests.post")
Expand All @@ -279,8 +282,9 @@ def test_generic_exception_after_role_name(mock_get, mock_post, monkeypatch):
monkeypatch.setattr(
mr, "get_role_policies", lambda _id: (_ for _ in ()).throw(Exception("oops"))
)
with pytest.raises(Exception):
with pytest.raises(SystemExit) as excinfo:
mr.main()
assert excinfo.value.code == 1


def test_run_as_script(monkeypatch):
Expand Down
6 changes: 4 additions & 2 deletions tests/test_migrate_service_accounts.py
Original file line number Diff line number Diff line change
Expand Up @@ -107,8 +107,9 @@ def raise_err(_):

monkeypatch.setattr(msa, "SERVICE_ACCOUNT_IDS", "['sa1']", raising=False)
monkeypatch.setattr(msa, "get_service_account", raise_err)
with pytest.raises(requests.exceptions.HTTPError):
with pytest.raises(SystemExit) as excinfo:
msa.main()
assert excinfo.value.code == 1


def test_generic_exception_branch(monkeypatch):
Expand All @@ -132,8 +133,9 @@ def test_generic_exception_branch(monkeypatch):
"create_service_account",
lambda x: (_ for _ in ()).throw(Exception("boom")),
)
with pytest.raises(Exception):
with pytest.raises(SystemExit) as excinfo:
msa.main()
assert excinfo.value.code == 1


def test_run_as_script(monkeypatch):
Expand Down
Loading