Skip to content

Commit

Permalink
Begin adding origin key management
Browse files Browse the repository at this point in the history
* Make it so you can go to /origins/x to view that origin (doesn't check
  for existence or permissions yet)
* Very basic validation of key pasting (but you can't save yet)
* Remove some logic around "default origin" that's not being used
* Fix test runner to use correct loader

Signed-off-by: Nathan L Smith <[email protected]>

Pull request: #674
Approved by: reset
  • Loading branch information
Nathan L Smith authored and jtimberman committed Jun 12, 2016
1 parent ab3e7bc commit 95f535b
Show file tree
Hide file tree
Showing 13 changed files with 420 additions and 27 deletions.
6 changes: 6 additions & 0 deletions components/builder-web/app/AppComponent.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import {ExplorePageComponent} from "./explore-page/ExplorePageComponent";
import {HeaderComponent} from "./header/HeaderComponent";
import {NotificationsComponent} from "./notifications/NotificationsComponent";
import {OriginCreatePageComponent} from "./origin-create-page/OriginCreatePageComponent";
import {OriginPageComponent} from "./origin-page/OriginPageComponent";
import {OriginsPageComponent} from "./origins-page/OriginsPageComponent";
import {OrganizationCreatePageComponent} from "./organization-create-page/OrganizationCreatePageComponent";
import {OrganizationsPageComponent} from "./organizations-page/OrganizationsPageComponent";
Expand Down Expand Up @@ -77,6 +78,11 @@ import {authenticateWithGitHub, loadSessionState, removeNotification,
name: "OriginCreate",
component: OriginCreatePageComponent,
},
{
path: "/origins/:origin",
name: "Origin",
component: OriginPageComponent,
},
{
path: "/orgs",
name: "Organizations",
Expand Down
6 changes: 6 additions & 0 deletions components/builder-web/app/actions/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,10 @@ export const POPULATE_MY_ORIGINS = originActions.POPULATE_MY_ORIGINS;
export const SET_CURRENT_ORIGIN = originActions.SET_CURRENT_ORIGIN;
export const SET_CURRENT_ORIGIN_CREATING_FLAG =
originActions.SET_CURRENT_ORIGIN_CREATING_FLAG;
export const SET_ORIGIN_ADDING_PRIVATE_KEY =
originActions.SET_ORIGIN_ADDING_PRIVATE_KEY;
export const SET_ORIGIN_ADDING_PUBLIC_KEY =
originActions.SET_ORIGIN_ADDING_PUBLIC_KEY;
export const TOGGLE_ORIGIN_PICKER = originActions.TOGGLE_ORIGIN_PICKER;

export const CLEAR_PACKAGES = packageActions.CLEAR_PACKAGES;
Expand Down Expand Up @@ -100,6 +104,8 @@ export const deleteOrigin = originActions.deleteOrigin;
export const fetchMyOrigins = originActions.fetchMyOrigins;
export const toggleOriginPicker = originActions.toggleOriginPicker;
export const setCurrentOrigin = originActions.setCurrentOrigin;
export const setOriginAddingPrivateKey = originActions.setOriginAddingPrivateKey;
export const setOriginAddingPublicKey = originActions.setOriginAddingPublicKey;

export const fetchExplore = packageActions.fetchExplore;
export const fetchPackage = packageActions.fetchPackage;
Expand Down
16 changes: 16 additions & 0 deletions components/builder-web/app/actions/origins.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ export const POPULATE_MY_ORIGINS = "POPULATE_MY_ORIGINS";
export const SET_CURRENT_ORIGIN = "SET_CURRENT_ORIGIN";
export const SET_CURRENT_ORIGIN_CREATING_FLAG =
"SET_CURRENT_ORIGIN_CREATING_FLAG";
export const SET_ORIGIN_ADDING_PRIVATE_KEY = "SET_ORIGIN_ADDING_PRIVATE_KEY";
export const SET_ORIGIN_ADDING_PUBLIC_KEY = "SET_ORIGIN_ADDING_PUBLIC_KEY";
export const TOGGLE_ORIGIN_PICKER = "TOGGLE_ORIGIN_PICKER";

export function createOrigin(origin, token, isFirstOrigin = false) {
Expand Down Expand Up @@ -93,6 +95,20 @@ function setCurrentOriginCreatingFlag(payload) {
};
}

export function setOriginAddingPrivateKey(payload: boolean) {
return {
type: SET_ORIGIN_ADDING_PRIVATE_KEY,
payload,
};
}

export function setOriginAddingPublicKey(payload: boolean) {
return {
type: SET_ORIGIN_ADDING_PUBLIC_KEY,
payload,
};
}

export function toggleOriginPicker() {
return {
type: TOGGLE_ORIGIN_PICKER,
Expand Down
1 change: 1 addition & 0 deletions components/builder-web/app/app.scss
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
@import "header/user-nav/user-nav";
@import "notifications/notifications";
@import "origin-create-page/origin-create-page";
@import "origin-page/origin-page";
@import "organization-create-page/organization-create-page";
@import "organization-members/organization-members";
@import "organizations-page/organizations-page";
Expand Down
6 changes: 6 additions & 0 deletions components/builder-web/app/initialState.ts
Original file line number Diff line number Diff line change
Expand Up @@ -73,11 +73,17 @@ export default Record({
origins: Record({
current: Record({
name: "smith",
privateKeys: List(),
publicKeys: List(),
})(),
mine: List(),
ui: Record({
current: Record({
addingPublicKey: false,
addingPrivateKey: false,
creating: false,
exists: false,
loading: true,
})(),
})(),
})(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,6 @@ import {requireSignIn} from "../util";
<div class="page-title">
<h2>Add Origin</h2>
<p>An origin represents the organization creating the artifact.</p>
<p *ngIf="isFirstOrigin">
This will be your default origin although you may be a member of
many organizations each maintaining its own set of project
origins.
</p>
</div>
<form class="page-body hab-origin-create--form"
[ngFormModel]="form"
Expand All @@ -49,24 +44,6 @@ import {requireSignIn} from "../util";
name="name"
[value]="isFirstOrigin ? username : ''">
</hab-checking-input>
<div class="hab-origin-create--checkbox">
<input [disabled]="isFirstOrigin"
id="setAsDefault"
ngControl="default"
type="checkbox">
<label class="hab-origin-create--checkbox--label"
for="setAsDefault">
Set as default origin
</label>
</div>
<p><small>
This will be the origin that is used by default by the
web application. You can change it later.
</small></p>
<p *ngIf="isFirstOrigin"><small>
Since this is the first origin you're creating, it will be
set to default automatically.
</small></p>
<button [disabled]="!form.valid || creating">
<span *ngIf="creating">Saving&hellip;</span>
<span *ngIf="!creating">Save & Continue</span>
Expand All @@ -82,9 +59,7 @@ export class OriginCreatePageComponent implements AfterViewInit, OnInit {
private pattern = "^[a-z0-9\-_]+$";

constructor(private formBuilder: FormBuilder, private store: AppStore) {
this.form = formBuilder.group({
default: new Control(this.isFirstOrigin),
});
this.form = formBuilder.group({});
}

get creating() { return this.store.getState().origins.ui.current.creating; }
Expand Down
103 changes: 103 additions & 0 deletions components/builder-web/app/origin-page/KeyAddFormComponent.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,103 @@
// Copyright:: Copyright (c) 2016 The Habitat Maintainers
//
// The terms of the Evaluation Agreement (Habitat) between Chef Software Inc.
// and the party accessing this file ("Licensee") apply to Licensee's use of
// the Software until such time that the Software is made available under an
// open source license such as the Apache 2.0 License.

import {Component, Input, OnInit} from "angular2/core";
import {Control, ControlGroup, FormBuilder, Validators} from "angular2/common";
import {parseKey} from "../util";

@Component({
selector: "hab-key-add-form",
template: `
<form class="hab-key-add-form" [ngFormModel]="form" #formValues="ngForm">
<a class="hab-key-add-form--close" href="#" (click)="onCloseClick()">
Close
</a>
<label class="hab-key-add-form--label" for="key">Key</label>
<small>
Paste your key here. Check the documentation for a guide on
<a href="{{docsUrl}}/concepts-keys/">
generating keys</a>.
</small>
<textarea
autofocus
name="key"
[ngFormControl]="form.controls['key']"
placeholder="Begins with '{{keyFileHeaderPrefix}}'"
rows=6></textarea>
<div class="hab-key-add-form--submit">
<button class="hab-key-add-form--save" [disabled]="!form.valid">
Save Key
</button>
<div *ngIf="control.dirty && control.errors" class="hab-key-add-form--errors">
<span *ngIf="control.errors.required">
A value is required.
</span>
<span *ngIf="control.errors.invalidFormat">
This is not a valid key format.
</span>
<span *ngIf="control.errors.invalidType">
Key must begin with '{{keyFileHeaderPrefix}}'.
</span>
<span *ngIf="control.errors.invalidOrigin">
Key origin must match '{{originName}}'.
</span>
</div>
</div>
</form>`,
})

export class KeyAddFormComponent implements OnInit {
@Input() docsUrl: String;
@Input() keyFileHeaderPrefix: String;
@Input() onCloseClick: Function;
@Input() originName: String;

private form: ControlGroup;
private control: Control;

constructor(private formBuilder: FormBuilder) {
this.form = formBuilder.group({});
}

private keyFormatValidator(control) {
if (parseKey(control.value).valid) {
return null;
} else {
return { invalidFormat: true };
}
}

private keyTypeValidator(control) {
if (parseKey(control.value).type === this.keyFileHeaderPrefix) {
return null;
} else {
return { invalidType: true };
}
}

private originMatchValidator(control) {
if (parseKey(control.value).origin === this.originName) {
return null;
} else {
return { invalidOrigin: true };
}
}

public ngOnInit() {
this.control = new Control(
"",
Validators.compose([
Validators.required,
this.keyFormatValidator,
this.keyTypeValidator.bind(this),
this.originMatchValidator.bind(this),
])
);

this.form.addControl("key", this.control);
}
}
Loading

0 comments on commit 95f535b

Please sign in to comment.