FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
cli/src/Support/ResolvedConnection.php at main · durable-workflow/cli · GitHub
Uh oh!
There was an error while loading.
Please reload this page
.
durable-workflow
/
cli
Public
Notifications
You must be signed in to change notification settings
Fork
0
Star
1
Code
Issues
0
Pull requests
0
Actions
Projects
Security and quality
0
Insights
Additional navigation options
Code
Issues
Pull requests
Actions
Projects
Security and quality
Insights
Expand file tree
Breadcrumbs
cli
/
src
/
Support
/
ResolvedConnection.php
Copy path
More file actions
More file actions
Latest commit
History
History
History
156 lines (137 loc) · 4.72 KB
Breadcrumbs
cli
/
src
/
Support
/
ResolvedConnection.php
Copy path
File metadata and controls
156 lines (137 loc) · 4.72 KB
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
<?php
declare
(strict_types=
1
);
namespace
DurableWorkflow
\
Cli
\
Support
;
/**
* The effective server/namespace/token tuple a command should use
* after flag > env > profile > default precedence has been applied.
* See ProfileResolver for how each field is chosen.
*/
final
class
ResolvedConnection
{
/**
* @param array<string, mixed> $sources
*/
public
function
__construct
(
public
readonly
string
$
server
,
public
readonly
string
$
namespace
,
public
readonly
?
string
$
token
,
public
readonly
bool
$
tlsVerify
,
public
readonly
?
Profile
$
profile
,
public
readonly
array
$
sources
= [],
) {}
/**
* Machine-readable, redacted view of the connection after flag, env,
* profile, and default precedence has been applied.
*
* @return array<string, mixed>
*/
public
function
effectiveConfig
(
string
$
configPath
):
array
{
$
tokenSource
=
$
this
->
sourceDetail
(
'
token
'
);
$
serverSource
=
$
this
->
sourceName
(
'
server
'
,
'
default
'
);
$
namespaceSource
=
$
this
->
sourceName
(
'
namespace
'
,
'
default
'
);
$
profileSource
=
$
this
->
sourceName
(
'
profile
'
,
null
);
$
tlsSource
=
$
this
->
sourceName
(
'
tls_verify
'
,
'
default
'
);
$
authSource
=
is_string
(
$
tokenSource
[
'
source
'
] ??
null
) ?
$
tokenSource
[
'
source
'
] :
'
none
'
;
$
server
= [
'
value
'
=>
$
this
->
server
,
'
source
'
=>
$
serverSource
,
'
contract_source
'
=>
self
::
contractSource
(
$
serverSource
),
];
return
[
'
contract
'
=> [
'
schema
'
=> AuthCompositionContract::
SCHEMA
,
'
version
'
=> AuthCompositionContract::
VERSION
,
],
'
server
'
=>
$
server
,
'
server_url
'
=>
$
server
,
'
namespace
'
=> [
'
value
'
=>
$
this
->
namespace
,
'
source
'
=>
$
namespaceSource
,
'
contract_source
'
=>
self
::
contractSource
(
$
namespaceSource
),
],
'
profile
'
=> [
'
name
'
=>
$
this
->
profile
?->name,
'
source
'
=>
$
profileSource
,
'
contract_source
'
=>
self
::
profileContractSource
(
$
profileSource
),
'
config_path
'
=>
$
configPath
,
],
'
auth
'
=> [
'
type
'
=>
$
this
->
token
!==
null
?
'
token
'
:
'
none
'
,
'
transport
'
=>
$
this
->
token
!==
null
?
'
bearer_authorization_header
'
:
null
,
'
present
'
=>
$
this
->
token
!==
null
,
'
source
'
=>
$
authSource
,
'
contract_source
'
=>
self
::
authContractSource
(
$
authSource
),
'
env
'
=>
$
tokenSource
[
'
env
'
] ??
null
,
'
profile
'
=>
$
tokenSource
[
'
profile
'
] ??
null
,
'
value
'
=>
$
this
->
token
!==
null
?
'
redacted
'
:
null
,
],
'
tls
'
=> [
'
verify
'
=>
$
this
->
tlsVerify
,
'
source
'
=>
$
tlsSource
,
'
contract_source
'
=>
self
::
contractSource
(
$
tlsSource
),
],
'
identity
'
=> [
'
subject
'
=>
null
,
'
roles
'
=> [],
'
source
'
=>
'
server
'
,
'
asserted
'
=>
false
,
],
];
}
private
function
sourceName
(
string
$
key
, ?
string
$
default
): ?
string
{
$
source
=
$
this
->
sources
[
$
key
] ??
null
;
if
(
is_string
(
$
source
)) {
return
$
source
;
}
if
(
is_array
(
$
source
) &&
is_string
(
$
source
[
'
source
'
] ??
null
)) {
return
$
source
[
'
source
'
];
}
return
$
default
;
}
/**
* @return array<string, mixed>
*/
private
function
sourceDetail
(
string
$
key
):
array
{
$
source
=
$
this
->
sources
[
$
key
] ??
null
;
if
(
is_array
(
$
source
)) {
return
$
source
;
}
if
(
is_string
(
$
source
)) {
return
[
'
source
'
=>
$
source
];
}
return
[];
}
private
static
function
contractSource
(?
string
$
source
): ?
string
{
if
(
$
source
===
null
) {
return
null
;
}
if
(
$
source
===
'
profile
'
) {
return
'
selected_profile
'
;
}
if
(
str_starts_with
(
$
source
,
'
DURABLE_WORKFLOW_
'
) ||
$
source
===
'
DW_ENV
'
) {
return
'
environment
'
;
}
return
$
source
;
}
private
static
function
profileContractSource
(?
string
$
source
): ?
string
{
return
match
(
$
source
) {
'
flag
'
=>
'
flag_env
'
,
'
DW_ENV
'
=>
'
DW_ENV
'
,
'
current_env
'
=>
'
current_profile
'
,
default
=>
$
source
,
};
}
private
static
function
authContractSource
(
string
$
source
):
string
{
return
match
(
$
source
) {
'
DURABLE_WORKFLOW_AUTH_TOKEN
'
=>
'
environment
'
,
'
profile_literal
'
=>
'
selected_profile
'
,
default
=>
$
source
,
};
}
}
Back
|
FazBrowse Home
|
New Git URL