|
1 | 1 | """This module is where most of the capability providers should be to not have them scattered around""" |
2 | 2 |
|
| 3 | +from openshift_client import Missing |
3 | 4 | from weakget import weakget |
4 | 5 |
|
5 | 6 | from testsuite import gateways |
@@ -67,25 +68,36 @@ def fips(): |
67 | 68 | CapabilityRegistry().register_provider(fips, {Capability.NOFIPS, Capability.FIPS}) |
68 | 69 |
|
69 | 70 |
|
70 | | -def zync(): |
71 | | - """Zync is available when the gateway is not ZyncLessApicast, |
72 | | - unless zync_routes_disabled is set (zync runs but doesn't create routes)""" |
73 | | - if issubclass(gateways.default, ZyncLessApicast): |
74 | | - if not weakget(settings)["threescale"]["gateway"]["default"]["zync_routes_disabled"] % False: |
75 | | - return {} |
76 | | - return {Capability.ZYNC} |
77 | | - |
| 71 | +def zync_capabilities(): |
| 72 | + """Determines zync capabilities based on gateway type and config. |
78 | 73 |
|
79 | | -CapabilityRegistry().register_provider(zync, {Capability.ZYNC}) |
| 74 | + Case 1 (standard zync): gateway is not ZyncLessApicast and threescale.zync_routes_disabled is not set. |
| 75 | + Provides ZYNC_ROUTES + ZYNC_OIDC_SYNC. Fails fast if APIManager has zync disabled. |
80 | 76 |
|
| 77 | + Case 2 (zync without routes): threescale.zync_routes_disabled: true in config. |
| 78 | + Provides only ZYNC_OIDC_SYNC. |
81 | 79 |
|
82 | | -def sso(): |
83 | | - """SSO is available when zync is enabled and RHSSO is configured in dynaconf""" |
84 | | - if Capability.ZYNC not in CapabilityRegistry(): |
85 | | - return {} |
86 | | - if not weakget(settings)["rhsso"]["password"] % None: |
| 80 | + Case 3 (zync disabled): gateway is ZyncLessApicast. |
| 81 | + Provides no zync capabilities. Fails fast if APIManager has zync enabled. |
| 82 | + """ |
| 83 | + if issubclass(gateways.default, ZyncLessApicast): |
| 84 | + enabled = openshift().api_manager.get_path("spec/zync/enabled") |
| 85 | + if enabled is Missing or enabled: |
| 86 | + raise RuntimeError("ZyncLessApicast requires zync to be disabled in APIManager (spec/zync/enabled: false)") |
87 | 87 | return {} |
88 | | - return {Capability.SSO} |
| 88 | + |
| 89 | + zync_routes_disabled = weakget(settings)["threescale"]["zync_routes_disabled"] % False |
| 90 | + |
| 91 | + if zync_routes_disabled: |
| 92 | + return {Capability.ZYNC_OIDC_SYNC} |
| 93 | + |
| 94 | + enabled = openshift().api_manager.get_path("spec/zync/enabled") |
| 95 | + if enabled is not Missing and not enabled: |
| 96 | + raise RuntimeError( |
| 97 | + "Config expects standard zync but APIManager has zync disabled. " |
| 98 | + "Use ZyncLessApicast gateway or set threescale.zync_routes_disabled: true." |
| 99 | + ) |
| 100 | + return {Capability.ZYNC_ROUTES, Capability.ZYNC_OIDC_SYNC} |
89 | 101 |
|
90 | 102 |
|
91 | | -CapabilityRegistry().register_provider(sso, {Capability.SSO}) |
| 103 | +CapabilityRegistry().register_provider(zync_capabilities, {Capability.ZYNC_ROUTES, Capability.ZYNC_OIDC_SYNC}) |
0 commit comments