Add ability to create self-hosted go-neb instances

They can't be provisioned or configured correctly yet, but they exist.
This commit is contained in:
Travis Ralston 2018-01-31 16:30:08 -07:00
parent 1ae69bc563
commit 74054c3962
12 changed files with 95 additions and 10 deletions

View File

@ -44,6 +44,11 @@ export class DimensionAppserviceAdminService {
@POST
@Path("new")
public createAppservice(@QueryParam("scalar_token") scalarToken: string, request: AppserviceCreateRequest): Promise<AppserviceResponse> {
// Trim off the @ sign if it's on the prefix
if (request.userPrefix[0] === "@") {
request.userPrefix = request.userPrefix.substring(1);
}
return DimensionAdminService.validateAndGetAdminTokenOwner(scalarToken).then(_userId => {
return AppserviceStore.getAllByUserPrefix(request.userPrefix);
}).then(appservices => {

View File

@ -0,0 +1,24 @@
<my-ibox title="New self-hosted go-neb">
<div class="my-ibox-content">
<p>Self-hosted go-neb instances are powered by application services installed on your homeserver. The application service is responsible for creating the bots dynamically.</p>
<label class="label-block">
User Prefix
<span class="text-muted ">This is the prefix used for all bot users.</span>
<input type="text" class="form-control"
placeholder="@_neb"
[(ngModel)]="userPrefix" [disabled]="isSaving"/>
</label>
<label class="label-block">
API URL
<span class="text-muted ">The admin/api url for go-neb. Be sure to not expose the admin API to the outside world because this endpoint is not authenticated.</span>
<input type="text" class="form-control"
placeholder="http://localhost:4050"
[(ngModel)]="adminUrl" [disabled]="isSaving"/>
</label>
<button type="button" (click)="save()" title="save" class="btn btn-primary btn-sm" [disabled]="isSaving">
<i class="far fa-save"></i> Save
</button>
</div>
</my-ibox>

View File

@ -0,0 +1,38 @@
import { Component } from "@angular/core";
import { AdminAppserviceApiService } from "../../../shared/services/admin/admin-appservice-api.service";
import { AdminNebApiService } from "../../../shared/services/admin/admin-neb-api.service";
import { ToasterService } from "angular2-toaster";
import { ActivatedRoute, Router } from "@angular/router";
@Component({
templateUrl: "./add_selfhosted.component.html",
styleUrls: ["./add_selfhosted.component.scss"],
})
export class AdminAddSelfhostedNebComponent {
public isSaving = false;
public userPrefix = "@_neb";
public adminUrl = "http://localhost:4050";
constructor(private asApi: AdminAppserviceApiService,
private nebApi: AdminNebApiService,
private toaster: ToasterService,
private router: Router,
private activatedRoute: ActivatedRoute) {
}
public save(): void {
this.isSaving = true;
this.asApi.createAppservice(this.userPrefix).then(appservice => {
return this.nebApi.newAppserviceConfiguration(this.adminUrl, appservice);
}).then(() => {
this.toaster.pop("success", "New go-neb created");
this.router.navigate(["../.."], {relativeTo: this.activatedRoute});
}).catch(err => {
console.error(err);
this.isSaving = false;
this.toaster.pop("error", "Error creating appservice");
});
}
}

View File

@ -19,8 +19,8 @@ export class AdminEditNebComponent implements OnInit, OnDestroy {
public nebConfig: FE_NebConfiguration;
private subscription: any;
private overlappingTypes: string[];
private botTypes: string[];
private overlappingTypes: string[] = [];
private botTypes: string[] = [];
constructor(private nebApi: AdminNebApiService, private route: ActivatedRoute, private toaster: ToasterService) {
}

View File

@ -21,7 +21,10 @@
<td colspan="2"><i>No go-neb configurations.</i></td>
</tr>
<tr *ngFor="let neb of configurations trackById">
<td>{{ neb.upstreamId ? "matrix.org's go-neb" : "Self-hosted go-neb" }}</td>
<td>
{{ neb.upstreamId ? "matrix.org's go-neb" : "Self-hosted go-neb" }}
<span class="text-muted" style="display: inline-block;" *ngIf="!neb.upstreamId">({{ neb.adminUrl }})</span>
</td>
<td class="text-center">
<span class="appsvcConfigButton" (click)="showAppserviceConfig(neb)"
*ngIf="!neb.upstreamId">

View File

@ -4,6 +4,7 @@ import { AdminNebApiService } from "../../shared/services/admin/admin-neb-api.se
import { AdminUpstreamApiService } from "../../shared/services/admin/admin-upstream-api.service";
import { AdminAppserviceApiService } from "../../shared/services/admin/admin-appservice-api.service";
import { FE_Appservice, FE_NebConfiguration, FE_Upstream } from "../../shared/models/admin_responses";
import { ActivatedRoute, Router } from "@angular/router";
@Component({
templateUrl: "./neb.component.html",
@ -21,7 +22,9 @@ export class AdminNebComponent {
constructor(private nebApi: AdminNebApiService,
private upstreamApi: AdminUpstreamApiService,
private appserviceApi: AdminAppserviceApiService,
private toaster: ToasterService) {
private toaster: ToasterService,
private router: Router,
private activatedRoute:ActivatedRoute) {
this.reload().then(() => this.isLoading = false).catch(error => {
console.error(error);
@ -69,7 +72,7 @@ export class AdminNebComponent {
}
public addSelfHostedNeb() {
console.log("ADD Hosted");
this.router.navigate(["new", "selfhosted"], {relativeTo: this.activatedRoute});
}
public addModularHostedNeb() {

View File

@ -1,8 +1,3 @@
.text-muted {
display: block;
font-size: 12px;
}
.label-block {
margin-bottom: 15px;
}

View File

@ -52,6 +52,7 @@ import { AdminNebApiService } from "./shared/services/admin/admin-neb-api.servic
import { AdminUpstreamApiService } from "./shared/services/admin/admin-upstream-api.service";
import { AdminNebComponent } from "./admin/neb/neb.component";
import { AdminEditNebComponent } from "./admin/neb/edit/edit.component";
import { AdminAddSelfhostedNebComponent } from "./admin/neb/add_selfhosted/add_selfhosted.component";
@NgModule({
imports: [
@ -98,6 +99,7 @@ import { AdminEditNebComponent } from "./admin/neb/edit/edit.component";
AdminWidgetJitsiConfigComponent,
AdminNebComponent,
AdminEditNebComponent,
AdminAddSelfhostedNebComponent,
// Vendor
],

View File

@ -18,6 +18,7 @@ import { AdminHomeComponent } from "./admin/home/home.component";
import { AdminWidgetsComponent } from "./admin/widgets/widgets.component";
import { AdminNebComponent } from "./admin/neb/neb.component";
import { AdminEditNebComponent } from "./admin/neb/edit/edit.component";
import { AdminAddSelfhostedNebComponent } from "./admin/neb/add_selfhosted/add_selfhosted.component";
const routes: Routes = [
{path: "", component: HomeComponent},
@ -57,6 +58,11 @@ const routes: Routes = [
path: ":nebId/edit",
component: AdminEditNebComponent,
data: {breadcrumb: "Edit go-neb", name: "Edit go-neb"},
},
{
path: "new/selfhosted",
component: AdminAddSelfhostedNebComponent,
data: {breadcrumb: "Add self-hosted go-neb", name: "Add self-hosted go-neb"},
}
]
},

View File

@ -12,4 +12,8 @@ export class AdminAppserviceApiService extends AuthedApi {
public getAppservices(): Promise<FE_Appservice[]> {
return this.authedGet("/api/v1/dimension/admin/appservices/all").map(r => r.json()).toPromise();
}
public createAppservice(userPrefix: string): Promise<FE_Appservice> {
return this.authedPost("/api/v1/dimension/admin/appservices/new", {userPrefix: userPrefix}).map(r => r.json()).toPromise();
}
}

View File

@ -35,4 +35,9 @@ button {
.label-block {
display: block;
}
.text-muted {
display: block;
font-size: 12px;
}