Skip to content

Commit ab8ca5b

Browse files
Merge pull request #7 from SkyflowFoundry/IE-532
IE-532: added support to update connections
2 parents bb98827 + 728e72e commit ab8ca5b

21 files changed

Lines changed: 400 additions & 39 deletions
Lines changed: 85 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,85 @@
1+
name: update_connection
2+
3+
on:
4+
workflow_dispatch:
5+
inputs:
6+
env_url:
7+
description: "Select source and target env's"
8+
type: choice
9+
default: "Source: SANDBOX, Target: PRODUCTION"
10+
options:
11+
- "Source: SANDBOX, Target: PRODUCTION"
12+
- "Source: SANDBOX, Target: SANDBOX"
13+
- "Source: PRODUCTION, Target: PRODUCTION"
14+
- "Source: PRODUCTION, Target: SANDBOX"
15+
source_connection_id:
16+
description: "Source Connection ID"
17+
required: false
18+
target_connection_id:
19+
description: "Target Connection ID"
20+
required: true
21+
source_account_access_token:
22+
description: "Access token of the Source Account"
23+
required: false
24+
target_account_access_token:
25+
description: "Access token of the Target Account"
26+
required: true
27+
source_account_id:
28+
description: "Source Account ID. If not provided, will use the repository variable"
29+
required: false
30+
target_account_id:
31+
description: "Target Account ID. If not provided, will use the repository variable"
32+
required: false
33+
34+
35+
jobs:
36+
execute-update-connection-script:
37+
runs-on: ubuntu-latest
38+
39+
steps:
40+
- name: Checkout code
41+
uses: actions/checkout@v4
42+
43+
- name: Set up Python
44+
uses: actions/setup-python@v5
45+
with:
46+
python-version: "3.x"
47+
48+
- name: Install dependencies
49+
run: pip install requests
50+
51+
- name: Parse and map environment URLs
52+
id: map_envs
53+
shell: bash
54+
run: |
55+
input="${{ github.event.inputs.env_url }}"
56+
57+
source_name=$(echo "$input" | sed -n 's/Source: \([^,]*\),.*/\1/p' | xargs)
58+
target_name=$(echo "$input" | sed -n 's/.*Target: \(.*\)/\1/p' | xargs)
59+
60+
get_env_url() {
61+
case "$1" in
62+
SANDBOX) echo "https://manage.skyflowapis-preview.com" ;;
63+
PRODUCTION) echo "https://manage.skyflowapis.com" ;;
64+
*) echo "Invalid environment: $1" >&2; exit 1 ;;
65+
esac
66+
}
67+
68+
# Resolve URLs
69+
source_url=$(get_env_url "$source_name")
70+
target_url=$(get_env_url "$target_name")
71+
72+
echo "source_url=$source_url" >> $GITHUB_OUTPUT
73+
echo "target_url=$target_url" >> $GITHUB_OUTPUT
74+
75+
- name: Run Python script
76+
env:
77+
SOURCE_CONNECTION_ID: ${{ github.event.inputs.source_connection_id }}
78+
TARGET_CONNECTION_ID: ${{ github.event.inputs.target_connection_id }}
79+
SOURCE_ACCOUNT_AUTH: ${{ github.event.inputs.source_account_access_token }}
80+
TARGET_ACCOUNT_AUTH: ${{ github.event.inputs.target_account_access_token }}
81+
SOURCE_ACCOUNT_ID: ${{ github.event.inputs.source_account_id != '' && github.event.inputs.source_account_id || vars.SOURCE_ACCOUNT_ID }}
82+
TARGET_ACCOUNT_ID: ${{ github.event.inputs.target_account_id != '' && github.event.inputs.target_account_id || vars.TARGET_ACCOUNT_ID }}
83+
SOURCE_ENV_URL: ${{ steps.map_envs.outputs.source_url }}
84+
TARGET_ENV_URL: ${{ steps.map_envs.outputs.target_url }}
85+
run: python3 update_connection.py

migrate_connections.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -128,10 +128,10 @@ def main(connection_ids=None):
128128
print(
129129
f"-- migrate_connections HTTP error: {http_err.response.content.decode()} --"
130130
)
131-
raise http_err
131+
exit(1)
132132
except Exception as err:
133133
print(f"-- migrate_connections other error: {err} --")
134-
raise err
134+
exit(1)
135135

136136

137137
if __name__ == "__main__":

migrate_pipelines.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -219,10 +219,10 @@ def main(pipeline_id: str) -> None:
219219
print(
220220
f"-- migrate_pipelines HTTP error: {http_err.response.content.decode()} --"
221221
)
222-
raise http_err
222+
exit(1)
223223
except Exception as err:
224224
print(f"-- migrate_pipelines other error: {err} --")
225-
raise err
225+
exit(1)
226226

