Skip to content

Commit

Permalink
Add feature flags for site and device apis
Browse files Browse the repository at this point in the history
Signed-off-by: Hiram Chirino <[email protected]>
  • Loading branch information
chirino committed Dec 15, 2023
1 parent 0290abd commit 092d2ee
Show file tree
Hide file tree
Showing 7 changed files with 106 additions and 57 deletions.
10 changes: 10 additions & 0 deletions deploy/nexodus/base/apiserver/deployment.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -205,6 +205,16 @@ spec:
name: nexodus-ca-key-pair
key: tls.key
optional: true
- name: NEXAPI_FFLAG_DEVICES
valueFrom:
configMapKeyRef:
name: apiserver
key: NEXAPI_FFLAG_DEVICES
- name: NEXAPI_FFLAG_SITES
valueFrom:
configMapKeyRef:
name: apiserver
key: NEXAPI_FFLAG_SITES

# CI deployment seems to fail when this is enabled
# readinessProbe:
Expand Down
2 changes: 2 additions & 0 deletions deploy/nexodus/base/apiserver/kustomization.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ configMapGenerator:
- NEXAPI_FETCH_MGR=redis
- NEXAPI_FETCH_MGR_TIMEOUT=2s
- NEXAPI_DEVICE_CACHE_SIZE=500
- NEXAPI_FFLAG_DEVICES=true
- NEXAPI_FFLAG_SITES=false
resources:
- service.yaml
- deployment.yaml
Expand Down
13 changes: 8 additions & 5 deletions deploy/nexodus/overlays/playground/kustomization.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -6,34 +6,37 @@ resources:
namespace: nexodus-playground
configMapGenerator:
- behavior: replace
name: auth-config
literals:
- hostname=auth.playground.nexodus.io
- frontend-url=https://playground.nexodus.io
name: auth-config
- behavior: replace
name: realm
files:
- files/nexodus.json
name: realm
- behavior: merge
name: apiproxy
literals:
- APIPROXY_API_URL=https://api.playground.nexodus.io
- APIPROXY_OIDC_URL=https://auth.playground.nexodus.io/realms/nexodus
- APIPROXY_API_DOMAIN=api.playground.nexodus.io
- APIPROXY_WEB_DOMAIN=playground.nexodus.io
- APIPROXY_WEB_ORIGINS=https://playground.nexodus.io
- ENVOY_COMP_LOG_LEVEL=upstream:info,http:info,router:info,jwt:info
name: apiproxy
- behavior: merge
name: apiserver
literals:
- NEXAPI_URL=https://api.playground.nexodus.io
- NEXAPI_OIDC_URL=https://auth.playground.nexodus.io/realms/nexodus
- NEXAPI_DOMAIN=api.playground.nexodus.io
- NEXAPI_REDIRECT_URL=https://playground.nexodus.io/#/login
- NEXAPI_ORIGINS=https://playground.nexodus.io
- NEXAPI_ENVIRONMENT=qa
- NEXAPI_FFLAG_SECURITY_GROUPS=true
- NEXAPI_FFLAG_SITES=true
- NEXAPI_FFLAG_DEVICES=false
- NEXAPI_FFLAG_DEVICES=true
- NEXAPI_FFLAG_SITES=false
- NEXAPI_DEBUG=0
name: apiserver
patches:

