Skip to content

Commit 9522699

Browse files
committed
tweak state diagram
1 parent 408c2cf commit 9522699

File tree

2 files changed

+60
-30
lines changed

2 files changed

+60
-30
lines changed

bin/structure.jl

Lines changed: 18 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,15 +9,15 @@ buffer = let buffer = IOBuffer(write=true)
99
write(buffer, """
1010
# Internal implementation notes
1111
12-
The authentication control flow is implemented as the following state machine, starting from the `NeedAuthentication` state (or `NoAuthentication` if `force=true` is passed to `authenticate`), and finishing in either `Success` or `Failure`.
12+
The authentication control flow is implemented as the following state machine, starting from the `NeedAuthentication`
13+
state (or `NoAuthentication` if `force=true` is passed to `authenticate`), and finishing in either `Success` or `Failure`.
1314
1415
```mermaid
1516
---
1617
title: PkgAuthentication state machine diagram
1718
---
1819
1920
stateDiagram-v2
20-
direction LR
2121
2222
[*] --> NeedAuthentication
2323
[*] --> NoAuthentication
@@ -33,6 +33,7 @@ buffer = let buffer = IOBuffer(write=true)
3333
all_targets[m[1]] = strip.(split(m[2], ','))
3434
end
3535
end
36+
choice_index = 0
3637
for state in sort(InteractiveUtils.subtypes(PkgAuthentication.State), by=string)
3738
println(buffer)
3839
state_str = string(nameof(state))
@@ -41,15 +42,27 @@ buffer = let buffer = IOBuffer(write=true)
4142
if isempty(targets) && (state ignore_errors)
4243
@warn "Empty targets list for $state"
4344
elseif !isempty(targets)
44-
for target in targets
45-
println(buffer, " $(state_str) --> $(target)")
45+
46+
if length(targets) > 1
47+
choice_index += 1
48+
println(buffer, " state state$(choice_index) <<choice>>")
49+
println(buffer, " $(state_str) --> state$(choice_index)")
50+
for target in targets
51+
if state_str == target
52+
println(buffer, " $(state_str) --> $(target): retry")
53+
else
54+
println(buffer, " state$(choice_index) --> $(target)")
55+
end
56+
end
57+
else
58+
println(buffer, " $(state_str) --> $(only(targets))")
4659
end
4760
end
4861
# Extract the docstring and put it into a mermaid note
4962
try
5063
docstr::Markdown.MD = Base.Docs.doc(state)
5164
docstr_text = docstr.meta[:results][1].text[1]
52-
println(buffer, " note right of $(state_str)")
65+
println(buffer, " note left of $(state_str)")
5366
TextWrap.print_wrapped(
5467
buffer, docstr_text, width=65,
5568
initial_indent = 8, subsequent_indent = 8,

docs/internals.md

Lines changed: 42 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,27 @@
11
# Internal implementation notes
22

3-
The authentication control flow is implemented as the following state machine, starting from the `NeedAuthentication` state (or `NoAuthentication` if `force=true` is passed to `authenticate`), and finishing in either `Success` or `Failure`.
3+
The authentication control flow is implemented as the following state machine, starting from the `NeedAuthentication`
4+
state (or `NoAuthentication` if `force=true` is passed to `authenticate`), and finishing in either `Success` or `Failure`.
45

56
```mermaid
67
---
78
title: PkgAuthentication state machine diagram
9+
theme: 'base'
10+
themeVariables:
11+
noteTextColor: '#222'
812
---
913
1014
stateDiagram-v2
11-
direction LR
1215
1316
[*] --> NeedAuthentication
1417
[*] --> NoAuthentication
1518
16-
ClaimToken --> ClaimToken
17-
ClaimToken --> HasNewToken
18-
ClaimToken --> Failure
19-
note right of ClaimToken
19+
state state1 <<choice>>
20+
ClaimToken --> state1
21+
ClaimToken --> ClaimToken: retry
22+
state1 --> HasNewToken
23+
state1 --> Failure
24+
note left of ClaimToken
2025
Starts polling the Pkg server's OAuth token claiming
2126
endpoint, returning to ClaimToken while the polling is
2227
happening. Proceeds to HasNewToken if it successfully
@@ -25,10 +30,12 @@ stateDiagram-v2
2530
end note
2631
2732
28-
HasNewToken --> HasNewToken
29-
HasNewToken --> Success
30-
HasNewToken --> Failure
31-
note right of HasNewToken
33+
state state2 <<choice>>
34+
HasNewToken --> state2
35+
HasNewToken --> HasNewToken: retry
36+
state2 --> Success
37+
state2 --> Failure
38+
note left of HasNewToken
3239
Takes the token from the previous step and writes it to
3340
the auth.toml file. In order to handle potential race
3441
conditions with other writes, it will check that the
@@ -38,43 +45,53 @@ stateDiagram-v2
3845
if there is an unexpected failure.
3946
end note
4047
41-
HasToken --> NeedRefresh
42-
HasToken --> Success
43-
note right of HasToken
48+
state state3 <<choice>>
49+
HasToken --> state3
50+
state3 --> NeedRefresh
51+
state3 --> Success
52+
note left of HasToken
4453
If the token is valid (i.e. not expired, based on the
4554
expiry times in the auth.toml file), proceeds to Success.
4655
Otherwise, proceeds to NeedRefresh.
4756
end note
4857
49-
NeedAuthentication --> HasToken
50-
NeedAuthentication --> NoAuthentication
51-
note right of NeedAuthentication
58+
state state4 <<choice>>
59+
NeedAuthentication --> state4
60+
state4 --> HasToken
61+
state4 --> NoAuthentication
62+
note left of NeedAuthentication
5263
Checks if a syntactically valid auth.toml token file
5364
exists for the requested server (but does not check
5465
whether it has expired or not). Proceeds to HasToken if
5566
it exists, or NoAuthentication if not.
5667
end note
5768
58-
NeedRefresh --> HasNewToken
59-
NeedRefresh --> NoAuthentication
60-
note right of NeedRefresh
69+
state state5 <<choice>>
70+
NeedRefresh --> state5
71+
state5 --> HasNewToken
72+
state5 --> NoAuthentication
73+
note left of NeedRefresh
6174
Attempts to acquire a new access token by using the
6275
refresh token in the auth.toml. If the refresh succeeds,
6376
it will proceed to HasNewToken, or to NoAuthentication if
6477
it fails.
6578
end note
6679
67-
NoAuthentication --> RequestLogin
68-
NoAuthentication --> Failure
69-
note right of NoAuthentication
80+
state state6 <<choice>>
81+
NoAuthentication --> state6
82+
state6 --> RequestLogin
83+
state6 --> Failure
84+
note left of NoAuthentication
7085
Attempts to acquire an OAuth challenge from the Pkg
7186
server. If successful, proceeds to RequestLogin, or to
7287
Failure otherwise.
7388
end note
7489
75-
RequestLogin --> ClaimToken
76-
RequestLogin --> Failure
77-
note right of RequestLogin
90+
state state7 <<choice>>
91+
RequestLogin --> state7
92+
state7 --> ClaimToken
93+
state7 --> Failure
94+
note left of RequestLogin
7895
Presents the in-browser step of the OAuth authentication
7996
process to the user (e.g. by opening the Pkg server's
8097
login page in the user's browser). Proceeds to ClaimToken

0 commit comments

Comments
 (0)