227227

228228
if __name__ == "__main__":

migrate_policies.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -111,10 +111,10 @@ def main(policy_ids=None):
111111
return policies_created
112112
except requests.exceptions.HTTPError as http_err:
113113
print(f'-- migrate_policies HTTP error: {http_err.response.content.decode()} --')
114-
raise http_err
114+
exit(1)
115115
except Exception as err:
116116
print(f"-- migrate_policies error: {err} --")
117-
raise err
117+
exit(1)
118118

119119

120120
if __name__ == "__main__":

migrate_roles.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -151,7 +151,7 @@ def main(role_ids=None):
151151
roles_created.append({"ID" : role_response["roles"][0]["ID"]})
152152
else:
153153
print("-- Role does not exist --")
154-
if(should_create_role):
154+
if should_create_role:
155155
role_payload = transform_role_payload(role_info)
156156
print(f"-- Creating role: {role_name} --")
157157
new_role = create_role(role_payload)
@@ -160,7 +160,7 @@ def main(role_ids=None):
160160
role_policies = get_role_policies(role_id)
161161
policy_ids = [policy["ID"] for policy in role_policies["policies"]]
162162
no_of_policies = len(policy_ids)
163-
if(no_of_policies == 0):
163+
if no_of_policies == 0:
164164
print('-- No policies found for the given role --')
165165
else:
166166
print(f"-- Working on policies migration. No. of policies found for given role: {no_of_policies} --")
@@ -173,10 +173,10 @@ def main(role_ids=None):
173173
except requests.exceptions.HTTPError as http_err:
174174
print(f'-- Role creation failed for {role_name if role_name else ""}, ID: {role_id}. --')
175175
print(f'-- migrate_roles HTTP error: {http_err.response.content.decode()} --')
176-
raise http_err
176+
exit(1)
177177
except Exception as err:
178178
print(f'-- migrate_roles error: {err} --')
179-
raise err
179+
exit(1)
180180

181181
if __name__ == "__main__":
182182
main()

migrate_service_accounts.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -124,10 +124,10 @@ def main(service_accounts_ids=None):
124124
print(
125125
f"-- migrate_service_accounts HTTP error: {http_err.response.content.decode()} --"
126126
)
127-
raise http_err
127+
exit(1)
128128
except Exception as err:
129129
print(f"-- migrate_service_accounts other error: {err} --")
130-
raise err
130+
exit(1)
131131

132132

133133
if __name__ == "__main__":

pytest.ini

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
[pytest]
2-
addopts = -q --cov=. --cov-report=term-missing --cov-fail-under=95
2+
addopts = -q --cov=. --cov-report=term-missing --cov-fail-under=98
33
testpaths = tests

tests/test_migrate_connections.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -104,8 +104,9 @@ def raise_err(*args, **kwargs):
104104
monkeypatch.setattr(mc, "SOURCE_ENV_URL", "https://s")
105105
mock_get.side_effect = raise_err
106106

107-
with pytest.raises(requests.exceptions.HTTPError):
107+
with pytest.raises(SystemExit) as excinfo:
108108
mc.main()
109+
assert excinfo.value.code == 1
109110

110111

111112
def test_main_migrate_all_with_source_calls_list(monkeypatch):
@@ -132,8 +133,9 @@ def boom(_):
132133
raise Exception("boom")
133134

134135
monkeypatch.setattr(mc, "get_connection", boom)
135-
with pytest.raises(Exception):
136+
with pytest.raises(SystemExit) as excinfo:
136137
mc.main()
138+
assert excinfo.value.code == 1
137139

138140

139141
def test_run_as_script_config_file(monkeypatch):

tests/test_migrate_pipelines.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -361,8 +361,9 @@ def raise_http_error(_):
361361

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

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

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

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

381-
with pytest.raises(RuntimeError):
382+
with pytest.raises(SystemExit) as excinfo:
382383
module.main("pipeline-other-error")
384+
assert excinfo.value.code == 1
383385

384386
stdout = capsys.readouterr().out
385387
assert "other error" in stdout

tests/test_migrate_policies.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -110,8 +110,9 @@ def raise_err(_):
110110
raise err
111111

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

116117

117118
def test_main_generic_exception(monkeypatch):
@@ -121,8 +122,9 @@ def test_main_generic_exception(monkeypatch):
121122
"transform_policy_payload",
122123
lambda _: (_ for _ in ()).throw(Exception("boom")),
123124
)
124-
with pytest.raises(Exception):
125+
with pytest.raises(SystemExit) as excinfo:
125126
mp.main(policy_ids=["p1"])
127+
assert excinfo.value.code == 1
126128

127129

128130
def test_run_as_script(monkeypatch):

0 commit comments

Comments
 (0)