Skip to content

Commit bbb6145

Browse files
committed
auth docs
1 parent b7d86dc commit bbb6145

File tree

3 files changed

+48
-0
lines changed

3 files changed

+48
-0
lines changed

docs/make.jl

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,19 @@ const DEFAULT_PROJECT_AUTH = mockauth(
3232
projectauth_setup!() = JuliaHub.__AUTH__[] = DEFAULT_PROJECT_AUTH
3333
projectauth_teardown!() = JuliaHub.__AUTH__[] = DEFAULT_GLOBAL_MOCK_AUTH
3434

35+
function env_setup!(; project=false)
36+
ENV["JULIA_PKG_SERVER"] = "juliahub.com"
37+
if project
38+
ENV["JULIAHUB_PROJECT_UUID"] = "b1a95ba8-43e6-4eb6-b280-3c5cbe0fa0b9"
39+
end
40+
return nothing
41+
end
42+
function env_teardown!()
43+
delete!(ENV, "JULIA_PKG_SERVER")
44+
delete!(ENV, "JULIAHUB_PROJECT_UUID")
45+
return nothing
46+
end
47+
3548
# The following setup function is reused in both at-setup blocks, but also in
3649
# doctestsetup.
3750
function setup_job_results_file!()

docs/src/guides/authentication.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,8 @@ When working with JuliaHub.jl in JuliaHub cloud environment, such as in JuliaHub
4343
The `JULIA_PKG_SERVER` should always be correctly set up, and the `auth.toml` file will also be present and up-to-date.
4444
This means that [`authenticate`](@ref) should automatically be able to authenticate your session, and you should never be prompted for interactive authentication.
4545

46+
This also extends to JuliaHub Projects support --- if an IDE has been launched withing the context of a project, the environment will have the `JULIAHUB_PROJECT_UUID` environment set, and the authentication object will be automatically linked to the correct project.
47+
4648
!!! tip "No need to authenticate()"
4749

4850
As in a JuliaHub environment everything is already set up and pointing to the correct server, you do not need to call [`authenticate`](@ref) yourself, nor set up `JULIA_PKG_SERVER`.

src/authentication.jl

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -229,6 +229,39 @@ This can be set by passing the optional `project` argument, which works as follo
229229
When the [`Authentication`](@ref) object is constructed, access to or existence of the specified
230230
project is not checked. However, if you attempt any project operations with with such an
231231
authentication object, they will fail and throw an error.
232+
233+
# Examples
234+
235+
If `JULIA_PKG_SERVER` is set, `authenticate()` will pick it up automatically,
236+
although it can also be overridden by setting the instance hostname explicitly:
237+
238+
```jldoctest; setup = :(Main.env_setup!()), teardown = :(Main.env_teardown!())
239+
julia> ENV["JULIA_PKG_SERVER"]
240+
"juliahub.com"
241+
242+
julia> JuliaHub.authenticate()
243+
JuliaHub.Authentication("https://juliahub.com", "username", *****)
244+
245+
julia> JuliaHub.authenticate("mycompany.juliahub.com")
246+
JuliaHub.Authentication("https://mycompany.juliahub.com", "username", *****)
247+
```
248+
249+
If `JULIAHUB_PROJECT_UUID` is set to point to a JuliaHub Project (e.g. in JuliaHub cloud
250+
environments), it will also get automatically picked up, but can also be overridden:
251+
252+
```jldoctest; setup = :(Main.env_setup!(; project=true)), teardown = :(Main.env_teardown!())
253+
julia> ENV["JULIAHUB_PROJECT_UUID"]
254+
"b1a95ba8-43e6-4eb6-b280-3c5cbe0fa0b9"
255+
256+
julia> JuliaHub.authenticate()
257+
JuliaHub.Authentication("https://juliahub.com", "username", *****; project_id = "b1a95ba8-43e6-4eb6-b280-3c5cbe0fa0b9")
258+
259+
julia> JuliaHub.authenticate(; project = "7ed96f69-a765-4de6-ac00-04a38684ce1c")
260+
JuliaHub.Authentication("https://juliahub.com", "username", *****; project_id = "7ed96f69-a765-4de6-ac00-04a38684ce1c")
261+
262+
julia> JuliaHub.authenticate(; project = nothing)
263+
JuliaHub.Authentication("https://juliahub.com", "username", *****)
264+
```
232265
"""
233266
function authenticate end
234267

0 commit comments

Comments
 (0)