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
a0494398
"git@edugit.org:nbildhauer/teckids.org.git" did not exist on "a1846b25715634a90a161bac17e93499e678e42b"
Verified
Commit
a0494398
authored
3 years ago
by
Nik | Klampfradler
Browse files
Options
Downloads
Patches
Plain Diff
[OAuth] Document get_client and remove get_or_error
parent
2a85c588
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
+0
-13
0 additions, 13 deletions
src/config.rs
src/oauth.rs
+13
-4
13 additions, 4 deletions
src/oauth.rs
with
13 additions
and
17 deletions
src/config.rs
+
0
−
13
View file @
a0494398
...
...
@@ -73,16 +73,3 @@ pub fn get_optional<'de, T: Deserialize<'de>>(conf: &config::Config, key: &str)
},
}
}
pub
fn
get_or_error
<
'de
,
T
:
Deserialize
<
'de
>
,
E
>
(
config
:
&
config
::
Config
,
key
:
&
str
,
error_value
:
E
)
->
Result
<
T
,
E
>
{
match
get_optional
(
config
,
key
)
{
Some
(
v
)
=>
{
debug!
(
"Configuration key found: {}"
,
key
);
return
Ok
(
v
);
},
None
=>
{
error!
(
"Configuration key not found: {}"
,
key
);
return
Err
(
error_value
);
},
}
}
This diff is collapsed.
Click to expand it.
src/oauth.rs
+
13
−
4
View file @
a0494398
...
...
@@ -14,7 +14,6 @@
*/
use
crate
::
config
::{
get_or_error
,
get_optional
};
...
...
@@ -52,13 +51,22 @@ fn full_key(parts: Vec<&str>) -> String {
parts
.join
(
"."
)
}
/// Construct an OAuth2 client ready to exchange credentials
///
/// Arguments
/// ---------
///
/// `conf` - reference to the config object
/// `prefix` - current prefix (probably `nss` or `pam`)
/// `error_value` - The value to return as Err result on error
fn
get_client
<
E
:
Copy
>
(
conf
:
&
Config
,
prefix
:
&
str
,
error_value
:
E
)
->
Result
<
BasicClient
,
E
>
{
let
client_id
=
ClientId
::
new
(
get_or_error
(
&
conf
,
&
full_key
(
vec!
[
prefix
,
"client_id"
]),
error_value
)
?
);
// Get all the configuration parameters
let
client_id
=
ClientId
::
new
(
get_optional
(
&
conf
,
&
full_key
(
vec!
[
prefix
,
"client_id"
]))
.ok_or
(
error_value
)
?
);
let
client_secret
=
match
get_optional
(
&
conf
,
&
full_key
(
vec!
[
prefix
,
"client_secret"
]))
{
Some
(
v
)
=>
Some
(
ClientSecret
::
new
(
v
)),
None
=>
None
,
};
let
auth_url
=
match
AuthUrl
::
new
(
get_o
r_error
(
&
conf
,
&
full_key
(
vec!
[
prefix
,
"auth_url"
])
,
error_value
)
?
)
{
let
auth_url
=
match
AuthUrl
::
new
(
get_o
ptional
(
&
conf
,
&
full_key
(
vec!
[
prefix
,
"auth_url"
])
)
.ok_or
(
error_value
)
?
)
{
Ok
(
u
)
=>
u
,
_
=>
{
error!
(
"Could not parse authorization URL"
);
...
...
@@ -76,6 +84,7 @@ fn get_client<E: Copy>(conf: &Config, prefix: &str, error_value: E) -> Result<Ba
None
=>
None
,
};
// Construct an OAuth 2 client ready to exchange credentials
let
client
=
BasicClient
::
new
(
client_id
,
client_secret
,
auth_url
,
token_url
);
return
Ok
(
client
);
}
...
...
@@ -148,7 +157,7 @@ fn get_data(conf: &Config, prefix: &str, endpoint: &str, param: String, token: &
let
token_type
=
"Bearer"
.to_string
();
// FIXME Probably we need to handle other token types
// Retreieve endpoint URL from configuration
let
mut
endpoint_url
:
String
=
get_o
r_error
(
&
conf
,
&
full_key
(
vec!
[
prefix
,
"urls"
,
endpoint
])
,
""
)
?
;
let
mut
endpoint_url
:
String
=
get_o
ptional
(
&
conf
,
&
full_key
(
vec!
[
prefix
,
"urls"
,
endpoint
])
)
.ok_or
(
""
)
?
;
endpoint_url
=
endpoint_url
.replace
(
"{}"
,
&
param
);
debug!
(
"Loading text data from {}"
,
endpoint_url
);
...
...
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