new uptime monitors + half-completed create container deployment flow

This commit is contained in:
Nicholas Orlowsky 2023-01-17 01:06:38 -06:00
parent ddb20ee17c
commit 847d11c841
No known key found for this signature in database
GPG key ID: 3845F78A73B14100
16 changed files with 550 additions and 84 deletions

View file

@ -1,4 +1,4 @@
import {Blog, Incident, Service, SessionKey, UptimeResponse} from "./types";
import {Blog, Incident, Namespace, Service, SessionKey, UptimeResponse} from "./types";
export async function getUptime(): Promise<UptimeResponse> {
let response: Response = await fetch('https://api-nws.nickorlow.com/uptime');
@ -40,4 +40,12 @@ export async function getSessionKey(accountId: string, password: string): Promis
return sessionKey;
}
export async function getNamespaces(accountId: string, skey: SessionKey): Promise<Namespace[]> {
let response: Response = await fetch('https://api-nws.nickorlow.com/'+accountId+'/namespaces', {
headers: {
Authorization: skey.id
}
});
let namespaces: Namespace[] = await response.json();
return namespaces;
}

View file

@ -1,5 +1,5 @@
import {useEffect, useState} from "react";
import {Account, Service, SessionKey} from "./types";
import {Account, Namespace, Service, SessionKey} from "./types";
export function useNonLoggedInRedirect() {
useEffect(()=>{
@ -58,6 +58,72 @@ export function useGetAccountServices() {
return services;
}
export function useGetAccountNamespaces() {
const [namespaces, setNamespaces] = useState<Namespace[]>([]);
useEffect(() => {
let rawSession: string | null = localStorage.getItem("session_key");
if(rawSession != null) {
let session: SessionKey = JSON.parse(rawSession);
fetch("https://api-nws.nickorlow.com/Account/" + session.accountId + "/namespaces",
{
headers: {
"Authorization": btoa(session.accountId + ":" + session.id)
}
}).then((response)=>{
response.json().then((svcs: Namespace[]) => {
console.log(svcs)
setNamespaces(svcs);
});
});
}
}, []);
return namespaces;
}
export function useNWSAuthKey() {
const [key, setKey] = useState('');
useEffect(() => {
let rawSession: string | null = localStorage.getItem("session_key");
if(rawSession != null) {
let session: SessionKey = JSON.parse(rawSession);
setKey(btoa(session.accountId + ":" + session.id))
}
}, []);
return key;
}
export function useGetServicesInNamespace() {
const [services, setServices] = useState<Service[]>([]);
const [ns, setNs] = useState<Namespace | null>(null);
useEffect(() => {
console.log(ns !== null ? ns.id : "null")
if(ns === null) return;
let rawSession: string | null = localStorage.getItem("session_key");
if(rawSession != null) {
let session: SessionKey = JSON.parse(rawSession);
fetch("https://api-nws.nickorlow.com/Account/" + session.accountId + "/namespaces/" + ns.id + "/services",
{
headers: {
"Authorization": btoa(session.accountId + ":" + session.id)
}
}).then((response)=>{
response.json().then((svcs: Service[]) => {
console.log(svcs)
setServices(svcs);
});
});
}
}, [ns]);
return {setNs, services, ns};
}
export function useNWSAccount() {
const [accountInfo, setAccountInfo] = useState<Account>();
@ -87,4 +153,4 @@ export function useNWSAccount() {
}, []);
return accountInfo;
}
}

View file

@ -3,6 +3,9 @@ export type UptimeRecord = {
url: string,
uptimeMonth: number,
uptimeAllTime: number,
uptimeYtd: number,
averageResponseTime: number,
monitorStart: string,
isUp: boolean,
undergoingMaintenance: boolean
};
@ -10,6 +13,7 @@ export type UptimeRecord = {
export type UptimeResponse = {
datacenters: UptimeRecord[],
services: UptimeRecord[],
competitors: UptimeRecord[],
lastUpdated: string
};
@ -64,4 +68,8 @@ export type SessionKey = {
ip: string
};
export type Namespace = {
id: string,
accountId: string,
name: string
}