Skip to content

Commit

Permalink
Allow backup/restore plugin to be enabled/disabled (#4818)
Browse files Browse the repository at this point in the history
  • Loading branch information
nwmac authored Dec 1, 2020
1 parent 4aec384 commit 968e3a9
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ <h1>Endpoints</h1>
[routerLink]="'/endpoints/new/'" matTooltip="Register Endpoint">
<mat-icon>add</mat-icon>
</button>
<button id="stratos-restore-backup" *appUserPermission="canRegisterEndpoint" mat-icon-button
<button id="stratos-restore-backup" *ngIf="canBackupRestore$ | async" mat-icon-button
[routerLink]="'/endpoints/backup-restore'" matTooltip="Backup/Restore Endpoints">
<mat-icon>settings_backup_restore</mat-icon>
</button>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,12 @@ import {
ViewContainerRef,
} from '@angular/core';
import { Store } from '@ngrx/store';
import { combineLatest, Subscription } from 'rxjs';
import { delay, first, map, tap } from 'rxjs/operators';
import { combineLatest, Observable, of, Subscription } from 'rxjs';
import { delay, first, map, switchMap, tap } from 'rxjs/operators';

import { RouterNav } from '../../../../../store/src/actions/router.actions';
import { EndpointOnlyAppState } from '../../../../../store/src/app-state';
import { selectSessionData } from '../../../../../store/src/reducers/auth.reducer';
import { selectDashboardState } from '../../../../../store/src/selectors/dashboard.selectors';
import { CustomizationService, CustomizationsMetadata } from '../../../core/customizations.types';
import { EndpointsService } from '../../../core/endpoints.service';
Expand All @@ -24,6 +25,7 @@ import {
StratosActionMetadata,
StratosActionType,
} from '../../../core/extension/extension-service';
import { CurrentUserPermissionsService } from '../../../core/permissions/current-user-permissions.service';
import { StratosCurrentUserPermissions } from '../../../core/permissions/stratos-user-permissions.checker';
import { safeUnsubscribe } from '../../../core/utils.service';
import { EndpointListHelper } from '../../../shared/components/list/list-types/endpoint/endpoint-list.helpers';
Expand All @@ -46,6 +48,8 @@ export class EndpointsPageComponent implements AfterViewInit, OnDestroy, OnInit
public canRegisterEndpoint = StratosCurrentUserPermissions.ENDPOINT_REGISTER;
private healthCheckTimeout: number;

public canBackupRestore$: Observable<boolean>;

@ViewChild('customNoEndpoints', { read: ViewContainerRef, static: true }) customNoEndpointsContainer;
customContentComponentRef: ComponentRef<any>;

Expand All @@ -62,7 +66,8 @@ export class EndpointsPageComponent implements AfterViewInit, OnDestroy, OnInit
private ngZone: NgZone,
private resolver: ComponentFactoryResolver,
private snackBarService: SnackBarService,
cs: CustomizationService
cs: CustomizationService,
currentUserPermissionsService: CurrentUserPermissionsService,
) {
this.customizations = cs.get();

Expand All @@ -81,6 +86,13 @@ export class EndpointsPageComponent implements AfterViewInit, OnDestroy, OnInit
}),
first()
).subscribe();

// Is the backup/restore plugin available on the backend?
this.canBackupRestore$ = this.store.select(selectSessionData()).pipe(
first(),
map(sessionData => sessionData?.plugins.backup),
switchMap(enabled => enabled ? currentUserPermissionsService.can(this.canRegisterEndpoint) : of(false))
);
}

subs: Subscription[] = [];
Expand Down
3 changes: 3 additions & 0 deletions src/jetstream/config.example
Original file line number Diff line number Diff line change
Expand Up @@ -80,3 +80,6 @@ INVITE_USER_CLIENT_SECRET=

# Enabled Artifact Hub
# ARTIFACT_HUB_DISABLED=false

# Allow backup/restore feature?
#FEATURE_ALLOW_BACKUP=false
8 changes: 7 additions & 1 deletion src/jetstream/plugins/backup/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"database/sql"
"errors"
"net/http"
"strconv"

goosedbversion "github.com/cloudfoundry-incubator/stratos/src/jetstream/repository/goose-db-version"
"github.com/cloudfoundry-incubator/stratos/src/jetstream/repository/interfaces"
Expand All @@ -21,7 +22,7 @@ type BackupRestore struct {
portalProxy interfaces.PortalProxy
}

// Init creates a new Autoscaler
// Init creates a new backup/restore plugin
func Init(portalProxy interfaces.PortalProxy) (interfaces.StratosPlugin, error) {
return &BackupRestore{portalProxy: portalProxy}, nil
}
Expand Down Expand Up @@ -54,6 +55,11 @@ func (br *BackupRestore) AddSessionGroupRoutes(echoGroup *echo.Group) {

// Init performs plugin initialization
func (br *BackupRestore) Init() error {
enabledStr := br.portalProxy.Env().String("FEATURE_ALLOW_BACKUP", "true")
if enabled, err := strconv.ParseBool(enabledStr); err == nil && !enabled {
return errors.New("Backup/restoure feature disabled via configuration")
}

return nil
}

Expand Down

0 comments on commit 968e3a9

Please sign in to comment.