Skip to content

Commit 1b124d2

Browse files
authored
Merge pull request #22 from DilumAluthge/dpa/env
Add the optional `modify_environment` kwarg to the `authenticate(server::AbstractString)` method
2 parents 971bfef + 4a7c9d7 commit 1b124d2

File tree

1 file changed

+17
-7
lines changed

1 file changed

+17
-7
lines changed

src/PkgAuthentication.jl

Lines changed: 17 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -32,14 +32,17 @@ function _assert_pkg_server_env_var_is_set()
3232
end
3333

3434
"""
35-
authenticate(server::AbstractString)
35+
authenticate(server::AbstractString; kwargs...)
3636
3737
Starts interactive (blocking) browser-based Pkg server authentication for the Pkg
3838
server specified by `server`. Also sets the `$(pkg_server_env_var_name)` environment
3939
variable to `server`.
4040
4141
`server` must be the URL of a valid Pkg server.
4242
43+
## Keyword arguments
44+
- `modify_environment::Bool = true`: Set the `$(pkg_server_env_var_name)` environment variable to `server`. In package code, this should probably be set to `false`, so that the package would not have unexpected global side effects.
45+
4346
## Example usage
4447
4548
```julia
@@ -51,13 +54,20 @@ function authenticate(
5154
auth_suffix::Union{String, Nothing} = nothing,
5255
force::Union{Bool, Nothing} = nothing,
5356
tries::Union{Integer, Nothing} = nothing,
57+
modify_environment::Bool = true,
5458
)::Union{Success, Failure}
55-
ENV[pkg_server_env_var_name] = server
56-
authenticate(;
57-
auth_suffix = auth_suffix,
58-
force = force,
59-
tries = tries,
60-
)
59+
if modify_environment
60+
ENV[pkg_server_env_var_name] = server
61+
end
62+
# Even if `modify_environment` is `false`, we still need to set the environment
63+
# variable for the duration of the `authenticate` call.
64+
withenv(pkg_server_env_var_name => server) do
65+
authenticate(;
66+
auth_suffix = auth_suffix,
67+
force = force,
68+
tries = tries,
69+
)
70+
end
6171
end
6272

6373
"""

0 commit comments

Comments
 (0)