File tree Expand file tree Collapse file tree 1 file changed +14
-9
lines changed Expand file tree Collapse file tree 1 file changed +14
-9
lines changed Original file line number Diff line number Diff line change 5
5
6
6
app = Flask (__name__ )
7
7
8
- # Key Vault URL (replace with yours)
8
+ # Key Vault URL
9
9
KEY_VAULT_URL = "https://yashkeyvaultverysafe.vault.azure.net/"
10
10
11
11
# Set up Azure Key Vault client
12
12
credential = DefaultAzureCredential ()
13
13
client = SecretClient (vault_url = KEY_VAULT_URL , credential = credential )
14
14
15
- # Get secret from Key Vault
16
- retrieved_secret = client .get_secret ("app-auth-secret" ).value
17
-
18
15
@app .route ("/" )
19
16
def home ():
20
- # Check if 'x-api-key' header matches the secret
21
- api_key = request .headers .get ('x-api-key' )
22
- if api_key != retrieved_secret :
23
- abort (403 ) # Forbidden
24
- return "✅ Authorized! You accessed a secure route."
17
+ try :
18
+ # Fetch secret inside the route
19
+ retrieved_secret = client .get_secret ("app-auth-secret" ).value
20
+ api_key = request .headers .get ('x-api-key' )
21
+ if api_key != retrieved_secret :
22
+ abort (403 )
23
+ return "✅ Authorized! You accessed a secure route."
24
+ except Exception as e :
25
+ return f"❌ Error: { str (e )} " , 500
26
+
27
+ @app .route ("/ping" )
28
+ def ping ():
29
+ return "App is alive!"
25
30
26
31
if __name__ == "__main__" :
27
32
app .run (host = '0.0.0.0' , port = 8000 )
You can’t perform that action at this time.
0 commit comments