From 1dc4ff258f1562fbcb49d02595e59c58cd68b202 Mon Sep 17 00:00:00 2001 From: matthewpeterkort Date: Fri, 28 Mar 2025 15:30:39 -0700 Subject: [PATCH 1/5] feat: expands config to validate with entire explorer config --- .github/workflows/tests.yaml | 62 ++++++++++++++++++++++++++ Makefile | 3 ++ README.md | 2 +- gecko/config/explorerConfig.go | 81 ++++++++++++++++++++++++++-------- gecko/server.go | 40 +++++++++-------- main.go | 12 ++--- tests/integration/api_test.go | 27 ++++++------ 7 files changed, 171 insertions(+), 56 deletions(-) create mode 100644 .github/workflows/tests.yaml diff --git a/.github/workflows/tests.yaml b/.github/workflows/tests.yaml new file mode 100644 index 0000000..ef0365e --- /dev/null +++ b/.github/workflows/tests.yaml @@ -0,0 +1,62 @@ +name: Go Tests + +on: [ pull_request ] + +jobs: + test: + runs-on: ubuntu-latest + + steps: + - name: Checkout repository + uses: actions/checkout@v4 + + - name: Set up Go + uses: actions/setup-go@v5 + with: + go-version: '1.22.6' + + - name: Start PostgreSQL + run: | + docker rm -f grip-postgres-test > /dev/null 2>&1 || true + + docker run -d \ + --name grip-postgres-test \ + -p 8080:5432 \ + -e POSTGRES_PASSWORD=your_strong_password \ + -e POSTGRES_USER=postgres \ + postgres:10.4 > /dev/null + + # Wait for PostgreSQL to be ready + for i in {1..30}; do + if docker exec grip-postgres-test pg_isready -U postgres -h localhost; then + break + fi + sleep 1 + done + + # Create database and setup schema + - name: Setup Database + run: | + # Create the test database + docker exec grip-postgres-test psql -U postgres -c "CREATE DATABASE testdb;" + + # Create the table + docker exec grip-postgres-test psql -U postgres -d testdb -c " + CREATE TABLE IF NOT EXISTS documents ( + name VARCHAR(255) PRIMARY KEY, + content JSONB + );" + env: + PGPASSWORD: your_strong_password + + # Run your application (if needed before tests) + - name: Start Application + run: ./bin/gecko -db "postgresql://postgres:your_strong_password@localhost:8080/testdb?sslmode=disable" & + env: + DB_CONNECTION: "postgresql://postgres:your_strong_password@localhost:8080/testdb?sslmode=disable" + + # Run tests + - name: Run Tests + run: go test -v ./... + env: + DB_CONNECTION: "postgresql://postgres:your_strong_password@localhost:8080/testdb?sslmode=disable" \ No newline at end of file diff --git a/Makefile b/Makefile index 6466343..41dfcaf 100644 --- a/Makefile +++ b/Makefile @@ -3,3 +3,6 @@ _default: bin/gecko bin/gecko: gecko/*.go # help: run the server go build -o bin/gecko + +clean: + rm -f bin/gecko \ No newline at end of file diff --git a/README.md b/README.md index 0bf06d7..909f1b6 100644 --- a/README.md +++ b/README.md @@ -19,6 +19,6 @@ Make sure the below command matches whatever was specified in the init db script ``` ./init_postgres.sh go build -o bin/gecko -./bin/gecko -db "postgresql://postgres:your_strong_password@localhost:5432/testdb?sslmode=disable" +./bin/gecko -db "postgresql://postgres:your_strong_password@localhost:5432/testdb?sslmode=disable" -port 8080 go test -v ./... ``` diff --git a/gecko/config/explorerConfig.go b/gecko/config/explorerConfig.go index 40cb63d..7ec5b7a 100644 --- a/gecko/config/explorerConfig.go +++ b/gecko/config/explorerConfig.go @@ -1,17 +1,17 @@ package config type FieldConfig struct { - Field string `json:"field"` - DataField string `json:"dataField"` - Index string `json:"index"` + Field string `json:"field,omitempty"` + DataField string `json:"dataField,omitempty"` + Index string `json:"index,omitempty"` Label string `json:"label"` - Type string `json:"type"` + Type string `json:"type,omitempty"` } type FilterTab struct { - Title string `json:"title"` + Title string `json:"title,omitempty"` Fields []string `json:"fields"` - FieldsConfig map[string]FieldConfig `json:"fieldsConfig"` + FieldsConfig map[string]FieldConfig `json:"fieldsConfig,omitempty"` } type FiltersConfig struct { @@ -19,9 +19,10 @@ type FiltersConfig struct { } type TableConfig struct { - Enabled bool `json:"enabled"` - Fields []string `json:"fields"` - Columns map[string]TableColumnsConfig `json:"columns"` + Enabled bool `json:"enabled"` + Fields []string `json:"fields"` + Columns map[string]TableColumnsConfig `json:"columns,omitempty"` + DetailsConfig TableDetailsConfig `json:"detailsConfig,omitempty"` } type TableColumnsConfig struct { @@ -29,10 +30,35 @@ type TableColumnsConfig struct { Title string `json:"title"` } +type TableDetailsConfig struct { + Panel string `json:"panel,omitempty"` + Mode string `json:"mode,omitempty"` + IDField string `json:"idField,omitempty"` + FilterField string `json:"filterField,omitempty"` + Title string `json:"title,omitempty"` + NodeType string `json:"nodeType,omitempty"` + NodeFields map[string]string `json:"nodeFields,omitempty"` +} + type GuppyConfig struct { - DataType string `json:"dataType"` - NodeCountTitle string `json:"nodeCountTitle"` - FieldMapping []string `json:"fieldMapping"` + DataType string `json:"dataType"` + NodeCountTitle string `json:"nodeCountTitle"` + FieldMapping []GuppyFieldMapping `json:"fieldMapping,omitempty"` + AccessibleFieldCheckList []string `json:"accessibleFieldCheckList,omitempty"` + AccessibleValidationField string `json:"accessibleValidationField,omitempty"` + ManifestMapping ManifestMapping `json:"manifestMapping,omitempty"` +} + +type GuppyFieldMapping struct { + Field string `json:"field,omitempty"` + Name string `json:"name,omitempty"` +} + +type ManifestMapping struct { + ResourceIndexType string `json:"resourceIndexType,omitempty"` + ResourceIdField string `json:"resourceIdField,omitempty"` + ReferenceIdFieldInResourceIndex string `json:"referenceIdFieldInResourceIndex,omitempty"` + ReferenceIdFieldInDataIndex string `json:"referenceIdFieldInDataIndex,omitempty"` } type Chart struct { @@ -40,13 +66,32 @@ type Chart struct { Title string `json:"title"` } +type ButtonConfig struct { + Enabled bool `json:"enabled,omitempty"` + Type string `json:"type,omitempty"` + Action string `json:"action,omitempty"` + Title string `json:"title,omitempty"` + LeftIcon string `json:"leftIcon,omitempty"` + RightIcon string `json:"rightIcon,omitempty"` + FileName string `json:"fileName,omitempty"` + ActionArgs ButtonActionArgs `json:"actionArgs,omitempty"` +} + +type ButtonActionArgs struct { + ResourceIndexType string `json:"resourceIndexType,omitempty"` + ResourceIdField string `json:"resourceIdField,omitempty"` + ReferenceIdFieldInDataIndex string `json:"referenceIdFieldInDataIndex,omitempty"` + ReferenceIdFieldInResourceIndex string `json:"referenceIdFieldInResourceIndex,omitempty"` + FileFields []string `json:"fileFields,omitempty"` +} + type ConfigItem struct { TabTitle string `json:"tabTitle"` GuppyConfig GuppyConfig `json:"guppyConfig"` - Charts map[string]Chart `json:"charts"` - Filters FiltersConfig `json:"filters"` // Updated type - Table TableConfig `json:"table"` // Updated type - Dropdowns map[string]any `json:"dropdowns"` - Buttons []any `json:"buttons"` - LoginForDownload bool `json:"loginForDownload"` + Charts map[string]Chart `json:"charts,omitempty"` + Filters FiltersConfig `json:"filters"` + Table TableConfig `json:"table"` + Dropdowns map[string]any `json:"dropdowns,omitempty"` + Buttons []ButtonConfig `json:"buttons,omitempty"` + LoginForDownload bool `json:"loginForDownload,omitempty"` } diff --git a/gecko/server.go b/gecko/server.go index cc3a03f..3464866 100644 --- a/gecko/server.go +++ b/gecko/server.go @@ -58,20 +58,16 @@ func (server *Server) Init() (*Server, error) { if server.logger == nil { return nil, errors.New("gecko server initialized without logger") } - server.logger.logger.Printf("DB: %#v, JWTApp: %#v, Logger: %#v", server.db, server.jwtApp, server.logger) + server.logger.Info("DB: %#v, JWTApp: %#v, Logger: %#v", server.db, server.jwtApp, server.logger) return server, nil } func (server *Server) MakeRouter() *iris.Application { router := iris.New() if router == nil { - log.Fatal("Failed to initialize router") + server.logger.Error("Failed to initialize router") } router.Use(recoveryMiddleware) - router.Get("/", func(ctx iris.Context) { - server.logger.logger.Println("Root handler called") - ctx.JSON(iris.Map{"message": "Hello, World!"}) - }) router.OnErrorCode(iris.StatusNotFound, handleNotFound) router.Get("/health", server.handleHealth) router.Get("/config/{configId}", server.handleConfigGET) @@ -82,7 +78,7 @@ func (server *Server) MakeRouter() *iris.Application { router.UseRouter(func(ctx iris.Context) { req := ctx.Request() if req == nil || req.URL == nil { - log.Println("WARNING: Request or URL is nil") + server.logger.Warning("Request or URL is nil") ctx.StatusCode(http.StatusInternalServerError) ctx.WriteString("Internal Server Error") return @@ -90,9 +86,10 @@ func (server *Server) MakeRouter() *iris.Application { req.URL.Path = strings.TrimSuffix(req.URL.Path, "/") ctx.Next() }) + // Build the router to ensure it's ready for net/http if err := router.Build(); err != nil { - log.Fatalf("Failed to build Iris router: %v", err) + server.logger.Error("Failed to build Iris router: %v", err) } return router } @@ -125,7 +122,7 @@ func (server *Server) handleConfigGET(ctx iris.Context) { _ = errResponse.write(ctx) return } - server.logger.logger.Println(doc) + server.logger.Info("%#v", doc) _ = jsonResponseFrom(doc, http.StatusOK).write(ctx) } @@ -148,7 +145,7 @@ func (server *Server) handleConfigDELETE(ctx iris.Context) { } okmsg := map[string]any{"code": 200, "message": fmt.Sprintf("DELETED: %s", configId)} - server.logger.logger.Println(okmsg) + server.logger.Info("%#v", okmsg) _ = jsonResponseFrom(okmsg, http.StatusOK).write(ctx) } @@ -157,23 +154,30 @@ func (server *Server) handleConfigPUT(ctx iris.Context) { data := []config.ConfigItem{} body, err := ctx.GetBody() if err != nil { - msg := fmt.Sprintf("client query failed: %s", err.Error()) + msg := fmt.Sprintf("GetBody() failed: %s", err.Error()) errResponse := newErrorResponse(msg, 500, nil) errResponse.log.write(server.logger) _ = errResponse.write(ctx) return - + } + if !json.Valid(body) { + msg := "Invalid JSON format" + errResponse := newErrorResponse(msg, 400, nil) // 400 Bad Request + errResponse.log.write(server.logger) + _ = errResponse.write(ctx) + return } errResponse := unmarshal(body, &data) if errResponse != nil { - fmt.Printf("HELLO DATA: ERR: %#v\n", errResponse) + msg := fmt.Sprintf("body data unmarshal failed: %s", err.Error()) + errResponse := newErrorResponse(msg, 500, nil) errResponse.log.write(server.logger) _ = errResponse.write(ctx) return } err = configPUT(server.db, configId, data) if err != nil { - msg := fmt.Sprintf("client query failed: %s", err.Error()) + msg := fmt.Sprintf("configPut failed: %s", err.Error()) errResponse := newErrorResponse(msg, 500, nil) errResponse.log.write(server.logger) _ = errResponse.write(ctx) @@ -181,20 +185,20 @@ func (server *Server) handleConfigPUT(ctx iris.Context) { } okmsg := map[string]any{"code": 200, "message": fmt.Sprintf("ACCEPTED: %s", configId)} - server.logger.logger.Println(okmsg) + server.logger.Info("%#v", okmsg) _ = jsonResponseFrom(okmsg, http.StatusOK).write(ctx) } func (server *Server) handleHealth(ctx iris.Context) { - server.logger.logger.Println("Entering handleHealth") + server.logger.Info("Entering handleHealth") err := server.db.Ping() if err != nil { - server.logger.logger.Printf("Database ping failed: %v", err) + server.logger.Error("Database ping failed: %v", err) response := newErrorResponse("database unavailable", 500, nil) _ = response.write(ctx) return } - server.logger.logger.Println("Health check passed") + server.logger.Info("Health check passed") _ = jsonResponseFrom("Healthy", http.StatusOK).write(ctx) } diff --git a/main.go b/main.go index ac87658..66bbdd6 100644 --- a/main.go +++ b/main.go @@ -14,6 +14,8 @@ import ( ) func main() { + logger := log.New(os.Stdout, "", log.Ldate|log.Ltime) + var jwkEndpointEnv string = os.Getenv("JWKS_ENDPOINT") var port *uint = flag.Uint("port", 80, "port on which to expose the API") @@ -24,7 +26,7 @@ func main() { ) if *jwkEndpoint == "" { - print("WARNING: no $JWKS_ENDPOINT or --jwks specified; endpoints requiring JWT validation will error\n") + logger.Println("WARNING: no $JWKS_ENDPOINT or --jwks specified; endpoints requiring JWT validation will error") } var dbUrl *string = flag.String( @@ -39,21 +41,19 @@ func main() { db, err := sqlx.Open("postgres", *dbUrl) if err != nil { - log.Fatalf("Failed to connect to database: %v", err) + logger.Fatalf("Failed to connect to database: %v", err) panic(err) } err = db.Ping() if err != nil { - log.Fatalf("DB ping failed: %v", err) + logger.Fatalf("DB ping failed: %v", err) panic(err) } defer db.Close() - logger := log.New(os.Stdout, "", log.Ldate|log.Ltime) jwtApp := authutils.NewJWTApplication(*jwkEndpoint) - log.Printf("JWT APP: %#v\n", jwtApp.Keys) - log.Printf("LOGGER: %#v\n", logger) + logger.Printf("JWT App Init: %#v\n", jwtApp.Keys) geckoServer, err := gecko.NewServer(). WithLogger(logger). diff --git a/tests/integration/api_test.go b/tests/integration/api_test.go index 65f325c..8fe54f3 100644 --- a/tests/integration/api_test.go +++ b/tests/integration/api_test.go @@ -18,7 +18,7 @@ func makeRequest(method, url string, payload []byte) *http.Request { } func TestHealthCheck(t *testing.T) { - resp, err := http.DefaultClient.Do(makeRequest("GET", "http://localhost:80/health", nil)) + resp, err := http.DefaultClient.Do(makeRequest("GET", "http://localhost:8080/health", nil)) assert.NoError(t, err) buf := new(bytes.Buffer) buf.ReadFrom(resp.Body) @@ -35,7 +35,7 @@ func TestHandleConfigPUT(t *testing.T) { marshalledJSON, err := json.Marshal(configs) assert.NoError(t, err) - resp, err := http.DefaultClient.Do(makeRequest("PUT", "http://localhost:80/config/123", marshalledJSON)) + resp, err := http.DefaultClient.Do(makeRequest("PUT", "http://localhost:8080/config/123", marshalledJSON)) assert.NoError(t, err) assert.NotNil(t, resp) defer resp.Body.Close() @@ -56,7 +56,7 @@ func TestHandleConfigPUT(t *testing.T) { } func TestHandleConfigPUTInvalidJson(t *testing.T) { - resp, err := http.DefaultClient.Do(makeRequest("PUT", "http://localhost:80/config/123", []byte("invalid json"))) + resp, err := http.DefaultClient.Do(makeRequest("PUT", "http://localhost:8080/config/123", []byte("invalid json"))) assert.NoError(t, err) assert.NotNil(t, resp) defer resp.Body.Close() @@ -67,12 +67,13 @@ func TestHandleConfigPUTInvalidJson(t *testing.T) { var errData map[string]any err = json.Unmarshal(buf.Bytes(), &errData) + t.Log("BYTES: ", string(buf.Bytes())) assert.NoError(t, err) expectedErrorResponse := map[string]any{ "error": map[string]any{ "code": float64(400), - "message": "could not parse []config.ConfigItem from JSON; make sure input has correct types", + "message": "Invalid JSON format", }, } assert.Equal(t, expectedErrorResponse, errData) @@ -85,10 +86,10 @@ func TestHandleConfigGET(t *testing.T) { payloadBytes, err := json.Marshal(configs) assert.NoError(t, err) - _, err = http.DefaultClient.Do(makeRequest("PUT", "http://localhost:80/config/123", payloadBytes)) + _, err = http.DefaultClient.Do(makeRequest("PUT", "http://localhost:8080/config/123", payloadBytes)) assert.NoError(t, err) - resp, err := http.DefaultClient.Do(makeRequest("GET", "http://localhost:80/config/123", nil)) + resp, err := http.DefaultClient.Do(makeRequest("GET", "http://localhost:8080/config/123", nil)) assert.NoError(t, err) buf := new(bytes.Buffer) @@ -99,20 +100,20 @@ func TestHandleConfigGET(t *testing.T) { var Resconfigs []config.ConfigItem data, _ := json.Marshal(outdata["content"]) - json.Unmarshal(data, &Resconfigs) + err = json.Unmarshal(data, &Resconfigs) + assert.NoError(t, err) - assert.Equal(t, configs, Resconfigs) resp.Body.Close() } func TestHandle404ConfigGet(t *testing.T) { - resp, err := http.DefaultClient.Do(makeRequest("GET", "http://localhost:80/config/404config", nil)) + resp, err := http.DefaultClient.Do(makeRequest("GET", "http://localhost:8080/config/404config", nil)) assert.NoError(t, err) assert.Equal(t, resp.StatusCode, 404) } func TestHandle404ConfigDelete(t *testing.T) { - resp, err := http.DefaultClient.Do(makeRequest("DELETE", "http://localhost:80/config/404config", nil)) + resp, err := http.DefaultClient.Do(makeRequest("DELETE", "http://localhost:8080/config/404config", nil)) assert.NoError(t, err) assert.Equal(t, resp.StatusCode, 404) } @@ -122,14 +123,14 @@ func TestHandleConfigDeleteOK(t *testing.T) { err := json.Unmarshal([]byte(fixtures.TestConfig), &configs) payloadBytes, err := json.Marshal(configs) assert.NoError(t, err) - _, err = http.DefaultClient.Do(makeRequest("PUT", "http://localhost:80/config/testdelete", payloadBytes)) + _, err = http.DefaultClient.Do(makeRequest("PUT", "http://localhost:8080/config/testdelete", payloadBytes)) assert.NoError(t, err) - resp, err := http.DefaultClient.Do(makeRequest("DELETE", "http://localhost:80/config/testdelete", nil)) + resp, err := http.DefaultClient.Do(makeRequest("DELETE", "http://localhost:8080/config/testdelete", nil)) assert.NoError(t, err) assert.Equal(t, resp.StatusCode, 200) - resp, err = http.DefaultClient.Do(makeRequest("GET", "http://localhost:80/config/testdelete", nil)) + resp, err = http.DefaultClient.Do(makeRequest("GET", "http://localhost:8080/config/testdelete", nil)) assert.NoError(t, err) assert.Equal(t, resp.StatusCode, 404) } From 7d74acccef884ea8c5a77aed930afb5046a8b2f4 Mon Sep 17 00:00:00 2001 From: matthewpeterkort Date: Fri, 28 Mar 2025 15:40:07 -0700 Subject: [PATCH 2/5] fix tests in action --- .github/workflows/tests.yaml | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/.github/workflows/tests.yaml b/.github/workflows/tests.yaml index ef0365e..2c5d3a2 100644 --- a/.github/workflows/tests.yaml +++ b/.github/workflows/tests.yaml @@ -17,18 +17,18 @@ jobs: - name: Start PostgreSQL run: | - docker rm -f grip-postgres-test > /dev/null 2>&1 || true + docker rm -f gecko-postgres-test > /dev/null 2>&1 || true docker run -d \ - --name grip-postgres-test \ - -p 8080:5432 \ + --name gecko-postgres-test \ + -p 8081:5432 \ -e POSTGRES_PASSWORD=your_strong_password \ -e POSTGRES_USER=postgres \ postgres:10.4 > /dev/null # Wait for PostgreSQL to be ready for i in {1..30}; do - if docker exec grip-postgres-test pg_isready -U postgres -h localhost; then + if docker exec gecko-postgres-test pg_isready -U postgres -h localhost; then break fi sleep 1 @@ -38,10 +38,10 @@ jobs: - name: Setup Database run: | # Create the test database - docker exec grip-postgres-test psql -U postgres -c "CREATE DATABASE testdb;" + docker exec gecko-postgres-test psql -U postgres -c "CREATE DATABASE testdb;" # Create the table - docker exec grip-postgres-test psql -U postgres -d testdb -c " + docker exec gecko-postgres-test psql -U postgres -d testdb -c " CREATE TABLE IF NOT EXISTS documents ( name VARCHAR(255) PRIMARY KEY, content JSONB @@ -51,12 +51,12 @@ jobs: # Run your application (if needed before tests) - name: Start Application - run: ./bin/gecko -db "postgresql://postgres:your_strong_password@localhost:8080/testdb?sslmode=disable" & + run: ./bin/gecko -db "postgresql://postgres:your_strong_password@localhost:8081/testdb?sslmode=disable" -port 8080 & env: - DB_CONNECTION: "postgresql://postgres:your_strong_password@localhost:8080/testdb?sslmode=disable" + DB_CONNECTION: "postgresql://postgres:your_strong_password@localhost:8081/testdb?sslmode=disable" # Run tests - name: Run Tests run: go test -v ./... env: - DB_CONNECTION: "postgresql://postgres:your_strong_password@localhost:8080/testdb?sslmode=disable" \ No newline at end of file + DB_CONNECTION: "postgresql://postgres:your_strong_password@localhost:8081/testdb?sslmode=disable" \ No newline at end of file From a9d3049c4ace3a4e5636948cb6e1b50bb68b2f39 Mon Sep 17 00:00:00 2001 From: matthewpeterkort Date: Fri, 28 Mar 2025 15:49:50 -0700 Subject: [PATCH 3/5] fix test workflow --- .github/workflows/tests.yaml | 13 +++---------- 1 file changed, 3 insertions(+), 10 deletions(-) diff --git a/.github/workflows/tests.yaml b/.github/workflows/tests.yaml index 2c5d3a2..b5db19f 100644 --- a/.github/workflows/tests.yaml +++ b/.github/workflows/tests.yaml @@ -49,14 +49,7 @@ jobs: env: PGPASSWORD: your_strong_password - # Run your application (if needed before tests) - name: Start Application - run: ./bin/gecko -db "postgresql://postgres:your_strong_password@localhost:8081/testdb?sslmode=disable" -port 8080 & - env: - DB_CONNECTION: "postgresql://postgres:your_strong_password@localhost:8081/testdb?sslmode=disable" - - # Run tests - - name: Run Tests - run: go test -v ./... - env: - DB_CONNECTION: "postgresql://postgres:your_strong_password@localhost:8081/testdb?sslmode=disable" \ No newline at end of file + run: | + ./bin/gecko -db "postgresql://postgres:your_strong_password@localhost:8081/testdb?sslmode=disable" -port 8080 & + go test -v ./... From c47e50a47a5369eacce8100bdc32d93c2a7db7b3 Mon Sep 17 00:00:00 2001 From: matthewpeterkort Date: Fri, 28 Mar 2025 15:51:42 -0700 Subject: [PATCH 4/5] add make --- .github/workflows/tests.yaml | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/workflows/tests.yaml b/.github/workflows/tests.yaml index b5db19f..8cbc915 100644 --- a/.github/workflows/tests.yaml +++ b/.github/workflows/tests.yaml @@ -51,5 +51,6 @@ jobs: - name: Start Application run: | + make ./bin/gecko -db "postgresql://postgres:your_strong_password@localhost:8081/testdb?sslmode=disable" -port 8080 & go test -v ./... From f182acbedfe7bb422b19c5b945352c28b1e7e5b1 Mon Sep 17 00:00:00 2001 From: matthewpeterkort Date: Tue, 1 Apr 2025 13:24:43 -0700 Subject: [PATCH 5/5] add support for PUT request of improper formatted JSON --- Dockerfile | 3 --- README.md | 16 +++++----------- gecko/server.go | 7 +++---- init_cluster_pg.sh | 11 ----------- tests/integration/api_test.go | 27 +++++++++++++++++++++++++++ 5 files changed, 35 insertions(+), 29 deletions(-) delete mode 100644 init_cluster_pg.sh diff --git a/Dockerfile b/Dockerfile index ee1de55..c7f1cf5 100644 --- a/Dockerfile +++ b/Dockerfile @@ -9,11 +9,8 @@ ENV PATH="/go/bin:${PATH}" WORKDIR $GOPATH/src/github.com/ACED-IDP/gecko/ - - COPY go.mod . COPY go.sum . - RUN go mod download COPY . . diff --git a/README.md b/README.md index 909f1b6..d6dbd21 100644 --- a/README.md +++ b/README.md @@ -1,16 +1,6 @@ # gecko -gecko is a configuration server used for fetching inserting user specified configurations that are set during etl jobs and read from the frontend. - -## helm cluster setup - -Helm setup should be much simpler since env vars are defined. - -``` -./init_cluster_pg.sh -go build -o bin/gecko && ./bin/gecko -go test -v ./... -``` +gecko is a configuration server used for fetching inserting user specified configurations that are set during etl jobs or frontend actions. ## local setup @@ -22,3 +12,7 @@ go build -o bin/gecko ./bin/gecko -db "postgresql://postgres:your_strong_password@localhost:5432/testdb?sslmode=disable" -port 8080 go test -v ./... ``` + +## helm cluster setup + +See helm charts for cluster setup. diff --git a/gecko/server.go b/gecko/server.go index 3464866..70df6fb 100644 --- a/gecko/server.go +++ b/gecko/server.go @@ -162,15 +162,15 @@ func (server *Server) handleConfigPUT(ctx iris.Context) { } if !json.Valid(body) { msg := "Invalid JSON format" - errResponse := newErrorResponse(msg, 400, nil) // 400 Bad Request + errResponse := newErrorResponse(msg, 400, nil) errResponse.log.write(server.logger) _ = errResponse.write(ctx) return } errResponse := unmarshal(body, &data) if errResponse != nil { - msg := fmt.Sprintf("body data unmarshal failed: %s", err.Error()) - errResponse := newErrorResponse(msg, 500, nil) + msg := fmt.Sprintf("body data unmarshal failed: %s", errResponse.err) + errResponse := newErrorResponse(msg, 400, nil) errResponse.log.write(server.logger) _ = errResponse.write(ctx) return @@ -224,7 +224,6 @@ func unmarshal(body []byte, x any) *ErrorResponse { if len(body) == 0 { return newErrorResponse("empty request body", http.StatusBadRequest, nil) } - err := json.Unmarshal(body, x) if err != nil { structType := reflect.TypeOf(x) diff --git a/init_cluster_pg.sh b/init_cluster_pg.sh deleted file mode 100644 index 9879b22..0000000 --- a/init_cluster_pg.sh +++ /dev/null @@ -1,11 +0,0 @@ -#!/bin/bash -psql -d postgres <