handle unuath response from patchdb ws, clean up old files, better setting of auth state

This commit is contained in:
Matt Hill
2021-10-06 13:15:51 -06:00
committed by Aiden McClelland
parent 446da8fd81
commit c3037d6251
12 changed files with 41 additions and 262 deletions

View File

@@ -1,41 +0,0 @@
#!/bin/bash
set -e
echo "turn off mocks"
echo "$( jq '.useMocks = false' use-mocks.json )" > use-mocks.json
echo "$( jq '.skipStartupAlerts = false' use-mocks.json )" > use-mocks.json
echo "FILTER: rm -rf www"
rm -rf www
echo "FILTER: ionic build"
npm run build-prod
echo "FILTER: cp client-manifest.yaml www"
cp client-manifest.yaml www
echo "FILTER: git hash"
touch git-hash.txt
git log | head -n1 > git-hash.txt
mv git-hash.txt www
echo "FILTER: removing mock icons"
rm -rf www/assets/img/service-icons
echo "FILTER: tar -zcvf ambassador-ui.tar.gz www"
tar -zcvf ambassador-ui.tar.gz www
SHA_SUM=$(sha1sum ambassador-ui.tar.gz)
echo "${SHA_SUM}"
echo "Set version"
VERSION=$(jq ".version" package.json)
echo "${VERSION}"
echo "FILTER: mkdir alpha-reg"
ssh root@alpha-registry.start9labs.com "mkdir -p /var/www/html/resources/sys/ambassador-ui.tar.gz/${VERSION}"
echo "FILTER: scp ambassador-ui.tar.gz"
scp ambassador-ui.tar.gz root@alpha-registry.start9labs.com:/var/www/html/resources/sys/ambassador-ui.tar.gz/${VERSION}/ambassador-ui.tar.gz
echo "FILTER: fin"

View File

@@ -1,41 +0,0 @@
#!/bin/bash
set -e
echo "turn off mocks"
echo "$( jq '.useMocks = false' use-mocks.json )" > use-mocks.json
echo "$( jq '.skipStartupAlerts = false' use-mocks.json )" > use-mocks.json
echo "FILTER: rm -rf www"
rm -rf www
echo "FILTER: ionic build"
npm run build-prod
echo "FILTER: cp client-manifest.yaml www"
cp client-manifest.yaml www
echo "FILTER: git hash"
touch git-hash.txt
git log | head -n1 > git-hash.txt
mv git-hash.txt www
echo "FILTER: removing mock icons"
rm -rf www/assets/img/service-icons
echo "FILTER: tar -zcvf ambassador-ui.tar.gz www"
tar -zcvf ambassador-ui.tar.gz www
SHA_SUM=$(sha1sum ambassador-ui.tar.gz)
echo "${SHA_SUM}"
echo "Set version"
VERSION=$(jq ".version" package.json)
echo "${VERSION}"
echo "FILTER: mkdir beta-reg"
ssh root@beta-registry.start9labs.com "mkdir -p /var/www/html/resources/sys/ambassador-ui.tar.gz/${VERSION}"
echo "FILTER: scp ambassador-ui.tar.gz"
scp ambassador-ui.tar.gz root@beta-registry.start9labs.com:/var/www/html/resources/sys/ambassador-ui.tar.gz/${VERSION}/ambassador-ui.tar.gz
echo "FILTER: fin"

View File

@@ -1,30 +0,0 @@
#!/bin/bash
set -e
#echo "turn off mocks"
#echo "$( jq '.useMocks = false' use-mocks.json )" > use-mocks.json
echo "FILTER: rm -rf www"
rm -rf www
echo "FILTER: ionic build"
npm run build-prod
echo "FILTER: ssh + rm -rf /var/www/html/start9-ambassador/"
ssh root@start9-$1.local "rm -rf /var/www/html/start9-ambassador"
echo "FILTER: tar -zcvf ambassador.tar.gz www"
rm -rf start9-ambassador
mv www start9-ambassador
tar -zcvf ambassador.tar.gz start9-ambassador
echo "FILTER: scp ambassador.tar.gz root@start9-def09913.local:/root"
scp ambassador.tar.gz root@start9-$1.local:/root/agent
echo "FILTER: ssh root@start9-$1.local:/root 1"
ssh root@start9-$1.local "cd /root/agent && tar -C /var/www/html/ -xvf ambassador.tar.gz"
echo "FILTER: ssh root@start9-$1.local:/root 2"
ssh root@start9-$1.local "systemctl restart nginx"
echo "FILTER: fin"

