Skip to content

Commit 7745918

Browse files
committed
feat: i guess it works locally
1 parent 9efe152 commit 7745918

File tree

2 files changed

+85
-0
lines changed

2 files changed

+85
-0
lines changed

seaweedfs.tf

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,12 @@
1+
data "kubernetes_service" "bunkerweb_external" {
2+
metadata {
3+
name = "bunkerweb-external"
4+
namespace = var.namespace
5+
}
6+
7+
depends_on = [helm_release.bunkerweb]
8+
}
9+
110
resource "kubernetes_secret" "seaweedfs_iam" {
211
metadata {
312
name = "seaweedfs-iam-config"
@@ -187,6 +196,11 @@ resource "kubernetes_deployment" "seaweedfs" {
187196
]
188197
}
189198

199+
host_aliases {
200+
ip = data.kubernetes_service.bunkerweb_external.spec[0].cluster_ip
201+
hostnames = [var.keycloak_domain, var.seaweedfs_domain]
202+
}
203+
190204
container {
191205
name = "seaweedfs"
192206
image = var.seaweedfs_image

test-s3.sh

Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
#!/usr/bin/env bash
2+
set -euo pipefail
3+
4+
ENDPOINT="http://localhost:18333"
5+
BUNKERWEB="http://localhost:8080"
6+
7+
CLIENT_SECRET=$(kubectl get secret keycloak-credentials -o jsonpath='{.data.client-secret}' | base64 -d)
8+
echo "Got client secret"
9+
10+
ID_TOKEN=$(curl -s -X POST \
11+
-H "Host: auth.localhost" \
12+
"$BUNKERWEB/realms/seaweedfs/protocol/openid-connect/token" \
13+
-d "grant_type=password" \
14+
-d "client_id=seaweedfs-client" \
15+
-d "client_secret=$CLIENT_SECRET" \
16+
-d "username=testuser" \
17+
-d "password=password" \
18+
-d "scope=openid" | jq -r '.id_token')
19+
20+
if [ "$ID_TOKEN" = "null" ] || [ -z "$ID_TOKEN" ]; then
21+
echo "ERROR: Failed to get ID token"
22+
exit 1
23+
fi
24+
echo "Got ID token"
25+
26+
STS_RESULT=$(curl -s "$BUNKERWEB" \
27+
-H "Host: s3.localhost" \
28+
--data-urlencode "Action=AssumeRoleWithWebIdentity" \
29+
--data-urlencode "WebIdentityToken=$ID_TOKEN" \
30+
--data-urlencode "RoleArn=arn:aws:iam::role/S3WriteRole" \
31+
--data-urlencode "RoleSessionName=testuser-session" \
32+
--data-urlencode "Version=2011-06-15")
33+
34+
export AWS_ACCESS_KEY_ID=$(echo "$STS_RESULT" | xmllint --xpath '//*[local-name()="AccessKeyId"]/text()' -)
35+
export AWS_SECRET_ACCESS_KEY=$(echo "$STS_RESULT" | xmllint --xpath '//*[local-name()="SecretAccessKey"]/text()' -)
36+
export AWS_SESSION_TOKEN=$(echo "$STS_RESULT" | xmllint --xpath '//*[local-name()="SessionToken"]/text()' -)
37+
echo "Got STS credentials (AccessKeyId: $AWS_ACCESS_KEY_ID)"
38+
39+
echo ""
40+
echo "=== List buckets ==="
41+
aws --endpoint-url "$ENDPOINT" s3 ls
42+
43+
BUCKET="test-bucket-$(date +%s)"
44+
echo ""
45+
echo "=== Create bucket: $BUCKET ==="
46+
aws --endpoint-url "$ENDPOINT" s3 mb "s3://$BUCKET"
47+
48+
echo "hello from SeaweedFS STS test" > /tmp/seaweed-test.txt
49+
echo ""
50+
echo "=== Upload file ==="
51+
aws --endpoint-url "$ENDPOINT" s3 cp /tmp/seaweed-test.txt "s3://$BUCKET/test.txt"
52+
53+
echo ""
54+
echo "=== List bucket contents ==="
55+
aws --endpoint-url "$ENDPOINT" s3 ls "s3://$BUCKET/"
56+
57+
echo ""
58+
echo "=== Download file ==="
59+
aws --endpoint-url "$ENDPOINT" s3 cp "s3://$BUCKET/test.txt" /tmp/seaweed-download.txt
60+
echo "Downloaded content: $(cat /tmp/seaweed-download.txt)"
61+
62+
echo ""
63+
echo "=== Delete file ==="
64+
aws --endpoint-url "$ENDPOINT" s3 rm "s3://$BUCKET/test.txt"
65+
66+
echo ""
67+
echo "=== Delete bucket ==="
68+
aws --endpoint-url "$ENDPOINT" s3 rb "s3://$BUCKET"
69+
70+
echo ""
71+
echo "All tests passed!"

0 commit comments

Comments
 (0)