Lab 6 - AI API Key handling

```bash
kubectl apply -f - <<'EOF'
apiVersion: security.policy.gloo.solo.io/v2
kind: ExtAuthPolicy
metadata:
name: huggingface-apikey
namespace: gloo-mesh-gateways
spec:
applyToRoutes:
- route:
labels:
route: huggingface
config:
server:
name: ext-auth-server
namespace: gloo-mesh-gateways
cluster: cluster-1
glooAuth:
configs:
- apiKeyAuth:
headerName: api-key
k8sSecretApikeyStorage:
labelSelector:
api-key: api-huggingface
EOF
```
```bash
kubectl apply -f - <<'EOF'
apiVersion: v1
kind: Secret
metadata:
name: api-huggingface-key
labels:
api-key: api-huggingface
type: extauth.solo.io/apikey
data:
api-key: bXlzZWNyZXRrZXk= # Base64 encoded value "mysecretkey"
EOF
```
```bash
curl http://$GLOO_GATEWAY/huggingface
```
```bash
curl -v -H "api-key: mysecretkey" http://$GLOO_GATEWAY/huggingface
```
```bash
kubectl patch secret api-huggingface-key \
--type=json \
-p='[{"op": "add", "path": "/data/huggingface-api-key", "value": "'$(echo -n $HF_API_TOKEN | base64)'"}]'
```
```bash
kubectl patch extauthpolicy huggingface-apikey \
-n gloo-mesh-gateways \
--type=json \
-p='[{"op": "add", "path": "/spec/config/glooAuth/configs/0/apiKeyAuth/headersFromMetadataEntry", "value": {"x-api-key": {"name": "huggingface-api-key"}}}]'
```
```bash
kubectl apply -f - <<'EOF'
apiVersion: trafficcontrol.policy.gloo.solo.io/v2
kind: TransformationPolicy
metadata:
name: huggingface-transformations
spec:
applyToRoutes:
- route:
labels:
route: huggingface
config:
request:
injaTemplate:
headers:
Authorization:
text: 'Bearer {{ huggingface-api-key }}'
extractors:
huggingface-api-key:
header: 'x-api-key'
regex: '.*'
EOF
```
```bash
curl http://$GLOO_GATEWAY/huggingface \
-X POST \
-d '{"inputs": "Write me a 30 second pitch on why I should use an API gateway in front of my LLM backends"}' \
-H 'Content-Type: application/json' \
-H "api-key: mysecretkey"
```