View File

@@ -1,117 +0,0 @@
manifest-version: 0
app-id: start9-ambassador
app-version: 0.2.17
uri-rewrites:
- =/api -> http://{{start9-ambassador}}:5959/authenticate
- /api/ -> http://{{start9-ambassador}}:5959/
main-is: index.html
error-pages:
404: index.html
mime-types:
wasm: application/wasm
bin: application/octet-stream
json: application/json
html: text/html
htm: text/html
shtml: text/html
css: text/css
xml: text/xml
gif: image/gif
jpeg: image/jpeg
jpg: image/jpeg
js: application/javascript
atom: application/atom+xml
rss: application/rss+xml
mml: text/mathml
txt: text/plain
jad: text/vnd.sun.j2me.app-descriptor
wml: text/vnd.wap.wml
htc: text/x-component
png: image/png
tif: image/tiff
tiff: image/tiff
wbmp: image/vnd.wap.wbmp
ico: image/x-icon
jng: image/x-jng
bmp: image/x-ms-bmp
svg: image/svg+xml
svgz: image/svg+xml
webp: image/webp
woff: application/font-woff
jar: application/java-archive
war: application/java-archive
ear: application/java-archive
json: application/json
hqx: application/mac-binhex40
doc: application/msword
pdf: application/pdf
ps: application/postscript
eps: application/postscript
ai: application/postscript
rtf: application/rtf
m3u8: application/vnd.apple.mpegur
xls: application/vnd.ms-exce
eot: application/vnd.ms-fontobjec
ppt: application/vnd.ms-powerpoin
wmlc: application/vnd.wap.wml
kml: application/vnd.google-earth.kml+xm
kmz: application/vnd.google-earth.km
7z: application/x-7z-compresse
cco: application/x-cocoa
jardiff: application/x-java-archive-diff
jnlp: application/x-java-jnlp-file
run: application/x-makesel
pl: application/x-perl
pm: application/x-perl
prc: application/x-pilot
pdb: application/x-pilot
rar: application/x-rar-compressed
rpm: application/x-redhat-package-manager
sea: application/x-sea
swf: application/x-shockwave-flash
sit: application/x-stuffit
tk: application/x-tcl
tcl: application/x-tcl
der: application/x-x509-ca-cert
pem: application/x-x509-ca-cert
crt: application/x-x509-ca-cert
xpi: application/x-xpinstall
xhtml: application/xhtml+xml
xspf: application/xspf+xml
zip: application/zip
bin: application/octet-stream
exe: application/octet-stream
dll: application/octet-stream
deb: application/octet-stream
dmg: application/octet-stream
iso: application/octet-stream
img: application/octet-stream
msi: application/octet-stream
msp: application/octet-stream
msm: application/octet-stream
docx: application/vnd.openxmlformats-officedocument.wordprocessingml.document
xlsx: application/vnd.openxmlformats-officedocument.spreadsheetml.sheet
pptx: application/vnd.openxmlformats-officedocument.presentationml.presentation
mid: audio/mid
kar: audio/mid
midi: audio/mid
mp3: audio/mpe
ogg: audio/og
m4a: audio/x-m4
ra: audio/x-realaudio
3gpp: video/3gp
3gp: video/3gp
ts: video/mp2
mp4: video/mp
mpeg: video/mpe
mpg: video/mpe
mov: video/quicktime
webm: video/web
flv: video/x-fl
m4v: video/x-m4
mng: video/x-mn
asx: video/x-ms-asf
asf: video/x-ms-asf
wmv: video/x-ms-wmv
avi: video/x-msvideo
mime-default: text/plain

View File

