Simplify, refactor and rename to bring in line with CTL
This patch does the following: 1. Simplify the client websocket message transformation 2. Move the cmd/airshipui to cmd 3. move internal to pkg 4. Clean up the copyright checker 5. clean up the linting in the makefile Change-Id: I1381d025e8058cbfba44b58ec3c2ec5c2aa36de5
This commit is contained in:
parent
a0d1b40230
commit
a15a4d87e2
13
Makefile
13
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
|
||||
|
@ -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) => {
|
||||
|
2
cmd/airshipui/main.go → cmd/main.go
Normal file → Executable file
2
cmd/airshipui/main.go → cmd/main.go
Normal file → Executable file
@ -15,7 +15,7 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"opendev.org/airship/airshipui/internal/commands"
|
||||
"opendev.org/airship/airshipui/pkg/commands"
|
||||
)
|
||||
|
||||
func main() {
|
@ -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)
|
||||
}
|
||||
}
|
@ -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
|
@ -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
|
@ -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
|
@ -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
|
@ -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
|
@ -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"
|
||||
)
|
||||
|
@ -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
|
@ -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"
|
||||
)
|
||||
|
@ -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,
|
@ -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) {
|
@ -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
|
@ -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
|
@ -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"
|
@ -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
|
@ -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) {
|
@ -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
|
||||
|
@ -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
|
||||
|
Loading…
Reference in New Issue
Block a user