From 44259fd432b07f3ce864d0c1352613e06e962884 Mon Sep 17 00:00:00 2001 From: Dilum Aluthge Date: Tue, 15 Feb 2022 19:46:14 -0500 Subject: [PATCH] Add the `NetworkOptions.__diagnostics__()` function --- src/NetworkOptions.jl | 1 + src/diagnostics.jl | 50 +++++++++++++++++++++++++++++++++++++++++++ test/runtests.jl | 8 +++++++ 3 files changed, 59 insertions(+) create mode 100644 src/diagnostics.jl diff --git a/src/NetworkOptions.jl b/src/NetworkOptions.jl index 87a82e1..5b06fe0 100644 --- a/src/NetworkOptions.jl +++ b/src/NetworkOptions.jl @@ -1,6 +1,7 @@ module NetworkOptions include("ca_roots.jl") +include("diagnostics.jl") include("ssh_options.jl") include("verify_host.jl") diff --git a/src/diagnostics.jl b/src/diagnostics.jl new file mode 100644 index 0000000..3fd321c --- /dev/null +++ b/src/diagnostics.jl @@ -0,0 +1,50 @@ +# NetworkOptions.__diagnostics__() +function __diagnostics__(io::IO) + indent = " " + name_list = [ + "JULIA_ALWAYS_VERIFY_HOSTS", + "JULIA_NO_VERIFY_HOSTS", + "JULIA_SSH_NO_VERIFY_HOSTS", + "JULIA_SSL_CA_ROOTS_PATH", + "JULIA_SSL_NO_VERIFY_HOSTS", + "SSH_DIR", + "SSH_KEY_NAME", + "SSH_KEY_PASS", + "SSH_KEY_PATH", + "SSH_KNOWN_HOSTS_FILES", + "SSH_PUB_KEY_PATH", + "SSL_CERT_DIR", + "SSL_CERT_FILE", + ] + lines_to_print = Tuple{String, String}[] + environment = ENV + for name in name_list + if haskey(environment, name) + value = environment[name] + if isempty(value) + description = "[empty]" + else + if isempty(strip(value)) + description = "[whitespace]" + else + description = "***" + end + end + line = (name, description) + push!(lines_to_print, line) + end + end + if isempty(lines_to_print) + println(io, "Relevant environment variables: [none]") + else + println(io, "Relevant environment variables:") + all_names = getindex.(lines_to_print, Ref(1)) + max_name_length = maximum(length.(all_names)) + name_pad_length = length(indent) + max_name_length + 1 + for (name, description) in lines_to_print + name_padded = rpad("$(indent)$(name):", name_pad_length) + println(io, "$(name_padded) $(description)") + end + end + return nothing +end diff --git a/test/runtests.jl b/test/runtests.jl index 14a1674..76f1c18 100644 --- a/test/runtests.jl +++ b/test/runtests.jl @@ -316,4 +316,12 @@ end end end +@testset "__diagnostics__()" begin + # check that `NetworkOptions.__diagnostics__(io)` doesn't error, produces some output + buf = PipeBuffer() + NetworkOptions.__diagnostics__(buf) + output = read(buf, String) + @test occursin("Relevant environment variables:", output) +end + reset_env()