Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add the NetworkOptions.__diagnostics__() function #21

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
8 changes: 8 additions & 0 deletions test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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()