From 85fa678d74ca7e8c39303ca4e8eb2dfd352dc5cf Mon Sep 17 00:00:00 2001 From: Marlon Alkan Date: Mon, 20 May 2024 00:52:57 +0200 Subject: [PATCH 1/8] hyperglass: frontend: delete build dir before copying generated code to it fixes #244 --- hyperglass/frontend/__init__.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/hyperglass/frontend/__init__.py b/hyperglass/frontend/__init__.py index 508700ad..0f6c64c4 100644 --- a/hyperglass/frontend/__init__.py +++ b/hyperglass/frontend/__init__.py @@ -131,7 +131,8 @@ async def build_ui(app_path: Path): log.error(err) raise RuntimeError(str(err)) from err - shutil.copytree(src=out_dir, dst=build_dir, dirs_exist_ok=True) + shutil.rmtree(build_dir) + shutil.copytree(src=out_dir, dst=build_dir, dirs_exist_ok=False) log.bind(src=out_dir, dst=build_dir).debug("Migrated Next.JS build output") return "\n".join(all_messages) From ad88d025c2be64cc9e5a5a5f5c522b96597841ff Mon Sep 17 00:00:00 2001 From: thatmattlove Date: Fri, 31 May 2024 22:22:39 -0400 Subject: [PATCH 2/8] fix leftover issue from #247 if build_dir does not exist --- hyperglass/frontend/__init__.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/hyperglass/frontend/__init__.py b/hyperglass/frontend/__init__.py index 0f6c64c4..2a34a522 100644 --- a/hyperglass/frontend/__init__.py +++ b/hyperglass/frontend/__init__.py @@ -131,7 +131,10 @@ async def build_ui(app_path: Path): log.error(err) raise RuntimeError(str(err)) from err - shutil.rmtree(build_dir) + if build_dir.exists(): + shutil.rmtree(build_dir) + else: + build_dir.mkdir() shutil.copytree(src=out_dir, dst=build_dir, dirs_exist_ok=False) log.bind(src=out_dir, dst=build_dir).debug("Migrated Next.JS build output") From 4b6e6cba70d5bd2d749ec41dec7ca8730240cbfe Mon Sep 17 00:00:00 2001 From: thatmattlove Date: Fri, 31 May 2024 22:24:41 -0400 Subject: [PATCH 3/8] fix config value overwrite; closes #249 --- hyperglass/models/main.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/hyperglass/models/main.py b/hyperglass/models/main.py index 65b8670d..672dd2c0 100644 --- a/hyperglass/models/main.py +++ b/hyperglass/models/main.py @@ -62,7 +62,7 @@ def convert_paths(self, value: t.Type[PathTypeT]) -> PathTypeT: *(p for p in value.parts if p not in Settings.original_app_path.parts) ) - if isinstance(value, str): + if isinstance(value, str) and str(Settings.original_app_path) in value: if Settings.container: path = Path(value) return str( From c8a348ed0fe33d3736d8e42a5e8206368f2304c3 Mon Sep 17 00:00:00 2001 From: thatmattlove Date: Fri, 31 May 2024 22:56:26 -0400 Subject: [PATCH 4/8] fix invalid next.config.js options --- hyperglass/ui/next.config.js | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/hyperglass/ui/next.config.js b/hyperglass/ui/next.config.js index 8e953956..0c259b9a 100644 --- a/hyperglass/ui/next.config.js +++ b/hyperglass/ui/next.config.js @@ -9,11 +9,14 @@ const nextConfig = { }, swcMinify: true, productionBrowserSourceMaps: true, - output: 'export', }; +if (process.env.NODE_ENV === 'production') { + nextConfig.output = 'export'; +} + if (process.env.NODE_ENV === 'development') { - nextConfig.rewrites = [ + nextConfig.rewrites = async () => [ { source: '/api/query', destination: `${process.env.HYPERGLASS_URL}api/query` }, { source: '/images/:image*', destination: `${process.env.HYPERGLASS_URL}images/:image*` }, ]; From c79ba8b72779e88630fb69295aede11c35daeace Mon Sep 17 00:00:00 2001 From: thatmattlove Date: Fri, 31 May 2024 22:56:55 -0400 Subject: [PATCH 5/8] fix browser DNS resolution; closes #251 --- hyperglass/ui/components/looking-glass-form.tsx | 4 +++- hyperglass/ui/util/common.test.ts | 13 +++++-------- hyperglass/ui/util/common.ts | 5 ++++- 3 files changed, 12 insertions(+), 10 deletions(-) diff --git a/hyperglass/ui/components/looking-glass-form.tsx b/hyperglass/ui/components/looking-glass-form.tsx index fc879bef..664f8a81 100644 --- a/hyperglass/ui/components/looking-glass-form.tsx +++ b/hyperglass/ui/components/looking-glass-form.tsx @@ -72,7 +72,9 @@ export const LookingGlassForm = (): JSX.Element => { const isFqdnQuery = useCallback( (target: string | string[], fieldType: Directive['fieldType'] | null): boolean => - typeof target === 'string' && fieldType === 'text' && isFQDN(target), + (typeof target === 'string' || Array.isArray(target)) && + fieldType === 'text' && + isFQDN(target), [], ); diff --git a/hyperglass/ui/util/common.test.ts b/hyperglass/ui/util/common.test.ts index fc041cd5..2ca4e124 100644 --- a/hyperglass/ui/util/common.test.ts +++ b/hyperglass/ui/util/common.test.ts @@ -1,5 +1,5 @@ -import { expect, describe, it, test } from 'vitest'; -import { all, chunkArray, entries, dedupObjectArray, andJoin, isFQDN } from './common'; +import { describe, expect, it, test } from 'vitest'; +import { all, andJoin, chunkArray, dedupObjectArray, entries, isFQDN } from './common'; test('all - all items are truthy', () => { // biome-ignore lint/suspicious/noSelfCompare: because this is a test, duh @@ -79,12 +79,6 @@ describe('andJoin - join array of strings to sentence structure', () => { }); describe('isFQDN - determine if a string is an FQDN pattern', () => { - it('is null and should be false', () => { - expect(isFQDN(null)).toBe(false); - }); - it('is undefined and should be false', () => { - expect(isFQDN(undefined)).toBe(false); - }); it("isn't an FQDN and should be false", () => { expect(isFQDN('example')).toBe(false); }); @@ -100,4 +94,7 @@ describe('isFQDN - determine if a string is an FQDN pattern', () => { it('is a longer FQDN and should be true', () => { expect(isFQDN('one.two.three.four.five.example.com')).toBe(true); }); + it('is an array of FQDNs and should be true', () => { + expect(isFQDN(['www.example.com'])).toBe(true); + }); }); diff --git a/hyperglass/ui/util/common.ts b/hyperglass/ui/util/common.ts index fc8d45ae..0bbec3bb 100644 --- a/hyperglass/ui/util/common.ts +++ b/hyperglass/ui/util/common.ts @@ -130,7 +130,7 @@ export function andJoin(values: string[], options?: AndJoinOptions): string { * * @param value Input value. */ -export function isFQDN(value: unknown): value is string { +export function isFQDN(value: string | string[]): value is string { /** * Don't set the global flag on this. * @see https://stackoverflow.com/questions/24084926/javascript-regexp-cant-use-twice @@ -142,5 +142,8 @@ export function isFQDN(value: unknown): value is string { const pattern = new RegExp( /^(?!:\/\/)([a-zA-Z0-9-]+\.)*[a-zA-Z0-9-][a-zA-Z0-9-]+\.[a-zA-Z-]{2,6}?$/im, ); + if (Array.isArray(value)) { + return isFQDN(value[0]); + } return typeof value === 'string' && pattern.test(value); } From 1d1dcd83192ca3883fd02b539dd746b10264be14 Mon Sep 17 00:00:00 2001 From: thatmattlove Date: Fri, 31 May 2024 23:00:51 -0400 Subject: [PATCH 6/8] fix logo width on mobile --- hyperglass/ui/components/header/title.tsx | 1 - 1 file changed, 1 deletion(-) diff --git a/hyperglass/ui/components/header/title.tsx b/hyperglass/ui/components/header/title.tsx index caabd56c..a4f10200 100644 --- a/hyperglass/ui/components/header/title.tsx +++ b/hyperglass/ui/components/header/title.tsx @@ -28,7 +28,6 @@ const MWrapper = (props: MWrapperProps): JSX.Element => { layout spacing={1} alignItems={formInteractive ? 'center' : 'flex-start'} - maxWidth="25%" {...props} /> ); From 35d9c26eff83d2cd4dab52039525f2f7b08b4986 Mon Sep 17 00:00:00 2001 From: thatmattlove Date: Fri, 31 May 2024 23:06:33 -0400 Subject: [PATCH 7/8] update version to 2.0.1 --- CHANGELOG.md | 8 ++++++++ hyperglass/constants.py | 2 +- hyperglass/ui/package.json | 2 +- pyproject.toml | 2 +- 4 files changed, 11 insertions(+), 3 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 783273fa..176c5667 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,6 +4,14 @@ All notable changes to this project will be documented in this file. The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). +## 2.0.1 - 2024-05-31 + +### Fixed +- [#244](https://github.com/thatmattlove/hyperglass/issues/244): Fix issue with UI build where UI build directory already existed and therefore could not be created. +- [#249](https://github.com/thatmattlove/hyperglass/issues/249): Fix issue where configuration values were improperly prepended with the `HYPERGLASS_APP_PATH` value. +- [#251](https://github.com/thatmattlove/hyperglass/issues/251): Fix issue where browser-based DNS resolution did not show, causing FQDN queries to fail due to validation. +- Fix issue where logo was improperly sized on small screens. + ## 2.0.0 - 2024-05-28 _v2.0.0 is a major release of hyperglass. Many things have changed, and it is likely best to redeploy hyperglass in a new environment to migrate to v2._ diff --git a/hyperglass/constants.py b/hyperglass/constants.py index 2a9fcd9f..c0907169 100644 --- a/hyperglass/constants.py +++ b/hyperglass/constants.py @@ -4,7 +4,7 @@ from datetime import datetime __name__ = "hyperglass" -__version__ = "2.0.0" +__version__ = "2.0.1" __author__ = "Matt Love" __copyright__ = f"Copyright {datetime.now().year} Matthew Love" __license__ = "BSD 3-Clause Clear License" diff --git a/hyperglass/ui/package.json b/hyperglass/ui/package.json index 18d6964c..087fb11b 100644 --- a/hyperglass/ui/package.json +++ b/hyperglass/ui/package.json @@ -1,5 +1,5 @@ { - "version": "2.0.0", + "version": "2.0.1", "name": "ui", "description": "UI for hyperglass, the modern network looking glass", "author": "Matt Love", diff --git a/pyproject.toml b/pyproject.toml index fd2d43e1..7dc0cd95 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,6 +1,6 @@ [project] name = "hyperglass" -version = "2.0.0" +version = "2.0.1" description = "hyperglass is the modern network looking glass that tries to make the internet better." authors = [ { name = "thatmattlove", email = "matt@hyperglass.dev" } From 7eb4f5ca93f2bf7a7d6f0fe52065c17a01ce3c0b Mon Sep 17 00:00:00 2001 From: thatmattlove Date: Fri, 31 May 2024 23:11:08 -0400 Subject: [PATCH 8/8] fix leftover issue from #247 if build_dir does not exist --- hyperglass/frontend/__init__.py | 2 -- 1 file changed, 2 deletions(-) diff --git a/hyperglass/frontend/__init__.py b/hyperglass/frontend/__init__.py index 2a34a522..d38cd6b2 100644 --- a/hyperglass/frontend/__init__.py +++ b/hyperglass/frontend/__init__.py @@ -133,8 +133,6 @@ async def build_ui(app_path: Path): if build_dir.exists(): shutil.rmtree(build_dir) - else: - build_dir.mkdir() shutil.copytree(src=out_dir, dst=build_dir, dirs_exist_ok=False) log.bind(src=out_dir, dst=build_dir).debug("Migrated Next.JS build output")