Skip to content

Commit

Permalink
Add the NetworkOptions.__diagnostics__() function
Browse files Browse the repository at this point in the history
  • Loading branch information
DilumAluthge committed Feb 16, 2022
1 parent 4d3df64 commit fcfbbcc
Show file tree
Hide file tree
Showing 3 changed files with 61 additions and 0 deletions.
1 change: 1 addition & 0 deletions src/NetworkOptions.jl
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
module NetworkOptions

include("ca_roots.jl")
include("diagnostics.jl")
include("ssh_options.jl")
include("verify_host.jl")

Expand Down
50 changes: 50 additions & 0 deletions src/diagnostics.jl
Original file line number Diff line number Diff line change
@@ -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
10 changes: 10 additions & 0 deletions test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -314,6 +314,16 @@ end
end
clear_env()
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)

NetworkOptions.__diagnostics__(stdout) # TODO: delete this line before merging the PR
end
end

reset_env()

0 comments on commit fcfbbcc

Please sign in to comment.