Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
N
nss-pam-webapi
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package Registry
Model registry
Operate
Terraform modules
Monitor
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
magicfelix
nss-pam-webapi
Commits
a698ac16
Verified
Commit
a698ac16
authored
3 years ago
by
Nik | Klampfradler
Browse files
Options
Downloads
Patches
Plain Diff
[Config] Make scopes optional
parent
3944d356
No related branches found
No related tags found
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
src/config.rs
+5
-1
5 additions, 1 deletion
src/config.rs
src/oauth.rs
+8
-2
8 additions, 2 deletions
src/oauth.rs
with
13 additions
and
3 deletions
src/config.rs
+
5
−
1
View file @
a698ac16
...
@@ -58,12 +58,16 @@ pub fn argv_to_config(argv: &Vec<String>) -> config::Config {
...
@@ -58,12 +58,16 @@ pub fn argv_to_config(argv: &Vec<String>) -> config::Config {
}
}
pub
fn
get_optional
<
'de
,
T
:
Deserialize
<
'de
>>
(
conf
:
&
config
::
Config
,
key
:
&
str
)
->
Option
<
T
>
{
pub
fn
get_optional
<
'de
,
T
:
Deserialize
<
'de
>>
(
conf
:
&
config
::
Config
,
key
:
&
str
)
->
Option
<
T
>
{
debug!
(
"Looking up key {} in config"
,
key
);
match
conf
.get
(
key
)
{
match
conf
.get
(
key
)
{
Ok
(
v
)
=>
Some
(
v
),
Ok
(
v
)
=>
Some
(
v
),
Err
(
_
)
=>
{
Err
(
_
)
=>
{
// Try falling back to parent block
// Try falling back to parent block
match
key
.find
(
'.'
)
{
match
key
.find
(
'.'
)
{
Some
(
i
)
=>
get_optional
(
conf
,
&
key
[
i
+
1
..
]),
Some
(
i
)
=>
{
debug!
(
"Key {} not found in config, trying parent block"
,
key
);
get_optional
(
conf
,
&
key
[
i
+
1
..
])
},
None
=>
None
,
None
=>
None
,
}
}
},
},
...
...
This diff is collapsed.
Click to expand it.
src/oauth.rs
+
8
−
2
View file @
a698ac16
...
@@ -71,7 +71,10 @@ fn get_client<E: Copy>(conf: Config, prefix: &str, error_value: E) -> Result<Bas
...
@@ -71,7 +71,10 @@ fn get_client<E: Copy>(conf: Config, prefix: &str, error_value: E) -> Result<Bas
}
}
pub
fn
get_access_token
<
E
:
Copy
>
(
conf
:
Config
,
prefix
:
&
str
,
error_value
:
E
,
unauth_value
:
E
)
->
Result
<
BasicTokenResponse
,
E
>
{
pub
fn
get_access_token
<
E
:
Copy
>
(
conf
:
Config
,
prefix
:
&
str
,
error_value
:
E
,
unauth_value
:
E
)
->
Result
<
BasicTokenResponse
,
E
>
{
let
scopes
:
Vec
<&
str
>
=
get_or_error
(
&
conf
,
&
full_key
(
prefix
,
"scopes"
),
error_value
)
?
;
let
scopes
:
Vec
<
String
>
=
match
get_optional
(
&
conf
,
&
full_key
(
prefix
,
"scopes"
))
{
Some
(
v
)
=>
v
,
None
=>
vec!
[]
};
let
client
=
get_client
(
conf
,
prefix
,
error_value
)
?
;
let
client
=
get_client
(
conf
,
prefix
,
error_value
)
?
;
let
mut
request
=
client
.exchange_client_credentials
();
let
mut
request
=
client
.exchange_client_credentials
();
...
@@ -96,7 +99,10 @@ pub fn get_access_token<E: Copy>(conf: Config, prefix: &str, error_value: E, una
...
@@ -96,7 +99,10 @@ pub fn get_access_token<E: Copy>(conf: Config, prefix: &str, error_value: E, una
}
}
pub
fn
get_access_token_password
<
E
:
Copy
>
(
conf
:
Config
,
prefix
:
&
str
,
username
:
String
,
password
:
String
,
error_value
:
E
,
unauth_value
:
E
)
->
Result
<
BasicTokenResponse
,
E
>
{
pub
fn
get_access_token_password
<
E
:
Copy
>
(
conf
:
Config
,
prefix
:
&
str
,
username
:
String
,
password
:
String
,
error_value
:
E
,
unauth_value
:
E
)
->
Result
<
BasicTokenResponse
,
E
>
{
let
scopes
:
Vec
<&
str
>
=
get_or_error
(
&
conf
,
&
full_key
(
prefix
,
"scopes"
),
error_value
)
?
;
let
scopes
:
Vec
<
String
>
=
match
get_optional
(
&
conf
,
&
full_key
(
prefix
,
"scopes"
))
{
Some
(
v
)
=>
v
,
None
=>
vec!
[]
};
let
res_username
=
ResourceOwnerUsername
::
new
(
username
);
let
res_username
=
ResourceOwnerUsername
::
new
(
username
);
let
res_password
=
ResourceOwnerPassword
::
new
(
password
);
let
res_password
=
ResourceOwnerPassword
::
new
(
password
);
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment