Skip to content

Commit

Permalink
Add a way to see the refresh token
Browse files Browse the repository at this point in the history
  • Loading branch information
ctron committed May 11, 2021
1 parent df92589 commit 0c77aa3
Show file tree
Hide file tree
Showing 3 changed files with 74 additions and 0 deletions.
12 changes: 12 additions & 0 deletions console-frontend/src/page.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ use crate::{
};
use patternfly_yew::*;
use yew::prelude::*;
use yew_router::agent::RouteRequest;
use yew_router::prelude::*;

#[derive(Switch, Debug, Clone, PartialEq)]
Expand All @@ -18,6 +19,8 @@ pub enum AppRoute {
Examples(Examples),
#[to = "/keys"]
ApiKeys,
#[to = "/token"]
CurrentToken,
// Index must come last
#[to = "/"]
Index,
Expand All @@ -38,6 +41,7 @@ pub struct AppPage {
pub enum Msg {
Logout,
About,
CurrentToken,
}

impl Component for AppPage {
Expand All @@ -60,6 +64,9 @@ impl Component for AppPage {
/>
}),
}),
Msg::CurrentToken => RouteAgentDispatcher::<()>::new().send(RouteRequest::ChangeRoute(
Route::from(AppRoute::CurrentToken),
)),
}
true
}
Expand Down Expand Up @@ -148,6 +155,7 @@ impl Component for AppPage {
// links
items.push({
let mut items = Vec::new();
items.push(html_nested!{<DropdownItem onclick=self.link.callback(|_|Msg::CurrentToken)>{"Current Token"}</DropdownItem>});
if let Some(account_url) = account_url {
items.push(html_nested! {
<DropdownItem target="_blank" href=account_url>{"Account"} <span class="pf-u-pl-sm">{Icon::ExternalLinkAlt}</span></DropdownItem>
Expand Down Expand Up @@ -182,6 +190,7 @@ impl Component for AppPage {
}];

let backend = self.props.backend.clone();
let token = self.props.token.clone();

return html! {
<Page
Expand All @@ -200,6 +209,9 @@ impl Component for AppPage {
AppRoute::ApiKeys => html!{<pages::ApiKeys
backend=backend.clone()
/>},
AppRoute::CurrentToken => html!{<pages::CurrentToken
token=token.clone()
/>},

AppRoute::Examples(example) => html!{
<examples::ExamplePage example=example/>
Expand Down
2 changes: 2 additions & 0 deletions console-frontend/src/pages/mod.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
mod api_keys;
mod token;

pub use api_keys::*;
pub use token::*;
60 changes: 60 additions & 0 deletions console-frontend/src/pages/token.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
use crate::backend::Token;
use patternfly_yew::*;
use yew::prelude::*;

#[derive(Clone, PartialEq, Eq, Properties)]
pub struct Props {
pub token: Token,
}

pub struct CurrentToken {
props: Props,
}

impl Component for CurrentToken {
type Message = ();
type Properties = Props;

fn create(props: Self::Properties, _link: ComponentLink<Self>) -> Self {
Self { props }
}

fn update(&mut self, _msg: Self::Message) -> ShouldRender {
true
}

fn change(&mut self, props: Self::Properties) -> ShouldRender {
if self.props != props {
self.props = props;
true
} else {
false
}
}

fn view(&self) -> Html {
let token = self.props.token.refresh_token.as_deref().unwrap_or("");

return html! {
<>
<PageSection variant=PageSectionVariant::Light limit_width=true>
<Content>
<Title>{"Current API token"}</Title>
</Content>
</PageSection>
<PageSection>
<Card
title={html!{"Current API refresh token"}}
>
<Clipboard
readonly=true
code=true
variant=ClipboardVariant::Expandable
value=token>
</Clipboard>
</Card>
</PageSection>
</>
};
}
}

0 comments on commit 0c77aa3

Please sign in to comment.