Mercurial
changeset 198:008ca7780c8a
S3 upload got it to work.
| author | MrJuneJune <me@mrjunejune.com> |
|---|---|
| date | Sat, 14 Feb 2026 16:18:14 -0800 |
| parents | 0106cb67d958 |
| children | b4a070994b54 |
| files | BUILD s3/BUILD s3/tests/BUILD s3/tests/s3_uploader_test.c |
| diffstat | 4 files changed, 98 insertions(+), 25 deletions(-) [+] |
line wrap: on
line diff
--- a/BUILD Sat Feb 14 16:08:47 2026 -0800 +++ b/BUILD Sat Feb 14 16:18:14 2026 -0800 @@ -0,0 +1,7 @@ +exports_files([".env"]) + +filegroup( + name = "env_file", + srcs = [".env"], + visibility = ["//visibility:public"], +)
--- a/s3/BUILD Sat Feb 14 16:08:47 2026 -0800 +++ b/s3/BUILD Sat Feb 14 16:18:14 2026 -0800 @@ -24,7 +24,7 @@ hdrs = [":s3_hdrs"], deps = [ "//dowa:dowa", - "//seobeo:seobeo_tcp_client", + "//seobeo:seobeo", "@openssl//:ssl", ], target_compatible_with = [ @@ -39,7 +39,7 @@ hdrs = [":s3_hdrs"], deps = [ "//dowa:dowa", - "//seobeo:seobeo_tcp_client", + "//seobeo:seobeo", "@openssl//:ssl", ], target_compatible_with = [
--- a/s3/tests/BUILD Sat Feb 14 16:08:47 2026 -0800 +++ b/s3/tests/BUILD Sat Feb 14 16:18:14 2026 -0800 @@ -1,7 +1,20 @@ load("@rules_cc//cc:cc_binary.bzl", "cc_binary") +load("@rules_cc//cc:cc_test.bzl", "cc_test") + +cc_test( + name = "s3_uploader_test", + srcs = ["s3_uploader_test.c"], + deps = [ + "//s3:s3", + ], + data = [ + "//:env_file", + ], + visibility = ["//visibility:public"], +) cc_binary( - name = "s3_uploader_test", + name = "s3_uploader_bin", srcs = ["s3_uploader_test.c"], deps = [ "//s3:s3",
--- a/s3/tests/s3_uploader_test.c Sat Feb 14 16:08:47 2026 -0800 +++ b/s3/tests/s3_uploader_test.c Sat Feb 14 16:18:14 2026 -0800 @@ -1,47 +1,97 @@ #include "s3/s3_uploader.h" #include <stdio.h> +#include <stdlib.h> #include <string.h> -// Simple test for S3 uploader -// Run with: bazel run //s3/tests:s3_uploader_test -// -// Set environment variables before running: -// export AWS_ACCESS_KEY_ID="your-access-key" -// export AWS_SECRET_ACCESS_KEY="your-secret-key" -// export AWS_REGION="us-east-1" -// export AWS_BUCKET="your-bucket" +// Simple .env parser +static char *parse_env_value(const char *env_content, const char *key) +{ + const char *pos = strstr(env_content, key); + if (!pos) return NULL; + + pos += strlen(key); + if (*pos != '=') return NULL; + pos++; + + const char *end = pos; + while (*end && *end != '\n' && *end != '\r') end++; + + size_t len = end - pos; + char *value = malloc(len + 1); + memcpy(value, pos, len); + value[len] = '\0'; + return value; +} + +static char *load_file(const char *path) +{ + FILE *f = fopen(path, "r"); + if (!f) return NULL; + + fseek(f, 0, SEEK_END); + long size = ftell(f); + fseek(f, 0, SEEK_SET); + + char *content = malloc(size + 1); + fread(content, 1, size, f); + content[size] = '\0'; + fclose(f); + return content; +} int main(int argc, char **argv) { - const char *access_key = getenv("AWS_ACCESS_KEY_ID"); - const char *secret_key = getenv("AWS_SECRET_ACCESS_KEY"); - const char *region = getenv("AWS_REGION"); - const char *bucket = getenv("AWS_BUCKET"); + // Try to load .env file - check multiple locations for bazel runfiles + char *env_content = load_file(".env"); + if (!env_content) + { + env_content = load_file("zenbu/.env"); // bazel runfiles path + } + if (!env_content) + { + env_content = load_file("../.env"); + } + if (!env_content) + { + env_content = load_file("../../.env"); + } - if (!access_key || !secret_key || !region || !bucket) + char *access_key = NULL; + char *secret_key = NULL; + + if (env_content) { - printf("Missing environment variables. Set:\n"); - printf(" AWS_ACCESS_KEY_ID\n"); - printf(" AWS_SECRET_ACCESS_KEY\n"); - printf(" AWS_REGION\n"); - printf(" AWS_BUCKET\n"); + access_key = parse_env_value(env_content, "AWS_MRJUNEJUNE_ACCESS_KEY"); + secret_key = parse_env_value(env_content, "AWS_MRJUNEJUNE_SECRET_ACCESS_KEY"); + free(env_content); + } + + // Fall back to environment variables + if (!access_key) access_key = getenv("AWS_ACCESS_KEY_ID") ? strdup(getenv("AWS_ACCESS_KEY_ID")) : NULL; + if (!secret_key) secret_key = getenv("AWS_SECRET_ACCESS_KEY") ? strdup(getenv("AWS_SECRET_ACCESS_KEY")) : NULL; + + if (!access_key || !secret_key) + { + printf("Missing credentials. Set in .env file or environment:\n"); + printf(" AWS_MRJUNEJUNE_ACCESS_KEY / AWS_ACCESS_KEY_ID\n"); + printf(" AWS_MRJUNEJUNE_SECRET_ACCESS_KEY / AWS_SECRET_ACCESS_KEY\n"); return 1; } S3_Config config = { .access_key_id = access_key, .secret_access_key = secret_key, - .region = region, - .bucket = bucket, + .region = "us-west-2", + .bucket = "mrjunejune", .endpoint = NULL, .use_path_style = FALSE }; printf("S3 Uploader Test\n"); printf("================\n"); - printf("Region: %s\n", region); - printf("Bucket: %s\n", bucket); + printf("Region: %s\n", config.region); + printf("Bucket: %s\n", config.bucket); printf("\n"); // Test 1: Upload string data @@ -135,5 +185,8 @@ } printf("\nDone!\n"); + + free(access_key); + free(secret_key); return 0; }