get password from file
This commit is contained in:
parent
b93db148f6
commit
50ac6f1310
2 changed files with 16 additions and 10 deletions
1
.gitignore
vendored
1
.gitignore
vendored
|
@ -2,3 +2,4 @@
|
||||||
/zig-cache
|
/zig-cache
|
||||||
/zig-out
|
/zig-out
|
||||||
/config.json
|
/config.json
|
||||||
|
/password
|
||||||
|
|
25
src/main.zig
25
src/main.zig
|
@ -90,15 +90,29 @@ pub fn main() !void {
|
||||||
|
|
||||||
const b64 = std.base64.standard.Encoder;
|
const b64 = std.base64.standard.Encoder;
|
||||||
|
|
||||||
|
var password_buffer: [128]u8 = undefined;
|
||||||
|
var password: []const u8 = undefined;
|
||||||
|
if (config.value.loki.password_file) |password_file_path| {
|
||||||
|
password = try std.fs.cwd().readFile(password_file_path, &password_buffer);
|
||||||
|
password = std.mem.trimRight(u8, password, "\r\n");
|
||||||
|
} else if (config.value.loki.password) |password_data| {
|
||||||
|
@memcpy(&password_buffer, password_data);
|
||||||
|
password = password_buffer[0..password_data.len];
|
||||||
|
} else {
|
||||||
|
iperf3_log.err("unable to determine password!", .{});
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
var auth_buf: [256]u8 = undefined;
|
var auth_buf: [256]u8 = undefined;
|
||||||
const auth = try std.fmt.bufPrint(
|
const auth = try std.fmt.bufPrint(
|
||||||
&auth_buf,
|
&auth_buf,
|
||||||
"{s}:{s}",
|
"{s}:{s}",
|
||||||
.{
|
.{
|
||||||
config.value.loki.username,
|
config.value.loki.username,
|
||||||
config.value.loki.password.?,
|
password,
|
||||||
},
|
},
|
||||||
);
|
);
|
||||||
|
|
||||||
var auth_encoded_buf: [b64.calcSize(auth_buf.len)]u8 = undefined;
|
var auth_encoded_buf: [b64.calcSize(auth_buf.len)]u8 = undefined;
|
||||||
var auth_encoded = b64.encode(&auth_encoded_buf, auth);
|
var auth_encoded = b64.encode(&auth_encoded_buf, auth);
|
||||||
var auth_header_buf: [256]u8 = undefined;
|
var auth_header_buf: [256]u8 = undefined;
|
||||||
|
@ -106,18 +120,9 @@ pub fn main() !void {
|
||||||
|
|
||||||
const uri = try std.Uri.parse(config.value.loki.url);
|
const uri = try std.Uri.parse(config.value.loki.url);
|
||||||
|
|
||||||
// var headers = std.http.Headers{ .allocator = allocator };
|
|
||||||
// try headers.append("Authorization", auth_header);
|
|
||||||
// try headers.append("Content-Type", "application/json");
|
|
||||||
|
|
||||||
var client = std.http.Client{ .allocator = allocator };
|
var client = std.http.Client{ .allocator = allocator };
|
||||||
defer client.deinit();
|
defer client.deinit();
|
||||||
|
|
||||||
// const stderr_file = std.io.getStdErr().writer();
|
|
||||||
// var stderr_bw = std.io.bufferedWriter(stderr_file);
|
|
||||||
// const stderr = stderr_bw.writer();
|
|
||||||
// _ = stderr;
|
|
||||||
|
|
||||||
var port_buf: [16]u8 = undefined;
|
var port_buf: [16]u8 = undefined;
|
||||||
var port: []u8 = undefined;
|
var port: []u8 = undefined;
|
||||||
if (config.value.iperf3.port) |p| {
|
if (config.value.iperf3.port) |p| {
|
||||||
|
|
Loading…
Reference in a new issue