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
2a85c588
Verified
Commit
2a85c588
authored
4 years ago
by
Nik | Klampfradler
Browse files
Options
Downloads
Patches
Plain Diff
[OAuth] Document full_key and get_data
parent
dcaf0e1a
No related branches found
Branches containing commit
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
src/oauth.rs
+12
-2
12 additions, 2 deletions
src/oauth.rs
with
12 additions
and
2 deletions
src/oauth.rs
+
12
−
2
View file @
2a85c588
...
@@ -45,6 +45,9 @@ use reqwest;
...
@@ -45,6 +45,9 @@ use reqwest;
use
serde_json
;
use
serde_json
;
use
jq_rs
;
use
jq_rs
;
/// Construct a configuration key from parts
///
/// Simply joins all elements of the passed array with a '.'
fn
full_key
(
parts
:
Vec
<&
str
>
)
->
String
{
fn
full_key
(
parts
:
Vec
<&
str
>
)
->
String
{
parts
.join
(
"."
)
parts
.join
(
"."
)
}
}
...
@@ -136,17 +139,24 @@ pub fn get_access_token_password<E: Copy>(conf: &Config, prefix: &str, username:
...
@@ -136,17 +139,24 @@ pub fn get_access_token_password<E: Copy>(conf: &Config, prefix: &str, username:
}
}
}
}
/// Retrieve text data from a configured URL endpoint
///
/// Takes the same arguments as `get_data_jq`.
fn
get_data
(
conf
:
&
Config
,
prefix
:
&
str
,
endpoint
:
&
str
,
param
:
String
,
token
:
&
BasicTokenResponse
)
->
Result
<
String
,
Box
<
dyn
error
::
Error
>>
{
fn
get_data
(
conf
:
&
Config
,
prefix
:
&
str
,
endpoint
:
&
str
,
param
:
String
,
token
:
&
BasicTokenResponse
)
->
Result
<
String
,
Box
<
dyn
error
::
Error
>>
{
/// Extract token as string from deserialized access token
let
access_token
=
token
.access_token
()
.secret
();
let
access_token
=
token
.access_token
()
.secret
();
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_or_error
(
&
conf
,
&
full_key
(
vec!
[
prefix
,
"urls"
,
endpoint
]),
""
)
?
;
let
mut
endpoint_url
:
String
=
get_or_error
(
&
conf
,
&
full_key
(
vec!
[
prefix
,
"urls"
,
endpoint
]),
""
)
?
;
endpoint_url
=
endpoint_url
.replace
(
"{}"
,
&
param
);
endpoint_url
=
endpoint_url
.replace
(
"{}"
,
&
param
);
debug!
(
"Loading text data from {}"
,
endpoint_url
);
debug!
(
"Loading text data from {}"
,
endpoint_url
);
// Send off request to server
let
client
=
reqwest
::
blocking
::
Client
::
new
();
let
client
=
reqwest
::
blocking
::
Client
::
new
();
Ok
(
client
Ok
(
client
.get
(
&
endpoint_url
)
.get
(
&
endpoint_url
)
.header
(
reqwest
::
header
::
AUTHORIZATION
,
format!
(
"
Bearer {}"
,
access_token
))
.header
(
reqwest
::
header
::
AUTHORIZATION
,
format!
(
"
{} {}"
,
token_type
,
access_token
))
.send
()
?
.send
()
?
.text
()
?
)
.text
()
?
)
}
}
...
...
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