@@ -9,7 +9,6 @@ import { Emver } from './services/emver.service'
import { SplitPaneTracker } from './services/split-pane.service'
import { ToastButton } from '@ionic/core'
import { PatchDbService } from './services/patch-db/patch-db.service'
import { HttpService } from './services/http.service'
import { ServerStatus } from './services/patch-db/data-model'
import { ConnectionFailure, ConnectionService } from './services/connection.service'
import { StartupAlertsService } from './services/startup-alerts.service'
@@ -69,7 +68,6 @@ export class AppComponent {
private readonly authService: AuthService,
private readonly router: Router,
private readonly embassyApi: ApiService,
private readonly http: HttpService,
private readonly alertCtrl: AlertController,
private readonly emver: Emver,
private readonly connectionService: ConnectionService,
@@ -141,10 +139,6 @@ export class AppComponent {
this.router.navigate(['/login'], { replaceUrl: true })
}
})
this.http.watchUnauth$().subscribe(() => {
this.authService.setUnverified()
})
}
async goToWebsite (): Promise<void> {

View File

@@ -20,6 +20,7 @@ import { LocalStorageBootstrap } from './services/patch-db/local-storage-bootstr
import { SharingModule } from './modules/sharing.module'
import { FormBuilder } from '@angular/forms'
import { GenericInputComponentModule } from './modals/generic-input/generic-input.component.module'
import { AuthService } from './services/auth.service'
@NgModule({
declarations: [AppComponent],
@@ -46,8 +47,16 @@ import { GenericInputComponentModule } from './modals/generic-input/generic-inpu
IonNav,
Storage,
{ provide: RouteReuseStrategy, useClass: IonicRouteStrategy },
{ provide: ApiService , useFactory: ApiServiceFactory, deps: [ConfigService, HttpService] }, { provide: ApiService , useFactory: ApiServiceFactory, deps: [ConfigService, HttpService] },
{ provide: PatchDbService, useFactory: PatchDbServiceFactory, deps: [ConfigService, LocalStorageBootstrap, ApiService] },
{
provide: ApiService,
useFactory: ApiServiceFactory,
deps: [ConfigService, HttpService],
},
{
provide: PatchDbService,
useFactory: PatchDbServiceFactory,
deps: [ConfigService, ApiService, LocalStorageBootstrap, AuthService],
},
],
bootstrap: [AppComponent],
schemas: [ CUSTOM_ELEMENTS_SCHEMA ],

View File

@@ -1,6 +1,7 @@
import { Component } from '@angular/core'
import { LoadingController } from '@ionic/angular'
import { LoadingController, getPlatforms } from '@ionic/angular'
import { Subscription } from 'rxjs'
import { ApiService } from 'src/app/services/api/embassy-api.service'
import { AuthService } from 'src/app/services/auth.service'
@Component({
@@ -18,6 +19,7 @@ export class LoginPage {
constructor (
private readonly authService: AuthService,
private readonly loadingCtrl: LoadingController,
private readonly api: ApiService,
) { }
ngOnDestroy () {
@@ -45,7 +47,11 @@ export class LoginPage {
await this.loader.present()
try {
await this.authService.login(this.password)
await this.api.login({
password: this.password,
metadata: { platforms: getPlatforms() },
})
this.authService.setVerified()
this.password = ''
} catch (e) {
this.error = e.code === 34 ? 'Invalid Password' : e.message

View File

@@ -1,9 +1,7 @@
import { Injectable } from '@angular/core'
import { BehaviorSubject, Observable } from 'rxjs'
import { distinctUntilChanged } from 'rxjs/operators'
import { ApiService } from './api/embassy-api.service'
import { Storage } from '@ionic/storage-angular'
import { getPlatforms, isPlatform } from '@ionic/angular'
export enum AuthState {
UNVERIFIED,
@@ -18,7 +16,6 @@ export class AuthService {
private readonly authState$: BehaviorSubject<AuthState> = new BehaviorSubject(AuthState.INITIALIZING)
constructor (
private readonly embassyApi: ApiService,
private readonly storage: Storage,
) { }
@@ -31,11 +28,7 @@ export class AuthService {
return this.authState$.pipe(distinctUntilChanged())
}
async login (password: string): Promise<void> {
await this.embassyApi.login({
password,
metadata: { platforms: getPlatforms() },
})
async setVerified (): Promise<void> {
await this.storage.set(this.LOGGED_IN_KEY, true)
this.authState$.next(AuthState.VERIFIED)
}

View File

@@ -1,29 +1,26 @@
import { Injectable } from '@angular/core'
import { HttpClient, HttpErrorResponse, HttpHeaders, HttpParams } from '@angular/common/http'
import { Observable, from, interval, race, Subject } from 'rxjs'
import { Observable, from, interval, race } from 'rxjs'
import { map, take } from 'rxjs/operators'
import { ConfigService } from './config.service'
import { Revision } from 'patch-db-client'
import { AuthService } from './auth.service'
@Injectable({
providedIn: 'root',
})
export class HttpService {
private unauthorizedApiResponse$ = new Subject()
fullUrl: string
constructor (
private readonly http: HttpClient,
private readonly config: ConfigService,
private readonly auth: AuthService,
) {
const port = config.mocks.enabled ? this.config.mocks.rpcPort : window.location.port
this.fullUrl = `${window.location.protocol}//${window.location.hostname}:${port}`
}
watchUnauth$ (): Observable<{ }> {
return this.unauthorizedApiResponse$.asObservable()
}
async rpcRequest<T> (rpcOpts: RPCOptions): Promise<T> {
const { url, version } = this.config.api
rpcOpts.params = rpcOpts.params || { }
@@ -37,7 +34,7 @@ export class HttpService {
const res = await this.httpRequest<RPCResponse<T>>(httpOpts)
if (isRpcError(res)) {
if (res.error.code === 34) this.unauthorizedApiResponse$.next(true)
if (res.error.code === 34) this.auth.setUnverified()
throw new RpcError(res.error)
}

View File

@@ -4,11 +4,13 @@ import { DataModel } from './data-model'
import { LocalStorageBootstrap } from './local-storage-bootstrap'
import { PatchDbService } from './patch-db.service'
import { ApiService } from 'src/app/services/api/embassy-api.service'
import { AuthService } from '../auth.service'
export function PatchDbServiceFactory (
config: ConfigService,
bootstrapper: LocalStorageBootstrap,
embassyApi: ApiService,
bootstrapper: LocalStorageBootstrap,
auth: AuthService,
): PatchDbService {
const { mocks, patchDb: { poll }, supportsWebSockets } = config
@@ -31,5 +33,5 @@ export function PatchDbServiceFactory (
}
}
return new PatchDbService(source, embassyApi, bootstrapper)
return new PatchDbService(source, embassyApi, bootstrapper, auth)
}

View File

@@ -4,11 +4,13 @@ import { BehaviorSubject, Observable, of, Subscription } from 'rxjs'
import { catchError, debounceTime, finalize, map, tap } from 'rxjs/operators'
import { pauseFor } from 'src/app/util/misc.util'
import { ApiService } from '../api/embassy-api.service'
import { AuthService } from '../auth.service'
import { DataModel } from './data-model'
export const PATCH_HTTP = new InjectionToken<Source<DataModel>>('app.config')
export const PATCH_SOURCE = new InjectionToken<Source<DataModel>>('app.config')
export const BOOTSTRAPPER = new InjectionToken<Bootstrapper<DataModel>>('app.config')
export const PATCH_HTTP = new InjectionToken<Source<DataModel>>('')
export const PATCH_SOURCE = new InjectionToken<Source<DataModel>>('')
export const BOOTSTRAPPER = new InjectionToken<Bootstrapper<DataModel>>('')
export const AUTH = new InjectionToken<AuthService>('')
export enum PatchConnection {
Initializing = 'initializing',
@@ -31,6 +33,7 @@ export class PatchDbService {
@Inject(PATCH_SOURCE) private readonly source: Source<DataModel>,
@Inject(PATCH_HTTP) private readonly http: ApiService,
@Inject(BOOTSTRAPPER) private readonly bootstrapper: Bootstrapper<DataModel>,
@Inject(AUTH) private readonly auth: AuthService,
) { }
async init (): Promise<void> {
@@ -60,8 +63,12 @@ export class PatchDbService {
error: async e => {
console.error('patch-db SYNC ERROR', e)
this.patchConnection$.next(PatchConnection.Disconnected)
await pauseFor(4000)
this.start()
if (e.code === 34) {
this.auth.setUnverified()
} else {
await pauseFor(4000)
this.start()
}
},
complete: () => {
console.warn('patch-db SYNC COMPLETE')