Skip to content

Commit 25aece9

Browse files
committed
first commit
1 parent 56fb8fc commit 25aece9

33 files changed

Lines changed: 506 additions & 22 deletions

.ember-cli

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
rather than JavaScript by default, when a TypeScript version of a given blueprint is available.
55
*/
66
"isTypeScriptProject": true,
7+
"output-path": "/Users/emoncuso/hashicorp/vault-ui",
78

89
/**
910
Setting `componentAuthoringFormat` to "strict" will force the blueprint generators to generate GJS

app/authenticators/token.ts

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
import { service } from '@ember/service';
2+
import Base from 'ember-simple-auth/authenticators/base';
3+
import type ApiService from 'fresh-vault/services/api';
4+
5+
type AuthenticateParams = { token: string, path: string };
6+
7+
export default class TokenAuthenticator extends Base {
8+
@service declare readonly api: ApiService;
9+
10+
restore(data: unknown) {
11+
return Promise.resolve(data);
12+
}
13+
14+
async authenticate({ path, token }: AuthenticateParams) {
15+
console.log({ path, token });
16+
17+
const res = await this.api.auth.lookupSelf({ token });
18+
console.log(res)
19+
return Promise.resolve({
20+
token,
21+
22+
});
23+
}
24+
25+
invalidate(data: unknown) {
26+
return Promise.resolve(data);
27+
}
28+
}

app/components/pages/login.hbs

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
<h1> Login </h1>
2+
3+
<form method="POST" {{on "submit" this.login.perform}}>
4+
<div>
5+
<label for="path">Path</label>
6+
<input
7+
id="path"
8+
name="path"
9+
type="text"
10+
value="/"
11+
readonly
12+
autocomplete="off"
13+
/>
14+
</div>
15+
<div>
16+
<label for="token">Token</label>
17+
<input
18+
id="token"
19+
name="token"
20+
type="text"
21+
required
22+
aria-required="true"
23+
autocomplete="off"
24+
/>
25+
</div>
26+
<button type="submit">
27+
Login
28+
</button>
29+
</form>

app/components/pages/login.ts

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
import { service } from '@ember/service';
2+
import Component from '@glimmer/component';
3+
4+
import { task } from 'ember-concurrency';
5+
import type SessionService from 'fresh-vault/services/session';
6+
7+
export interface PagesLoginSignature {
8+
// The arguments accepted by the component
9+
Args: {};
10+
// Any blocks yielded by the component
11+
Blocks: {
12+
default: []
13+
};
14+
// The element to which `...attributes` is applied in the component template
15+
Element: null;
16+
}
17+
18+
export default class PagesLogin extends Component<PagesLoginSignature> {
19+
@service declare readonly session: SessionService;
20+
21+
login = task({ drop: true }, async (e: unknown) => {
22+
e.preventDefault();
23+
24+
const fd = new FormData(e.target);
25+
26+
const path = fd.get('path');
27+
const token = fd.get('token');
28+
29+
this.session.authenticate('authenticator:token', { path, token });
30+
});
31+
}

app/components/pages/overview.hbs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
<h1> Overview </h1>
2+
3+
<button {{on "click" this.logout}}>
4+
Logout
5+
</button>
6+
7+
<p>Hey I'm a random web app connecting to Vault!</p>
8+
<p>Vault server version is: <strong>{{this.backendVersion}}</strong></p>

app/components/pages/overview.ts

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
import { service } from '@ember/service';
2+
import Component from '@glimmer/component';
3+
import type ClusterService from 'fresh-vault/services/cluster';
4+
import type SessionService from 'fresh-vault/services/session';
5+
6+
export interface PagesOverviewSignature {
7+
// The arguments accepted by the component
8+
Args: {};
9+
// Any blocks yielded by the component
10+
Blocks: {
11+
default: []
12+
};
13+
// The element to which `...attributes` is applied in the component template
14+
Element: null;
15+
}
16+
17+
export default class PagesOverview extends Component<PagesOverviewSignature> {
18+
@service declare readonly cluster: ClusterService;
19+
@service declare readonly session: SessionService;
20+
21+
// get isDr() {
22+
// return
23+
// }
24+
25+
// get isPr() {
26+
27+
// }
28+
29+
// get isSecondary() {
30+
31+
// }
32+
33+
get backendVersion() {
34+
return this.cluster.health.version;
35+
}
36+
37+
logout = async () => {
38+
this.session.invalidate();
39+
}
40+
}

app/router.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,5 +7,8 @@ export default class Router extends EmberRouter {
77
}
88

99
Router.map(function () {
10-
// Add route declarations here
10+
this.route('login');
11+
this.route('authenticated', { path: '/' }, function () {
12+
this.route('overview', { path: '/' });
13+
});
1114
});

app/routes/application.ts

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
import Route from '@ember/routing/route';
2+
import { service } from '@ember/service';
3+
import type ApiService from 'fresh-vault/services/api';
4+
import type ClusterService from 'fresh-vault/services/cluster';
5+
import type SessionService from 'fresh-vault/services/session';
6+
7+
export default class ApplicationRoute extends Route {
8+
@service declare readonly api: ApiService;
9+
@service declare readonly cluster: ClusterService;
10+
@service declare readonly session: SessionService;
11+
12+
beforeModel() {
13+
this.session.setup();
14+
}
15+
16+
async model() {
17+
const [
18+
health,
19+
sealStatus
20+
] = await Promise.all([
21+
this.api.sys.health(),
22+
this.api.sys.sealStatus(),
23+
]);
24+
25+
console.log({ health, sealStatus });
26+
27+
return {
28+
health,
29+
sealStatus
30+
}
31+
}
32+
33+
afterModel(model: unknown) {
34+
this.cluster.health = model.health;
35+
this.cluster.sealStatus = model.sealStatus;
36+
}
37+
}

app/routes/authenticated.ts

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
import Route from '@ember/routing/route';
2+
import { service } from '@ember/service';
3+
4+
import type SessionService from 'fresh-vault/services/session';
5+
import type Transition from '@ember/routing/transition';
6+
7+
export default class AuthenticatedRoute extends Route {
8+
@service declare readonly session: SessionService;
9+
beforeModel(transition: Transition) {
10+
this.session.requireAuthentication(transition, 'login');
11+
}
12+
}
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
import Route from '@ember/routing/route';
2+
import { tracked } from '@glimmer/tracking';
3+
4+
export default class AuthenticatedOverviewRoute extends Route {
5+
@tracked health = {}
6+
@tracked sealStatus = {}
7+
}

0 commit comments

Comments
 (0)