update constants to zig appropriate naming

This commit is contained in:
Emil Lerch 2025-12-09 12:02:52 -08:00
parent 669eb67a00
commit 2738d6ed87
Signed by: lobo
GPG key ID: A7B62D657EF764F8

View file

@ -2,11 +2,11 @@ const std = @import("std");
const http = std.http;
const json = std.json;
const CLIENT_ID = "5ghq3i6k4p9s7dfu34ckmec91";
const COGNITO_URL = "https://cognito-idp.us-east-1.amazonaws.com/";
const APPSYNC_URL = "https://s34ox7kri5dsvdr43bfgp6qh6i.appsync-api.us-east-1.amazonaws.com/graphql";
const API_KEY = "da2-dm2g4rqvjbaoxcpo4eccs3k5he";
const SHADOW_API_URL = "https://698suy4zs3.execute-api.us-east-1.amazonaws.com/Prod/thing";
const client_id = "5ghq3i6k4p9s7dfu34ckmec91";
const cognito_url = "https://cognito-idp.us-east-1.amazonaws.com/";
const appsync_url = "https://s34ox7kri5dsvdr43bfgp6qh6i.appsync-api.us-east-1.amazonaws.com/graphql";
const api_key = "da2-dm2g4rqvjbaoxcpo4eccs3k5he";
const shadow_api_url = "https://698suy4zs3.execute-api.us-east-1.amazonaws.com/Prod/thing";
const AuthResult = struct {
id_token: []const u8,
@ -50,10 +50,10 @@ fn authenticate(allocator: std.mem.Allocator, username: []const u8, password: []
var client = http.Client{ .allocator = allocator };
defer client.deinit();
const body = try std.fmt.allocPrint(allocator, "{{\"AuthFlow\":\"USER_PASSWORD_AUTH\",\"ClientId\":\"{s}\",\"AuthParameters\":{{\"USERNAME\":\"{s}\",\"PASSWORD\":\"{s}\"}}}}", .{ CLIENT_ID, username, password });
const body = try std.fmt.allocPrint(allocator, "{{\"AuthFlow\":\"USER_PASSWORD_AUTH\",\"ClientId\":\"{s}\",\"AuthParameters\":{{\"USERNAME\":\"{s}\",\"PASSWORD\":\"{s}\"}}}}", .{ client_id, username, password });
defer allocator.free(body);
const uri = try std.Uri.parse(COGNITO_URL);
const uri = try std.Uri.parse(cognito_url);
var response_buf: [1024 * 1024]u8 = undefined;
var writer = std.Io.Writer.fixed(&response_buf);
@ -106,7 +106,7 @@ fn getDevices(allocator: std.mem.Allocator, id_token: []const u8, username: []co
const body = try std.fmt.allocPrint(allocator, "{{\"query\":\"{s}\",\"variables\":{{\"email\":\"{s}\"}}}}", .{ query, username });
defer allocator.free(body);
const uri = try std.Uri.parse(APPSYNC_URL);
const uri = try std.Uri.parse(appsync_url);
var response_buf: [1024 * 1024]u8 = undefined;
var writer = std.Io.Writer.fixed(&response_buf);
@ -117,7 +117,7 @@ fn getDevices(allocator: std.mem.Allocator, id_token: []const u8, username: []co
.response_writer = &writer,
.extra_headers = &.{
.{ .name = "Authorization", .value = id_token },
.{ .name = "x-api-key", .value = API_KEY },
.{ .name = "x-api-key", .value = api_key },
.{ .name = "Content-Type", .value = "application/json" },
},
});
@ -130,7 +130,7 @@ fn startRecirculation(allocator: std.mem.Allocator, id_token: []const u8, serial
var client = http.Client{ .allocator = allocator };
defer client.deinit();
const url = try std.fmt.allocPrint(allocator, "{s}/{s}/shadow", .{ SHADOW_API_URL, serial_number });
const url = try std.fmt.allocPrint(allocator, "{s}/{s}/shadow", .{ shadow_api_url, serial_number });
defer allocator.free(url);
const body = try std.fmt.allocPrint(allocator, "{{\"recirculation_duration\":{d},\"set_recirculation_enabled\":true}}", .{duration_minutes});
@ -162,7 +162,7 @@ fn getRecirculationStatus(allocator: std.mem.Allocator, id_token: []const u8, se
const body = try std.fmt.allocPrint(allocator, "{{\"query\":\"{s}\",\"variables\":{{\"heater_serial_number\":\"{s}\"}}}}", .{ query, serial_number });
defer allocator.free(body);
const uri = try std.Uri.parse(APPSYNC_URL);
const uri = try std.Uri.parse(appsync_url);
var response_buf: [1024 * 1024]u8 = undefined;
var writer = std.Io.Writer.fixed(&response_buf);
@ -173,7 +173,7 @@ fn getRecirculationStatus(allocator: std.mem.Allocator, id_token: []const u8, se
.response_writer = &writer,
.extra_headers = &.{
.{ .name = "Authorization", .value = id_token },
.{ .name = "x-api-key", .value = API_KEY },
.{ .name = "x-api-key", .value = api_key },
.{ .name = "Content-Type", .value = "application/json" },
},
});