# Update the dns names for the certificates
Expand Down
12 changes: 11 additions & 1 deletion internal/handlers/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import (
"github.com/nexodus-io/nexodus/internal/signalbus"
"github.com/redis/go-redis/v9"
"net/http"
"os"
"strconv"

"github.com/nexodus-io/nexodus/internal/database"
Expand Down Expand Up @@ -73,8 +74,17 @@ func NewAPI(

fflags.RegisterEnvFlag("multi-organization", "NEXAPI_FFLAG_MULTI_ORGANIZATION", true)
fflags.RegisterEnvFlag("security-groups", "NEXAPI_FFLAG_SECURITY_GROUPS", true)
fflags.RegisterEnvFlag("devices-api", "NEXAPI_FFLAG_DEVICES", true)
fflags.RegisterEnvFlag("sites-api", "NEXAPI_FFLAG_SITES", false)
fflags.RegisterFlag("ca-api", func() bool {
return caKeyPair.Certificate != nil
sitesFlag, err := strconv.ParseBool(os.Getenv("NEXAPI_FFLAG_SITES"))
if err != nil || !sitesFlag {
return false
}
if caKeyPair.Certificate != nil {
return false
}
return true
})

ctx, span := tracer.Start(parent, "NewAPI")
Expand Down
45 changes: 5 additions & 40 deletions ui/src/App.tsx
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
import { Admin, CustomRoutes, Resource, fetchUtils } from "react-admin";
import { Admin, CustomRoutes, Resource } from "react-admin";
import { Route } from "react-router";

import simpleRestProvider from "ra-data-simple-rest";
import { goOidcAgentAuthProvider } from "./providers/AuthProvider";

// icons
import DeviceIcon from "@mui/icons-material/Devices";
import SiteIcon from "@mui/icons-material/BorderOuter";
Expand All @@ -14,14 +11,14 @@ import RegKeyIcon from "@mui/icons-material/Key";
import VPCIcon from "@mui/icons-material/Cloud";

// pages
import { UserShow, UserList } from "./pages/Users";
import { UserList, UserShow } from "./pages/Users";
import { DeviceEdit, DeviceList, DeviceShow } from "./pages/Devices";
import {
OrganizationCreate,
OrganizationList,
OrganizationShow,
OrganizationCreate,
} from "./pages/Organizations";
import { VPCList, VPCShow, VPCCreate } from "./pages/VPCs";
import { VPCCreate, VPCList, VPCShow } from "./pages/VPCs";
import Dashboard from "./pages/Dashboard";
import LoginPage from "./pages/Login";
import Layout from "./layout/Layout";
Expand All @@ -41,39 +38,7 @@ import {
RegKeyShow,
} from "./pages/RegKeys";
import { SiteEdit, SiteList, SiteShow } from "./pages/Sites";

const fetchJson = (url: string, options: any = {}) => {
// Includes the encrypted session cookie in requests to the API
options.credentials = "include";
// some of the PUT api calls should be converted to PATCH
if (options.method === "PUT") {
if (
url.startsWith(`${backend}/api/reg-keys/`) ||
url.startsWith(`${backend}/api/devices/`) ||
url.startsWith(`${backend}/api/security-groups/`) ||
url.startsWith(`${backend}/api/vpcs/`)
) {
options.method = "PATCH";
}
}
return fetchUtils.fetchJson(url, options);
};

const backend = `${window.location.protocol}//api.${window.location.host}`;
const authProvider = goOidcAgentAuthProvider(backend);
const baseDataProvider = simpleRestProvider(
`${backend}/api`,
fetchJson,
"X-Total-Count",
);
const dataProvider = {
...baseDataProvider,
getFlag: (name: string) => {
return fetchJson(`${backend}/api/fflags/${name}`).then(
(response) => response,
);
},
};
import { authProvider, dataProvider } from "./DataProvider";

const App = () => {
return (
Expand Down
40 changes: 40 additions & 0 deletions ui/src/DataProvider.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
import { goOidcAgentAuthProvider } from "./providers/AuthProvider";
import simpleRestProvider from "ra-data-simple-rest";
import { fetchUtils } from "react-admin";

const fetchJson = (url: string, options: any = {}) => {
// Includes the encrypted session cookie in requests to the API
options.credentials = "include";
// some of the PUT api calls should be converted to PATCH
if (options.method === "PUT") {
if (
url.startsWith(`${backend}/api/reg-keys/`) ||
url.startsWith(`${backend}/api/devices/`) ||
url.startsWith(`${backend}/api/security-groups/`) ||
url.startsWith(`${backend}/api/vpcs/`)
) {
options.method = "PATCH";
}
}
return fetchUtils.fetchJson(url, options);
};
const backend = `${window.location.protocol}//api.${window.location.host}`;
export const authProvider = goOidcAgentAuthProvider(backend);
const baseDataProvider = simpleRestProvider(
`${backend}/api`,
fetchJson,
"X-Total-Count",
);
export const dataProvider = {
...baseDataProvider,
getFlag: (name: string) => {
return fetchJson(`${backend}/api/fflags/${name}`).then(
(response) => response,
);
},
getFlags: async () => {
return (await fetchJson(`${backend}/api/fflags`)).json as {
[index: string]: boolean;
};
},
};
41 changes: 30 additions & 11 deletions ui/src/layout/Menus.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,21 @@ import InvitationIcon from "@mui/icons-material/Rsvp";
import { MenuProps } from "react-admin";
import RegKeyIcon from "@mui/icons-material/Key";
import VPCIcon from "@mui/icons-material/Cloud";
import { dataProvider } from "../DataProvider";
import { useEffect, useState } from "react";

export const CustomMenu = (props: MenuProps) => {
const [flags, setFlags] = useState({} as { [index: string]: boolean });
useEffect(() => {
(async () => {
try {
setFlags(await dataProvider.getFlags());
} catch (e) {
console.log(e);
}
})();
}, []);

return (
<Menu {...props}>
<DashboardMenuItem />
Expand All @@ -18,22 +31,28 @@ export const CustomMenu = (props: MenuProps) => {
leftIcon={<OrganizationIcon />}
/>
<MenuItemLink to="/vpcs" primaryText="VPCs" leftIcon={<VPCIcon />} />
<MenuItemLink
to="/devices"
primaryText="Devices"
leftIcon={<DeviceIcon />}
/>
<MenuItemLink to="/sites" primaryText="Sites" leftIcon={<SiteIcon />} />
{flags["devices-api"] && (
<MenuItemLink
to="/devices"
primaryText="Devices"
leftIcon={<DeviceIcon />}
/>
)}
{flags["sites-api"] && (
<MenuItemLink to="/sites" primaryText="Sites" leftIcon={<SiteIcon />} />
)}
<MenuItemLink
to="/invitations"
primaryText="Invitations"
leftIcon={<InvitationIcon />}
/>
<MenuItemLink
to="/_security-groups"
primaryText="Security Groups"
leftIcon={<SecurityIcon />}
/>
{flags["devices-api"] && (
<MenuItemLink
to="/_security-groups"
primaryText="Security Groups"
leftIcon={<SecurityIcon />}
/>
)}
<MenuItemLink
to="/reg-keys"
primaryText="Registration Keys"
Expand Down

0 comments on commit 092d2ee

Please sign in to comment.