Api proxy
This package contains the core code for the API Proxy mechanism.
For more information and context, refer to: - The ADR that introduced this mechanism ⧉ - The technical proposal that describes it ⧉
shared.api_proxy.common ¶
This file contains symbols used by both proxy apps and proxied apps.
For definitions, see the technical proposal here ⧉.
ProxiedEnvName ¶
Bases: AlanBaseEnum
Name of the environments that can be proxied via the API Proxy mechanism, i.e. that can receive calls from other back-ends.
ProxyAppName ¶
Bases: AlanBaseEnum
Name of the proxy apps ⧉ in the API Proxy mechanism.
get_service_account_secret_name_config_key ¶
Source code in shared/api_proxy/common.py
get_current_proxied_env_name ¶
Source code in shared/api_proxy/common.py
shared.api_proxy.proxied ¶
This file contains functions for proxied apps (i.e. another app will access their HTTP functions).
For definitions, see the technical proposal here ⧉.
ProxiedOnlyBlueprint ¶
Bases: Blueprint
A blueprint for endpoints that can only be reached via the API Proxy mechanism.
This blueprint automatically handles authentication and authorization via the current app's authentication/authorization manager:
flask_loginfor EU Toolsshared.iamfor country apps
Constructor for a blueprint that contains proxied-only endpoints.
The permissions_for_endpoints argument is the required permissions for the endpoints that will be
registered under this blueprint. A good default value is {EmployeePermission.use_proxied_only_endpoints}, as
all proxy apps will have this permission when calling endpoints.
The set acts as an "OR" (more precisely, the principal's permission set must intersect this set).
Source code in shared/api_proxy/proxied.py
shared.api_proxy.proxy ¶
This file contains functions for apps that will act as PROXIES (i.e. they will access other apps' HTTP functions)
KNOWN_PROXIED_APP_NAMES
module-attribute
¶
List of names that can be recognized as AppName by the API Proxy system.
Note that this list intentionally contains duplicates (e.g. fr-api and fr_api), use PROXIED_APP_NAMES if you need a list of distinct AppNames for proxied apps.
PROXIED_APP_NAMES
module-attribute
¶
List of possible proxied apps in the API Proxy mechanism.
ProxyApiBlueprint ¶
ProxyApiBlueprint(
proxy_name,
proxied_url_prefix,
name,
import_name,
url_prefix=None,
restrict_to_current_env=True,
)
Bases: Blueprint
This blueprint exposes a Proxy HTTP API configured according to the constructor arguments. Can only be used on Proxy Apps (see ProxyAppName).
You MUST secure this blueprint via a before_request hook.
See here ⧉ for more information.
The schema for the API this blueprint exposes (and what endpoint it results in on proxied apps) is described here ⧉
Constructor for ProxyApiBlueprint
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
proxy_name
|
ProxyAppName
|
Name of the proxy app this HTTP API will be exposed from. |
required |
proxied_url_prefix
|
str
|
The prefix that will be appended to requests sent to the proxied app, i.e. |
required |
name
|
str
|
The name of this blueprint (passed as-is to the Flask blueprint). |
required |
import_name
|
str
|
The import name of this blueprint (passed as-is to the Flask blueprint). |
required |
url_prefix
|
str | None
|
The URL prefix for THIS schema, which the API will be served under. Defaults to None. |
None
|
restrict_to_current_env
|
bool
|
If true (and by default), calls to the proxied app will be done on the same environment as the proxy app. If false, the caller can set which environment they'd like to call as a path parameter. Setting to False is dangerous. |
True
|
Source code in shared/api_proxy/proxy.py
build_request_session ¶
Source code in shared/api_proxy/proxy.py
ProxyRequestSessionBuilder ¶
An object that can be used to manually build request sessions to send requests to proxied apps.
Instantiating this class is only useful when you don't have a ProxyApiBlueprint. If you do have a
ProxyApiBlueprint, you can use the build_request_session on it directly to create a session.
See here ⧉ for more information on this use case.
Source code in shared/api_proxy/proxy.py
build_request_session ¶
Builds a session for use with the requests library.
Source code in shared/api_proxy/proxy.py
shared.api_proxy.utils ¶
create_api_proxy_service_account_users_for_current_env ¶
Source code in shared/api_proxy/utils.py
61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 | |