kaqing 2.0.171__py3-none-any.whl → 2.0.203__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- adam/app_session.py +5 -10
- adam/apps.py +18 -4
- adam/batch.py +7 -7
- adam/checks/check_utils.py +3 -1
- adam/checks/disk.py +2 -3
- adam/columns/memory.py +3 -4
- adam/commands/__init__.py +15 -6
- adam/commands/alter_tables.py +26 -41
- adam/commands/app/__init__.py +0 -0
- adam/commands/{app_cmd.py → app/app.py} +2 -2
- adam/commands/{show → app}/show_app_actions.py +7 -15
- adam/commands/{show → app}/show_app_queues.py +1 -4
- adam/{utils_app.py → commands/app/utils_app.py} +9 -1
- adam/commands/audit/audit.py +9 -26
- adam/commands/audit/audit_repair_tables.py +5 -7
- adam/commands/audit/audit_run.py +1 -1
- adam/commands/audit/completions_l.py +15 -0
- adam/commands/audit/show_last10.py +2 -14
- adam/commands/audit/show_slow10.py +2 -13
- adam/commands/audit/show_top10.py +2 -11
- adam/commands/audit/utils_show_top10.py +15 -3
- adam/commands/bash/bash.py +1 -1
- adam/commands/bash/utils_bash.py +1 -1
- adam/commands/cassandra/__init__.py +0 -0
- adam/commands/cassandra/download_cassandra_log.py +45 -0
- adam/commands/cassandra/nodetool.py +64 -0
- adam/commands/cassandra/nodetool_commands.py +120 -0
- adam/commands/cassandra/restart_cluster.py +47 -0
- adam/commands/cassandra/restart_node.py +51 -0
- adam/commands/cassandra/restart_nodes.py +47 -0
- adam/commands/cassandra/rollout.py +88 -0
- adam/commands/cat.py +5 -19
- adam/commands/cd.py +7 -9
- adam/commands/check.py +10 -18
- adam/commands/cli_commands.py +6 -1
- adam/commands/{cp.py → clipboard_copy.py} +34 -36
- adam/commands/code.py +2 -2
- adam/commands/command.py +139 -22
- adam/commands/commands_utils.py +14 -12
- adam/commands/cql/alter_tables.py +66 -0
- adam/commands/cql/completions_c.py +29 -0
- adam/commands/cql/cqlsh.py +3 -7
- adam/commands/cql/utils_cql.py +23 -61
- adam/commands/debug/__init__.py +0 -0
- adam/commands/debug/debug.py +22 -0
- adam/commands/debug/debug_completes.py +35 -0
- adam/commands/debug/debug_timings.py +35 -0
- adam/commands/deploy/deploy_pg_agent.py +2 -2
- adam/commands/deploy/deploy_pod.py +2 -4
- adam/commands/deploy/undeploy_pg_agent.py +2 -2
- adam/commands/devices/device.py +40 -9
- adam/commands/devices/device_app.py +19 -29
- adam/commands/devices/device_auit_log.py +3 -3
- adam/commands/devices/device_cass.py +17 -23
- adam/commands/devices/device_export.py +12 -11
- adam/commands/devices/device_postgres.py +79 -63
- adam/commands/devices/devices.py +1 -1
- adam/commands/download_cassandra_log.py +45 -0
- adam/commands/download_file.py +47 -0
- adam/commands/export/clean_up_all_export_sessions.py +3 -3
- adam/commands/export/clean_up_export_sessions.py +7 -19
- adam/commands/export/completions_x.py +11 -0
- adam/commands/export/download_export_session.py +40 -0
- adam/commands/export/drop_export_database.py +6 -22
- adam/commands/export/drop_export_databases.py +3 -9
- adam/commands/export/export.py +1 -17
- adam/commands/export/export_databases.py +109 -32
- adam/commands/export/export_select.py +8 -55
- adam/commands/export/export_sessions.py +211 -0
- adam/commands/export/export_use.py +13 -16
- adam/commands/export/export_x_select.py +48 -0
- adam/commands/export/exporter.py +176 -167
- adam/commands/export/import_files.py +44 -0
- adam/commands/export/import_session.py +10 -6
- adam/commands/export/importer.py +24 -9
- adam/commands/export/importer_athena.py +114 -44
- adam/commands/export/importer_sqlite.py +45 -23
- adam/commands/export/show_column_counts.py +11 -20
- adam/commands/export/show_export_databases.py +5 -2
- adam/commands/export/show_export_session.py +6 -15
- adam/commands/export/show_export_sessions.py +4 -11
- adam/commands/export/utils_export.py +79 -27
- adam/commands/find_files.py +51 -0
- adam/commands/find_processes.py +76 -0
- adam/commands/generate_report.py +52 -0
- adam/commands/head.py +36 -0
- adam/commands/help.py +2 -2
- adam/commands/intermediate_command.py +6 -3
- adam/commands/login.py +3 -6
- adam/commands/ls.py +2 -2
- adam/commands/medusa/medusa_backup.py +13 -16
- adam/commands/medusa/medusa_restore.py +26 -37
- adam/commands/medusa/medusa_show_backupjobs.py +7 -7
- adam/commands/medusa/medusa_show_restorejobs.py +6 -6
- adam/commands/medusa/utils_medusa.py +15 -0
- adam/commands/nodetool.py +3 -8
- adam/commands/os/__init__.py +0 -0
- adam/commands/os/cat.py +36 -0
- adam/commands/os/download_file.py +47 -0
- adam/commands/os/find_files.py +51 -0
- adam/commands/os/find_processes.py +76 -0
- adam/commands/os/head.py +36 -0
- adam/commands/os/shell.py +41 -0
- adam/commands/param_get.py +10 -12
- adam/commands/param_set.py +7 -10
- adam/commands/postgres/completions_p.py +22 -0
- adam/commands/postgres/postgres.py +25 -40
- adam/commands/postgres/postgres_databases.py +269 -0
- adam/commands/postgres/utils_postgres.py +33 -20
- adam/commands/preview_table.py +4 -2
- adam/commands/pwd.py +4 -6
- adam/commands/reaper/reaper_forward.py +2 -2
- adam/commands/reaper/reaper_run_abort.py +4 -10
- adam/commands/reaper/reaper_runs.py +3 -3
- adam/commands/reaper/reaper_schedule_activate.py +12 -12
- adam/commands/reaper/reaper_schedule_start.py +7 -12
- adam/commands/reaper/reaper_schedule_stop.py +7 -12
- adam/commands/reaper/utils_reaper.py +13 -6
- adam/commands/repair/repair_log.py +1 -4
- adam/commands/repair/repair_run.py +3 -8
- adam/commands/repair/repair_scan.py +1 -6
- adam/commands/repair/repair_stop.py +1 -5
- adam/commands/restart_cluster.py +47 -0
- adam/commands/restart_node.py +51 -0
- adam/commands/restart_nodes.py +47 -0
- adam/commands/shell.py +9 -2
- adam/commands/show/show.py +4 -4
- adam/commands/show/show_adam.py +3 -3
- adam/commands/show/show_cassandra_repairs.py +5 -6
- adam/commands/show/show_cassandra_status.py +29 -29
- adam/commands/show/show_cassandra_version.py +1 -4
- adam/commands/show/{show_commands.py → show_cli_commands.py} +3 -6
- adam/commands/show/show_login.py +3 -9
- adam/commands/show/show_params.py +2 -5
- adam/commands/show/show_processes.py +15 -16
- adam/commands/show/show_storage.py +9 -8
- adam/config.py +4 -5
- adam/embedded_params.py +1 -1
- adam/log.py +4 -4
- adam/repl.py +26 -18
- adam/repl_commands.py +32 -20
- adam/repl_session.py +9 -1
- adam/repl_state.py +39 -10
- adam/sql/async_executor.py +44 -0
- adam/sql/lark_completer.py +286 -0
- adam/sql/lark_parser.py +604 -0
- adam/sql/qingl.lark +1076 -0
- adam/sql/sql_completer.py +4 -6
- adam/sql/sql_state_machine.py +25 -13
- adam/sso/authn_ad.py +2 -5
- adam/sso/authn_okta.py +2 -4
- adam/sso/cred_cache.py +2 -5
- adam/sso/idp.py +8 -11
- adam/utils.py +299 -105
- adam/utils_athena.py +18 -18
- adam/utils_audits.py +3 -7
- adam/utils_issues.py +2 -2
- adam/utils_k8s/app_clusters.py +4 -4
- adam/utils_k8s/app_pods.py +8 -6
- adam/utils_k8s/cassandra_clusters.py +16 -5
- adam/utils_k8s/cassandra_nodes.py +9 -6
- adam/utils_k8s/custom_resources.py +11 -17
- adam/utils_k8s/jobs.py +7 -11
- adam/utils_k8s/k8s.py +14 -5
- adam/utils_k8s/kube_context.py +3 -6
- adam/{pod_exec_result.py → utils_k8s/pod_exec_result.py} +4 -4
- adam/utils_k8s/pods.py +85 -23
- adam/utils_k8s/statefulsets.py +5 -2
- adam/utils_local.py +42 -0
- adam/utils_repl/appendable_completer.py +6 -0
- adam/utils_repl/repl_completer.py +45 -2
- adam/utils_repl/state_machine.py +3 -3
- adam/utils_sqlite.py +58 -30
- adam/version.py +1 -1
- {kaqing-2.0.171.dist-info → kaqing-2.0.203.dist-info}/METADATA +1 -1
- kaqing-2.0.203.dist-info/RECORD +277 -0
- kaqing-2.0.203.dist-info/top_level.txt +2 -0
- teddy/__init__.py +0 -0
- teddy/lark_parser.py +436 -0
- teddy/lark_parser2.py +618 -0
- adam/commands/cql/cql_completions.py +0 -33
- adam/commands/export/export_handlers.py +0 -71
- adam/commands/export/export_select_x.py +0 -54
- adam/commands/logs.py +0 -37
- adam/commands/postgres/postgres_context.py +0 -274
- adam/commands/postgres/psql_completions.py +0 -10
- adam/commands/report.py +0 -61
- adam/commands/restart.py +0 -60
- kaqing-2.0.171.dist-info/RECORD +0 -236
- kaqing-2.0.171.dist-info/top_level.txt +0 -1
- /adam/commands/{app_ping.py → app/app_ping.py} +0 -0
- /adam/commands/{show → app}/show_app_id.py +0 -0
- {kaqing-2.0.171.dist-info → kaqing-2.0.203.dist-info}/WHEEL +0 -0
- {kaqing-2.0.171.dist-info → kaqing-2.0.203.dist-info}/entry_points.txt +0 -0
adam/sql/sql_completer.py
CHANGED
|
@@ -2,7 +2,7 @@ from enum import Enum
|
|
|
2
2
|
from typing import Callable
|
|
3
3
|
|
|
4
4
|
import sqlparse
|
|
5
|
-
from sqlparse.sql import
|
|
5
|
+
from sqlparse.sql import Token
|
|
6
6
|
|
|
7
7
|
from adam.sql.term_completer import TermCompleter
|
|
8
8
|
from adam.utils_repl.automata_completer import AutomataCompleter
|
|
@@ -26,11 +26,9 @@ class SqlCompleter(AutomataCompleter[Token]):
|
|
|
26
26
|
tokens = []
|
|
27
27
|
|
|
28
28
|
stmts = sqlparse.parse(text)
|
|
29
|
-
if
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
statement: Statement = stmts[0]
|
|
33
|
-
tokens = statement.tokens
|
|
29
|
+
if stmts:
|
|
30
|
+
for stmt in stmts:
|
|
31
|
+
tokens.extend(stmt.tokens)
|
|
34
32
|
|
|
35
33
|
return tokens
|
|
36
34
|
|
adam/sql/sql_state_machine.py
CHANGED
|
@@ -2,6 +2,7 @@ from typing import Callable
|
|
|
2
2
|
from sqlparse.sql import Token
|
|
3
3
|
from sqlparse import tokens as TOKEN
|
|
4
4
|
|
|
5
|
+
from adam.utils import log_exc
|
|
5
6
|
from adam.utils_repl.state_machine import StateMachine, State
|
|
6
7
|
|
|
7
8
|
__all__ = [
|
|
@@ -77,8 +78,7 @@ SQL_SPEC = [
|
|
|
77
78
|
'select_from_sq_ > as > select_from_x_as ^ as',
|
|
78
79
|
'select_from_x_comma_ > name|audit > select_from_x ^ tables',
|
|
79
80
|
'select_from_x_ ^ as,where,inner join,left outer join,right outer join,full outer join,group by,order by,limit,&',
|
|
80
|
-
'
|
|
81
|
-
'select_from_x_as_x_ > , > select_from_x_comma_ ^ where,inner join,left outer join,right outer join,full outer join,group by,order by,limit',
|
|
81
|
+
'select_from_x_as_x_ > , > select_from_x_comma_ ^ where,inner join,left outer join,right outer join,full outer join,group by,order by,limit,&',
|
|
82
82
|
'- > as > select_from_x_as',
|
|
83
83
|
'- > where > select_where',
|
|
84
84
|
'- > order > select_order',
|
|
@@ -97,6 +97,7 @@ SQL_SPEC = [
|
|
|
97
97
|
'- > full > select_from_x_full',
|
|
98
98
|
'- > full outer join > select_join',
|
|
99
99
|
'- > ; > ',
|
|
100
|
+
'- > & > select_from_x$',
|
|
100
101
|
'select_from_x_as_ > name > select_from_x_as_x ^ x,y,z',
|
|
101
102
|
'select_from_x_as_x > , > select_from_x_as_x_comma_',
|
|
102
103
|
'- > ; > ',
|
|
@@ -119,34 +120,38 @@ SQL_SPEC = [
|
|
|
119
120
|
'select_where_a_not_op > name|single|num > select_where_sc ^ single',
|
|
120
121
|
'select_where_a_op > name|single|num > select_where_sc ^ single',
|
|
121
122
|
'select_where_sc > ; > ',
|
|
122
|
-
'select_where_sc_ > and|or > select_where ^ and,or,order by,group by,limit',
|
|
123
|
+
'select_where_sc_ > and|or > select_where ^ and,or,order by,group by,limit,&',
|
|
123
124
|
'- > group > select_group',
|
|
124
125
|
'- > group by > select_group_by',
|
|
125
126
|
'- > order > select_order',
|
|
126
127
|
'- > order by > select_order_by',
|
|
127
128
|
'- > limit > select_where_sc_limit',
|
|
128
129
|
'- > ; > ',
|
|
130
|
+
'- > & > select_from_x$',
|
|
129
131
|
'select_group_ > by > select_group_by ^ by',
|
|
130
132
|
'select_group_by_ > name > select_group_by_a ^ columns',
|
|
131
133
|
'select_group_by_a > , > select_group_by_a_comma_ ^ columns',
|
|
132
134
|
'- > ; > ',
|
|
133
135
|
'select_group_by_a_comma_ > name > select_group_by_a ^ columns',
|
|
134
|
-
'select_group_by_a_ > limit > select_where_sc_limit ^ limit,order by',
|
|
136
|
+
'select_group_by_a_ > limit > select_where_sc_limit ^ limit,order by,&',
|
|
135
137
|
'- > order > select_order',
|
|
136
138
|
'- > order by > select_order_by',
|
|
137
139
|
'- > ; > ',
|
|
140
|
+
'- > & > select_from_x$',
|
|
138
141
|
'select_order_ > by > select_order_by ^ by',
|
|
139
142
|
'select_order_by_ > name > select_order_by_a ^ columns',
|
|
140
143
|
'select_order_by_a > , > select_order_by_a_comma_',
|
|
141
144
|
'- > ; > ',
|
|
142
145
|
'select_order_by_a_comma_ > name > select_order_by_a ^ columns',
|
|
143
|
-
'select_order_by_a_ > desc|asc > select_order_by_a_desc ^ desc,asc,limit',
|
|
146
|
+
'select_order_by_a_ > desc|asc > select_order_by_a_desc ^ desc,asc,limit,&',
|
|
144
147
|
'- > limit > select_where_sc_limit',
|
|
145
148
|
'- > ; > ',
|
|
149
|
+
'- > & > select_from_x$',
|
|
146
150
|
'select_order_by_a_desc > , > select_order_by_a_comma_',
|
|
147
151
|
'- > ; > ',
|
|
148
|
-
'select_order_by_a_desc_ > limit > select_where_sc_limit ^ limit',
|
|
152
|
+
'select_order_by_a_desc_ > limit > select_where_sc_limit ^ limit,&',
|
|
149
153
|
'- > ; > ',
|
|
154
|
+
'- > & > select_from_x$',
|
|
150
155
|
'select_where_sc_limit_ > num > select_where_sc_limit_num ^ 1',
|
|
151
156
|
'select_where_sc_limit_num > ; > ',
|
|
152
157
|
'select_where_sc_limit_num_rp__ > as > select_from_x_as ^ as',
|
|
@@ -202,7 +207,9 @@ SQL_SPEC = [
|
|
|
202
207
|
'insert_values > ( > insert_values_lp_',
|
|
203
208
|
'insert_values_lp_ > name|single|num > insert_values_lp_v ^ single',
|
|
204
209
|
'insert_values_lp_v > , > insert_values_lp_v_comma_',
|
|
210
|
+
'- > ) > insert_values_lp_v_rp_',
|
|
205
211
|
'insert_values_lp_v_comma_ > name|single|num > insert_values_lp_v',
|
|
212
|
+
'insert_values_lp_v_rp__ > & > insert_values_lp_v_rp_$ ^ &',
|
|
206
213
|
|
|
207
214
|
# <update_statement> ::= UPDATE <table_name>
|
|
208
215
|
# SET <set_clause_list>
|
|
@@ -223,8 +230,9 @@ SQL_SPEC = [
|
|
|
223
230
|
'update_set_a_op > name|single|num > update_set_sc ^ single',
|
|
224
231
|
'update_set_sc > , > update_set_sc_comma_',
|
|
225
232
|
'update_set_sc_comma_ > name > update_set_a ^ id',
|
|
226
|
-
'update_set_sc_ > , > update_set_sc_comma_ ^ where',
|
|
233
|
+
'update_set_sc_ > , > update_set_sc_comma_ ^ where,&',
|
|
227
234
|
'- > where > update_where',
|
|
235
|
+
'- > & > update_set_sc$ ^ &',
|
|
228
236
|
'update_where_ > name > update_where_a ^ id',
|
|
229
237
|
'update_where_a > comparison > update_where_a_op',
|
|
230
238
|
'update_where_a_ > comparison > update_where_a_op ^ =,<,<=,>,>=,<>,like,not,in',
|
|
@@ -241,7 +249,7 @@ SQL_SPEC = [
|
|
|
241
249
|
'update_where_a_in_lp_a_comma_ > name|single|num > update_where_a_in_lp_a ^ single',
|
|
242
250
|
'update_where_a_not_op > name|single|num > update_where_sc ^ single',
|
|
243
251
|
'update_where_a_op > name|single|num > update_where_sc ^ single',
|
|
244
|
-
'update_where_sc_ > and|or > update_where ^ and,or',
|
|
252
|
+
'update_where_sc_ > and|or > update_where ^ and,or,&',
|
|
245
253
|
|
|
246
254
|
# <delete_statement> ::= DELETE FROM <table_name> [ WHERE <search_condition> ]
|
|
247
255
|
|
|
@@ -403,9 +411,15 @@ CQL_SPEC = SQL_SPEC + [
|
|
|
403
411
|
'export_table_to_ > athena|sqlite|csv > export_table_to$ ^ athena,sqlite,csv',
|
|
404
412
|
|
|
405
413
|
' > import > import',
|
|
406
|
-
'import_ > session > import_session ^ session',
|
|
414
|
+
'import_ > session > import_session ^ session,files',
|
|
415
|
+
'- > files > import_files',
|
|
407
416
|
'import_session_ > name > import_session_s ^ export-sessions-incomplete',
|
|
408
417
|
'import_session_s_ > to > import_session_to ^ to',
|
|
418
|
+
'import_files_ > name > import_files_f',
|
|
419
|
+
'import_files_f > , > import_files',
|
|
420
|
+
'import_files_f_ > as > import_files_f_as ^ as',
|
|
421
|
+
'import_files_f_as_ > name > import_files_f_as_a',
|
|
422
|
+
'import_files_f_as_a_ > to > import_session_to ^ to',
|
|
409
423
|
'import_session_to_ > athena|sqlite > import_session_to$ ^ athena,sqlite',
|
|
410
424
|
|
|
411
425
|
' > consistency > consistency',
|
|
@@ -433,7 +447,7 @@ CQL_SPEC = SQL_SPEC + [
|
|
|
433
447
|
CQL_KEYWORDS = SQL_KEYWORDS + [
|
|
434
448
|
'schema', 'keyspace', 'keyspaces', 'tables', 'export', 'copy', 'consistency',
|
|
435
449
|
'quorum', 'all', 'serial', 'one', 'each_quorum', 'local_quorum', 'any', 'local_one', 'two', 'three', 'local_serial', 'to',
|
|
436
|
-
'database', 'databases', 'session', 'sessions', 'clean', 'up', 'athena', 'sqlite', 'csv', 'import'
|
|
450
|
+
'database', 'databases', 'session', 'sessions', 'clean', 'up', 'athena', 'sqlite', 'csv', 'import', 'files'
|
|
437
451
|
]
|
|
438
452
|
|
|
439
453
|
CQL_EXPANDABLE_NAMES = EXPANDABLE_NAMES | {
|
|
@@ -547,7 +561,7 @@ class SqlStateMachine(StateMachine[Token]):
|
|
|
547
561
|
elif token.ttype == TOKEN.Operator.Comparison:
|
|
548
562
|
it = 'comparison'
|
|
549
563
|
|
|
550
|
-
|
|
564
|
+
with log_exc(False):
|
|
551
565
|
# print(f'\n{state.to_s} > {it} > ', end='')
|
|
552
566
|
if comeback_state:
|
|
553
567
|
state = comeback_state
|
|
@@ -558,8 +572,6 @@ class SqlStateMachine(StateMachine[Token]):
|
|
|
558
572
|
|
|
559
573
|
if last_name:
|
|
560
574
|
state.context['last_name'] = last_name
|
|
561
|
-
except:
|
|
562
|
-
pass
|
|
563
575
|
|
|
564
576
|
return state
|
|
565
577
|
|
adam/sso/authn_ad.py
CHANGED
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
import json
|
|
2
2
|
import re
|
|
3
|
-
import traceback
|
|
4
3
|
import jwt
|
|
5
4
|
import requests
|
|
6
5
|
from urllib.parse import urlparse, parse_qs
|
|
@@ -8,7 +7,7 @@ from urllib.parse import urlparse, parse_qs
|
|
|
8
7
|
from adam.log import Log
|
|
9
8
|
from adam.sso.authenticator import Authenticator
|
|
10
9
|
from adam.sso.id_token import IdToken
|
|
11
|
-
from adam.utils import debug
|
|
10
|
+
from adam.utils import debug, log_exc
|
|
12
11
|
from .idp_login import IdpLogin
|
|
13
12
|
from adam.config import Config
|
|
14
13
|
|
|
@@ -139,7 +138,7 @@ class AdAuthenticator(Authenticator):
|
|
|
139
138
|
|
|
140
139
|
def parse_id_token(self, id_token: str) -> IdToken:
|
|
141
140
|
jwks_url = Config().get('idps.ad.jwks-uri', '')
|
|
142
|
-
|
|
141
|
+
with log_exc():
|
|
143
142
|
jwks_client = jwt.PyJWKClient(jwks_url, cache_jwk_set=True, lifespan=360)
|
|
144
143
|
signing_key = jwks_client.get_signing_key_from_jwt(id_token)
|
|
145
144
|
data = jwt.decode(
|
|
@@ -164,7 +163,5 @@ class AdAuthenticator(Authenticator):
|
|
|
164
163
|
nbf=data['nbf'] if 'nbf' in data else 0,
|
|
165
164
|
exp=data['exp'] if 'exp' in data else 0
|
|
166
165
|
)
|
|
167
|
-
except:
|
|
168
|
-
debug(traceback.format_exc())
|
|
169
166
|
|
|
170
167
|
return None
|
adam/sso/authn_okta.py
CHANGED
|
@@ -8,7 +8,7 @@ from adam.sso.id_token import IdToken
|
|
|
8
8
|
|
|
9
9
|
from .idp_login import IdpLogin
|
|
10
10
|
from adam.config import Config
|
|
11
|
-
from adam.utils import debug, log2
|
|
11
|
+
from adam.utils import debug, log2, log_exc
|
|
12
12
|
|
|
13
13
|
class OktaException(Exception):
|
|
14
14
|
pass
|
|
@@ -95,7 +95,7 @@ class OktaAuthenticator(Authenticator):
|
|
|
95
95
|
return None
|
|
96
96
|
|
|
97
97
|
jwks_url = Config().get('idps.okta.jwks-uri', 'https://c3energy.okta.com/oauth2/v1/keys')
|
|
98
|
-
|
|
98
|
+
with log_exc():
|
|
99
99
|
jwks_client = jwt.PyJWKClient(jwks_url, cache_jwk_set=True, lifespan=360)
|
|
100
100
|
signing_key = jwks_client.get_signing_key_from_jwt(id_token)
|
|
101
101
|
data = jwt.decode(
|
|
@@ -121,7 +121,5 @@ class OktaAuthenticator(Authenticator):
|
|
|
121
121
|
nbf=data['nbf'] if 'nbf' in data else 0,
|
|
122
122
|
exp=data['exp'] if 'exp' in data else 0
|
|
123
123
|
)
|
|
124
|
-
except:
|
|
125
|
-
pass
|
|
126
124
|
|
|
127
125
|
return None
|
adam/sso/cred_cache.py
CHANGED
|
@@ -1,10 +1,9 @@
|
|
|
1
1
|
import os
|
|
2
2
|
from pathlib import Path
|
|
3
|
-
import traceback
|
|
4
3
|
from dotenv import load_dotenv
|
|
5
4
|
|
|
6
5
|
from adam.config import Config
|
|
7
|
-
from adam.utils import debug
|
|
6
|
+
from adam.utils import debug, log_exc
|
|
8
7
|
from adam.utils_k8s.kube_context import KubeContext
|
|
9
8
|
|
|
10
9
|
class CredCache:
|
|
@@ -35,10 +34,8 @@ class CredCache:
|
|
|
35
34
|
def cache(self, username: str, password: str = None):
|
|
36
35
|
if os.path.exists(self.env_f):
|
|
37
36
|
with open(self.env_f, 'w') as file:
|
|
38
|
-
|
|
37
|
+
with log_exc():
|
|
39
38
|
file.truncate()
|
|
40
|
-
except:
|
|
41
|
-
debug(traceback.format_exc())
|
|
42
39
|
|
|
43
40
|
updated = []
|
|
44
41
|
updated.append(f'IDP_USERNAME={username}')
|
adam/sso/idp.py
CHANGED
|
@@ -3,7 +3,6 @@ import getpass
|
|
|
3
3
|
import os
|
|
4
4
|
import sys
|
|
5
5
|
import termios
|
|
6
|
-
import traceback
|
|
7
6
|
from typing import Callable, TypeVar
|
|
8
7
|
import requests
|
|
9
8
|
from kubernetes import config
|
|
@@ -15,7 +14,7 @@ from .cred_cache import CredCache
|
|
|
15
14
|
from .idp_session import IdpSession
|
|
16
15
|
from .idp_login import IdpLogin
|
|
17
16
|
from adam.config import Config
|
|
18
|
-
from adam.utils import debug, log
|
|
17
|
+
from adam.utils import debug, log, log_exc
|
|
19
18
|
|
|
20
19
|
T = TypeVar('T')
|
|
21
20
|
|
|
@@ -31,6 +30,8 @@ class Idp:
|
|
|
31
30
|
def login(app_host: str, username: str = None, idp_uri: str = None, forced = False, use_token_from_env = True, use_cached_creds = True, verify = True) -> IdpLogin:
|
|
32
31
|
session: IdpSession = IdpSession.create(username, app_host, app_host, idp_uri=idp_uri)
|
|
33
32
|
|
|
33
|
+
debug(f'Idp.login({username})')
|
|
34
|
+
|
|
34
35
|
if use_token_from_env:
|
|
35
36
|
if l0 := session.login_from_env_var():
|
|
36
37
|
return l0
|
|
@@ -39,11 +40,9 @@ class Idp:
|
|
|
39
40
|
token_server = Config().get('app.login.token-server-url', 'http://localhost:{port}').replace('{port}', port)
|
|
40
41
|
res: requests.Response = requests.get(token_server)
|
|
41
42
|
if res.status_code == 200 and res.text:
|
|
42
|
-
|
|
43
|
+
with log_exc():
|
|
43
44
|
# may fail if the idp token is not complete
|
|
44
45
|
return session.login_from_token(res.text)
|
|
45
|
-
except:
|
|
46
|
-
pass
|
|
47
46
|
|
|
48
47
|
r: IdpLogin = None
|
|
49
48
|
try:
|
|
@@ -59,8 +58,9 @@ class Idp:
|
|
|
59
58
|
default_user = CredCache().get_username()
|
|
60
59
|
debug(f'User read from cache: {default_user}')
|
|
61
60
|
|
|
62
|
-
|
|
63
|
-
|
|
61
|
+
# no value in using USERNAME
|
|
62
|
+
# if from_env := os.getenv('USERNAME') and in_docker():
|
|
63
|
+
# default_user = from_env
|
|
64
64
|
if default_user and default_user != username:
|
|
65
65
|
session = IdpSession.create(default_user, app_host, app_host)
|
|
66
66
|
|
|
@@ -125,7 +125,7 @@ class Idp:
|
|
|
125
125
|
termios.tcsetattr(fd, termios.TCSADRAIN, old)
|
|
126
126
|
|
|
127
127
|
def try_kubeconfig(username: str, kubeconfig: str):
|
|
128
|
-
|
|
128
|
+
with log_exc():
|
|
129
129
|
if kubeconfig[0] == '\t':
|
|
130
130
|
kubeconfig = kubeconfig[1:]
|
|
131
131
|
kubeconfig_string = base64.b64decode(kubeconfig.encode('ascii') + b'==').decode('utf-8')
|
|
@@ -136,8 +136,5 @@ class Idp:
|
|
|
136
136
|
Secrets.list_secrets(os.getenv('NAMESPACE'))
|
|
137
137
|
|
|
138
138
|
return IdpLogin(None, None, None, username)
|
|
139
|
-
except:
|
|
140
|
-
debug(traceback.format_exc())
|
|
141
|
-
pass
|
|
142
139
|
|
|
143
140
|
return None
|