diff --git a/Makefile b/Makefile index 6610da1..d684b59 100755 --- a/Makefile +++ b/Makefile @@ -43,7 +43,7 @@ COVER_PROFILE ?= cover.out COVER_EXCLUDE ?= (zz_generated) # Override the value of the version variable in main.go -LD_FLAGS= '-X opendev.org/airship/airshipui/internal/commands.version=$(GIT_VERSION)' +LD_FLAGS= '-X opendev.org/airship/airshipui/pkg/commands.version=$(GIT_VERSION)' GO_FLAGS := -ldflags=$(LD_FLAGS) BUILD_DIR := bin @@ -72,7 +72,7 @@ $(MAIN): FORCE @mkdir -p $(BUILD_DIR) cd $(WEBDIR) && (PATH="$(PATH):$(NODEJS_BIN)"; $(NPM) install) && cd .. cd $(WEBDIR) && (PATH="$(PATH):$(NODEJS_BIN)"; $(NG) build) && cd .. - go build -o $(MAIN)$(EXTENSION) $(GO_FLAGS) cmd/$(@F)/main.go + go build -o $(MAIN)$(EXTENSION) $(GO_FLAGS) cmd/main.go FORCE: @@ -180,10 +180,11 @@ lint: tidy $(LINTER) @./tools/whitespace_linter @echo "Running golangci-lint linting step..." $(LINTER) run --config $(LINTER_CONFIG) - @echo "Installing NPM & running client linting step..." - ./tools/install_npm - cd $(WEBDIR) && (PATH="$(PATH):$(NODEJS_BIN)"; $(NPM) install) && cd .. - cd $(WEBDIR) && (PATH="$(PATH):$(NODEJS_BIN)"; $(NG) build) && cd .. +# TODO: Replace eslint with TS lint +# @echo "Installing NPM & running client linting step..." +# ./tools/install_npm +# cd $(WEBDIR) && (PATH="$(PATH):$(NODEJS_BIN)"; $(NPM) install) && cd .. +# cd $(WEBDIR) && (PATH="$(PATH):$(NODEJS_BIN)"; $(NG) build) && cd .. @echo "Linting completed successfully" .PHONY: tidy diff --git a/client/src/services/websocket/websocket.service.ts b/client/src/services/websocket/websocket.service.ts index 7bc1a6b..a528f68 100644 --- a/client/src/services/websocket/websocket.service.ts +++ b/client/src/services/websocket/websocket.service.ts @@ -13,80 +13,12 @@ export class WebsocketService { private ws: WebSocket; private timeout: number; - private static convertIncomingMessageJsonToObject(incomingMessage: string): WebsocketMessage { - const json = JSON.parse(incomingMessage); - const messageTransform = new WebsocketMessage(); - if (typeof json.type === 'string') { - messageTransform.type = json.type; - } - if (typeof json.component === 'string') { - messageTransform.component = json.component; - } - if (typeof json.subComponent === 'string') { - messageTransform.subComponent = json.subComponent; - } - if (typeof json.timestamp === 'number') { - messageTransform.timestamp = json.timestamp; - } - if (typeof json.error === 'string') { - messageTransform.error = json.error; - } - if (typeof json.fade === 'boolean') { - messageTransform.fade = json.fade; - } - if (typeof json.html === 'string') { - messageTransform.html = json.html; - } - if (typeof json.isAuthenticated === 'boolean') { - messageTransform.isAuthenticated = json.isAuthenticated; - } - if (typeof json.message === 'string') { - messageTransform.message = json.message; - } - if (typeof json.data === 'string' && JSON.parse(json.data)) { - messageTransform.data = JSON.parse(json.data); - } - if (typeof json.yaml === 'string') { - messageTransform.yaml = json.yaml; - } - if (typeof json.dashboards !== undefined && Array.isArray(json.dashboards)) { - json.dashboards.forEach(dashboard => { - const dashboardTransform = new Dashboard(); - if (typeof dashboard.name === 'string') { - dashboardTransform.name = dashboard.name; - } - if (typeof dashboard.baseURL === 'string') { - dashboardTransform.baseURL = dashboard.baseURL; - } - if (typeof dashboard.path === 'string') { - dashboardTransform.path = dashboard.path; - } - if (typeof dashboard.isProxied === 'boolean') { - dashboardTransform.isProxied = dashboard.isProxied; - } - if (typeof dashboard.executable === 'object') { - const executableTransform = new Executable(); - if (typeof dashboard.executable.autoStart === 'boolean') { - executableTransform.autoStart = dashboard.executable.autoStart; - } - if (typeof dashboard.executable.filePath === 'string') { - executableTransform.filePath = dashboard.executable.filePath; - } - if (typeof dashboard.executable.args !== undefined && Array.isArray(typeof dashboard.executable.args)) { - dashboard.executable.args.forEach(arg => { - if (typeof arg === 'string') { - executableTransform.args.push(arg); - } - }); - } - } - if (messageTransform.dashboards === undefined) { - messageTransform.dashboards = []; - } - messageTransform.dashboards.push(dashboardTransform); - }); - } - return messageTransform; + private static messageToObject(incomingMessage: string): WebsocketMessage { + let json = JSON.parse(incomingMessage); + let obj = new WebsocketMessage(); + + Object.assign(obj, json); + return obj; } constructor() { @@ -107,7 +39,7 @@ export class WebsocketService { this.ws = new WebSocket('ws://localhost:8080/ws'); this.ws.onmessage = (event) => { - this.subject.next(WebsocketService.convertIncomingMessageJsonToObject(event.data)); + this.subject.next(WebsocketService.messageToObject(event.data)); }; this.ws.onerror = (event) => { diff --git a/cmd/airshipui/main.go b/cmd/main.go old mode 100644 new mode 100755 similarity index 92% rename from cmd/airshipui/main.go rename to cmd/main.go index 68c6701..123fc09 --- a/cmd/airshipui/main.go +++ b/cmd/main.go @@ -15,7 +15,7 @@ package main import ( - "opendev.org/airship/airshipui/internal/commands" + "opendev.org/airship/airshipui/pkg/commands" ) func main() { diff --git a/internal/webservice/handlers.go b/internal/webservice/handlers.go deleted file mode 100644 index d6a38be..0000000 --- a/internal/webservice/handlers.go +++ /dev/null @@ -1,44 +0,0 @@ -/* - Licensed under the Apache License, Version 2.0 (the "License"); - you may not use this file except in compliance with the License. - You may obtain a copy of the License at - - https://www.apache.org/licenses/LICENSE-2.0 - - Unless required by applicable law or agreed to in writing, software - distributed under the License is distributed on an "AS IS" BASIS, - WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - See the License for the specific language governing permissions and - limitations under the License. -*/ - -package webservice - -import ( - "github.com/pkg/errors" - - "net/http" - - "opendev.org/airship/airshipui/util/utilfile" - "opendev.org/airship/airshipui/util/utilhttp" -) - -const ( - clientPath = "client/dist/airshipui-ui" -) - -func serveFile(w http.ResponseWriter, r *http.Request) { - filePath, filePathErr := utilfile.FilePath(clientPath, r.URL.Path) - if filePathErr != nil { - utilhttp.HandleErr(w, errors.WithStack(filePathErr), http.StatusInternalServerError) - return - } - fileExists, fileExistsErr := utilfile.Exists(filePath) - if fileExistsErr != nil { - utilhttp.HandleErr(w, errors.WithStack(fileExistsErr), http.StatusInternalServerError) - return - } - if fileExists { - http.ServeFile(w, r, filePath) - } -} diff --git a/internal/commands/plugins.go b/pkg/commands/plugins.go similarity index 96% rename from internal/commands/plugins.go rename to pkg/commands/plugins.go index 6b7f8f8..322eb07 100644 --- a/internal/commands/plugins.go +++ b/pkg/commands/plugins.go @@ -25,8 +25,8 @@ import ( "sync" "syscall" - "opendev.org/airship/airshipui/internal/configs" - "opendev.org/airship/airshipui/internal/webservice" + "opendev.org/airship/airshipui/pkg/configs" + "opendev.org/airship/airshipui/pkg/webservice" ) // ProcessGrpCmd wraps an exec.Cmd and a signal chan diff --git a/internal/commands/plugins_windows.go b/pkg/commands/plugins_windows.go similarity index 97% rename from internal/commands/plugins_windows.go rename to pkg/commands/plugins_windows.go index dbe719d..6cb94bd 100644 --- a/internal/commands/plugins_windows.go +++ b/pkg/commands/plugins_windows.go @@ -24,8 +24,8 @@ import ( "unsafe" "golang.org/x/sys/windows" - "opendev.org/airship/airshipui/internal/configs" - "opendev.org/airship/airshipui/internal/webservice" + "opendev.org/airship/airshipui/pkg/configs" + "opendev.org/airship/airshipui/pkg/webservice" ) // struct to store PID and process handle diff --git a/internal/commands/root.go b/pkg/commands/root.go similarity index 96% rename from internal/commands/root.go rename to pkg/commands/root.go index 716d1b7..d3e3c30 100644 --- a/internal/commands/root.go +++ b/pkg/commands/root.go @@ -26,8 +26,8 @@ import ( "github.com/spf13/cobra" - "opendev.org/airship/airshipui/internal/configs" - "opendev.org/airship/airshipui/internal/webservice" + "opendev.org/airship/airshipui/pkg/configs" + "opendev.org/airship/airshipui/pkg/webservice" ) // rootCmd represents the base command when called without any subcommands diff --git a/internal/commands/version.go b/pkg/commands/version.go similarity index 100% rename from internal/commands/version.go rename to pkg/commands/version.go diff --git a/internal/configs/configs.go b/pkg/configs/configs.go similarity index 100% rename from internal/configs/configs.go rename to pkg/configs/configs.go diff --git a/internal/configs/configs_test.go b/pkg/configs/configs_test.go similarity index 100% rename from internal/configs/configs_test.go rename to pkg/configs/configs_test.go diff --git a/internal/configs/testdata/airshipui.json b/pkg/configs/testdata/airshipui.json similarity index 100% rename from internal/configs/testdata/airshipui.json rename to pkg/configs/testdata/airshipui.json diff --git a/internal/configs/testdata/airshipui_invalid.json b/pkg/configs/testdata/airshipui_invalid.json similarity index 100% rename from internal/configs/testdata/airshipui_invalid.json rename to pkg/configs/testdata/airshipui_invalid.json diff --git a/internal/configs/testdata/config.yaml b/pkg/configs/testdata/config.yaml similarity index 100% rename from internal/configs/testdata/config.yaml rename to pkg/configs/testdata/config.yaml diff --git a/internal/configs/testdata/kubeconfig.yaml b/pkg/configs/testdata/kubeconfig.yaml similarity index 100% rename from internal/configs/testdata/kubeconfig.yaml rename to pkg/configs/testdata/kubeconfig.yaml diff --git a/internal/integrations/ctl/airshipctl.go b/pkg/ctl/airshipctl.go similarity index 98% rename from internal/integrations/ctl/airshipctl.go rename to pkg/ctl/airshipctl.go index f6ae419..5b5db1e 100644 --- a/internal/integrations/ctl/airshipctl.go +++ b/pkg/ctl/airshipctl.go @@ -22,7 +22,7 @@ import ( "opendev.org/airship/airshipctl/pkg/environment" "opendev.org/airship/airshipctl/pkg/version" - "opendev.org/airship/airshipui/internal/configs" + "opendev.org/airship/airshipui/pkg/configs" ) // obtain base path of caller so references to html diff --git a/internal/integrations/ctl/baremetal.go b/pkg/ctl/baremetal.go similarity index 97% rename from internal/integrations/ctl/baremetal.go rename to pkg/ctl/baremetal.go index f2df6c4..df3f70f 100644 --- a/internal/integrations/ctl/baremetal.go +++ b/pkg/ctl/baremetal.go @@ -18,7 +18,7 @@ import ( "fmt" "opendev.org/airship/airshipctl/pkg/bootstrap/isogen" - "opendev.org/airship/airshipui/internal/configs" + "opendev.org/airship/airshipui/pkg/configs" ) // HandleBaremetalRequest will flop between requests so we don't have to have them all mapped as function calls diff --git a/internal/integrations/ctl/baremetal_test.go b/pkg/ctl/baremetal_test.go similarity index 97% rename from internal/integrations/ctl/baremetal_test.go rename to pkg/ctl/baremetal_test.go index 0e9672a..dcc5c86 100644 --- a/internal/integrations/ctl/baremetal_test.go +++ b/pkg/ctl/baremetal_test.go @@ -18,7 +18,7 @@ import ( "testing" "github.com/stretchr/testify/assert" - "opendev.org/airship/airshipui/internal/configs" + "opendev.org/airship/airshipui/pkg/configs" "opendev.org/airship/airshipui/util/utiltest" ) diff --git a/internal/integrations/ctl/document.go b/pkg/ctl/document.go similarity index 98% rename from internal/integrations/ctl/document.go rename to pkg/ctl/document.go index 8110c7a..1ac5775 100644 --- a/internal/integrations/ctl/document.go +++ b/pkg/ctl/document.go @@ -21,7 +21,7 @@ import ( "os" "opendev.org/airship/airshipctl/pkg/document/pull" - "opendev.org/airship/airshipui/internal/configs" + "opendev.org/airship/airshipui/pkg/configs" ) // HandleDocumentRequest will flop between requests so we don't have to have them all mapped as function calls diff --git a/internal/integrations/ctl/document_test.go b/pkg/ctl/document_test.go similarity index 97% rename from internal/integrations/ctl/document_test.go rename to pkg/ctl/document_test.go index b8272c7..f810cd4 100644 --- a/internal/integrations/ctl/document_test.go +++ b/pkg/ctl/document_test.go @@ -18,7 +18,7 @@ import ( "testing" "github.com/stretchr/testify/assert" - "opendev.org/airship/airshipui/internal/configs" + "opendev.org/airship/airshipui/pkg/configs" "opendev.org/airship/airshipui/util/utiltest" ) diff --git a/internal/webservice/alerts.go b/pkg/webservice/alerts.go similarity index 96% rename from internal/webservice/alerts.go rename to pkg/webservice/alerts.go index ca1596e..8a845e5 100644 --- a/internal/webservice/alerts.go +++ b/pkg/webservice/alerts.go @@ -17,7 +17,7 @@ package webservice import ( "time" - "opendev.org/airship/airshipui/internal/configs" + "opendev.org/airship/airshipui/pkg/configs" ) // Alerts serves as a queue to hold alerts to be sent to the UI, diff --git a/internal/webservice/alerts_test.go b/pkg/webservice/alerts_test.go similarity index 97% rename from internal/webservice/alerts_test.go rename to pkg/webservice/alerts_test.go index 4968793..cc02a0d 100644 --- a/internal/webservice/alerts_test.go +++ b/pkg/webservice/alerts_test.go @@ -19,7 +19,7 @@ import ( "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" - "opendev.org/airship/airshipui/internal/configs" + "opendev.org/airship/airshipui/pkg/configs" ) func TestSendAlert(t *testing.T) { diff --git a/internal/webservice/proxy.go b/pkg/webservice/proxy.go similarity index 98% rename from internal/webservice/proxy.go rename to pkg/webservice/proxy.go index fd5cc60..acc7f85 100755 --- a/internal/webservice/proxy.go +++ b/pkg/webservice/proxy.go @@ -21,7 +21,7 @@ import ( "net/http/httputil" "net/url" - "opendev.org/airship/airshipui/internal/configs" + "opendev.org/airship/airshipui/pkg/configs" ) // map of proxy targets which will be used based on the request diff --git a/internal/webservice/server.go b/pkg/webservice/server.go similarity index 69% rename from internal/webservice/server.go rename to pkg/webservice/server.go index dc0d25e..2dccfe7 100755 --- a/internal/webservice/server.go +++ b/pkg/webservice/server.go @@ -19,12 +19,36 @@ import ( "net/http" "time" - "opendev.org/airship/airshipui/internal/configs" + "github.com/pkg/errors" + "opendev.org/airship/airshipui/pkg/configs" + "opendev.org/airship/airshipui/util/utilfile" + "opendev.org/airship/airshipui/util/utilhttp" ) // semaphore to signal the UI to authenticate var isAuthenticated bool +const ( + clientPath = "client/dist/airshipui-ui" +) + +// test if path and file exists, if it does send a page, else 404 for you +func serveFile(w http.ResponseWriter, r *http.Request) { + filePath, filePathErr := utilfile.FilePath(clientPath, r.URL.Path) + if filePathErr != nil { + utilhttp.HandleErr(w, errors.WithStack(filePathErr), http.StatusInternalServerError) + return + } + fileExists, fileExistsErr := utilfile.Exists(filePath) + if fileExistsErr != nil { + utilhttp.HandleErr(w, errors.WithStack(fileExistsErr), http.StatusInternalServerError) + return + } + if fileExists { + http.ServeFile(w, r, filePath) + } +} + // handle an auth complete attempt func handleAuth(http.ResponseWriter, *http.Request) { // TODO: handle the response body to capture the credentials diff --git a/internal/webservice/server_test.go b/pkg/webservice/server_test.go similarity index 97% rename from internal/webservice/server_test.go rename to pkg/webservice/server_test.go index 80c657f..a6328b0 100644 --- a/internal/webservice/server_test.go +++ b/pkg/webservice/server_test.go @@ -20,7 +20,7 @@ import ( "testing" "time" - "opendev.org/airship/airshipui/internal/configs" + "opendev.org/airship/airshipui/pkg/configs" "github.com/gorilla/websocket" "github.com/stretchr/testify/assert" diff --git a/internal/webservice/websocket.go b/pkg/webservice/websocket.go similarity index 97% rename from internal/webservice/websocket.go rename to pkg/webservice/websocket.go index 23a661b..6cbdd7f 100644 --- a/internal/webservice/websocket.go +++ b/pkg/webservice/websocket.go @@ -21,8 +21,8 @@ import ( "time" "github.com/gorilla/websocket" - "opendev.org/airship/airshipui/internal/configs" - "opendev.org/airship/airshipui/internal/integrations/ctl" + "opendev.org/airship/airshipui/pkg/configs" + "opendev.org/airship/airshipui/pkg/ctl" ) // gorilla ws specific HTTP upgrade to WebSockets diff --git a/internal/webservice/websocket_test.go b/pkg/webservice/websocket_test.go similarity index 99% rename from internal/webservice/websocket_test.go rename to pkg/webservice/websocket_test.go index 23b043d..78e32f9 100644 --- a/internal/webservice/websocket_test.go +++ b/pkg/webservice/websocket_test.go @@ -23,7 +23,7 @@ import ( "github.com/gorilla/websocket" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" - "opendev.org/airship/airshipui/internal/configs" + "opendev.org/airship/airshipui/pkg/configs" ) func TestClientInit(t *testing.T) { diff --git a/tools/check_copyright b/tools/check_copyright index eb99ca8..36f345b 100755 --- a/tools/check_copyright +++ b/tools/check_copyright @@ -18,7 +18,7 @@ declare FILES_MISSING_COPYRIGHT=() check_license() { ext=$1 # skipping license for testdata and manifests folders - FILES=$(find -L . -name "*.${ext}" | grep -v "testdata" | grep -v "manifests") + FILES=$(find -L . -name "*.${ext}" | grep -v "testdata" | grep -v "manifests" | grep -v "tools/*node*" | grep -v "client/node_modules" | grep -v "client/dist") for each in $FILES do diff --git a/util/utiltest/utiltest.go b/util/utiltest/utiltest.go index b683016..9c95180 100644 --- a/util/utiltest/utiltest.go +++ b/util/utiltest/utiltest.go @@ -22,7 +22,7 @@ import ( "github.com/stretchr/testify/require" "opendev.org/airship/airshipctl/pkg/config" - "opendev.org/airship/airshipui/internal/configs" + "opendev.org/airship/airshipui/pkg/configs" ) // TODO: Determine if this should be broken out into it's own file