Skip to content

Commit

Permalink
Merge pull request #536 from meshery/fix/security
Browse files Browse the repository at this point in the history
Remove circular dependencies
  • Loading branch information
leecalcote authored Oct 17, 2023
2 parents e76bb7f + cc4af68 commit dcc2130
Show file tree
Hide file tree
Showing 15 changed files with 378 additions and 928 deletions.
6 changes: 3 additions & 3 deletions .github/workflows/approve-to-run-ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ jobs:
strategy:
matrix:
platform: [ubuntu-22.04]
go-version: [1.19.x]
go-version: [1.21.x]
runs-on: ${{ matrix.platform }}
steps:
- uses: actions/setup-go@v4
Expand All @@ -36,7 +36,7 @@ jobs:
- name: Set up Go
uses: actions/setup-go@v4
with:
go-version: 1.19.x
go-version: 1.21.x
- name: Set up test-env
run: make test-env
- name: Run unit tests
Expand All @@ -60,6 +60,6 @@ jobs:
- name: Set up Go
uses: actions/setup-go@v4
with:
go-version: 1.19.x
go-version: 1.21.x
- name: Build
run: make build
2 changes: 1 addition & 1 deletion .github/workflows/error-ref-publisher.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ jobs:
- name: Setup Go
uses: actions/setup-go@master
with:
go-version: 1.19
go-version: 1.21

- name: Run utility
run: |
Expand Down
10 changes: 3 additions & 7 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -117,22 +117,18 @@ run-lint:
get-lint:
go get github.com/golangci/golangci-lint/cmd/golangci-lint@v1.50.1

# Run meshery error utility against code
error:
go run github.com/layer5io/meshkit/cmd/errorutil -d . analyze -i ./helpers -o ./helpers

.PHONY: test
test: manifests generate fmt vet error ## Run tests.
test: manifests generate fmt vet ## Run tests.
go test ./... -coverprofile cover.out

##@ Build

.PHONY: build
build: generate fmt vet error manifests ## Build manager binary.
build: generate fmt vet manifests ## Build manager binary.
go build -o bin/manager main.go

.PHONY: run
run: manifests generate fmt vet error ## Run a controller from your host.
run: manifests generate fmt vet ## Run a controller from your host.
go mod tidy; \
go run ./main.go

Expand Down
4 changes: 2 additions & 2 deletions controllers/broker_controller.go
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
Copyright 2023 Layer5, Inc.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -29,7 +29,7 @@ import (

mesheryv1alpha1 "github.com/layer5io/meshery-operator/api/v1alpha1"
brokerpackage "github.com/layer5io/meshery-operator/pkg/broker"
"github.com/layer5io/meshkit/utils"
"github.com/meshery/meshery-operator/pkg/utils"
kubeerror "k8s.io/apimachinery/pkg/api/errors"
types "k8s.io/apimachinery/pkg/types"
)
Expand Down
33 changes: 19 additions & 14 deletions controllers/error.go
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
Copyright 2020 Layer5, Inc.
Copyright 2023 Layer5, Inc.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
Expand All @@ -16,7 +16,7 @@ limitations under the License.
package controllers

import (
"github.com/layer5io/meshkit/errors"
"errors"
)

// Error codes
Expand All @@ -34,53 +34,58 @@ const (
ErrCheckHealthCode = "1010"
ErrGetEndpointCode = "1011"
ErrUpdateResourceCode = "1012"
ErrMarshalCode = "11049"
)

// Error definitions
func ErrGetMeshsync(err error) error {
return errors.New(ErrGetMeshsyncCode, errors.Alert, []string{"Meshsync resource not found"}, []string{err.Error()}, []string{}, []string{})
return errors.New(ErrGetMeshsyncCode + ":" + "Unable to get meshsync resource")
}

func ErrCreateMeshsync(err error) error {
return errors.New(ErrCreateMeshsyncCode, errors.Alert, []string{"Unable to create meshsync controller"}, []string{err.Error()}, []string{}, []string{})
return errors.New(ErrCreateMeshsyncCode + ":" + "Unable to create meshsync controller")
}

func ErrDeleteMeshsync(err error) error {
return errors.New(ErrDeleteMeshsyncCode, errors.Alert, []string{"Unable to delete meshsync controller"}, []string{err.Error()}, []string{}, []string{})
return errors.New(ErrDeleteMeshsyncCode + ":" + "Unable to delete meshsync controller")
}

func ErrReconcileMeshsync(err error) error {
return errors.New(ErrReconcileMeshsyncCode, errors.Alert, []string{"Error during meshsync resource reconciliation"}, []string{err.Error()}, []string{}, []string{})
return errors.New(ErrReconcileMeshsyncCode + ":" + "Error during meshsync resource reconciliation")
}

func ErrGetBroker(err error) error {
return errors.New(ErrGetBrokerCode, errors.Alert, []string{"Broker resource not found"}, []string{err.Error()}, []string{}, []string{})
return errors.New(ErrGetBrokerCode + ":" + "Broker resource not found")
}

func ErrCreateBroker(err error) error {
return errors.New(ErrCreateBrokerCode, errors.Alert, []string{"Unable to create broker controller"}, []string{err.Error()}, []string{}, []string{})
return errors.New(ErrCreateBrokerCode + ":" + "Unable to create broker controller")
}

func ErrDeleteBroker(err error) error {
return errors.New(ErrDeleteBrokerCode, errors.Alert, []string{"Unable to delete broker controller"}, []string{err.Error()}, []string{}, []string{})
return errors.New(ErrDeleteBrokerCode + ":" + "Unable to delete broker controller")
}

func ErrReconcileBroker(err error) error {
return errors.New(ErrReconcileBrokerCode, errors.Alert, []string{"Error during broker resource reconciliation"}, []string{err.Error()}, []string{}, []string{})
return errors.New(ErrReconcileBrokerCode + ":" + "Error during broker resource reconciliation")
}

func ErrReconcileCR(err error) error {
return errors.New(ErrReconcileCRCode, errors.Alert, []string{"Error during custom resource reconciliation"}, []string{err.Error()}, []string{}, []string{})
return errors.New(ErrReconcileCRCode + ":" + "Error during custom resource reconciliation")
}

func ErrCheckHealth(err error) error {
return errors.New(ErrCheckHealthCode, errors.Alert, []string{"Error during health check"}, []string{err.Error()}, []string{}, []string{})
return errors.New(ErrCheckHealthCode + ":" + "Error during health check")
}

func ErrGetEndpoint(err error) error {
return errors.New(ErrGetEndpointCode, errors.Alert, []string{"Error getting endpoint"}, []string{err.Error()}, []string{}, []string{})
return errors.New(ErrGetEndpointCode + ":" + "Unable to get endpoint")
}

func ErrUpdateResource(err error) error {
return errors.New(ErrUpdateResourceCode, errors.Alert, []string{"Error updating resource"}, []string{err.Error()}, []string{}, []string{})
return errors.New(ErrUpdateResourceCode + ":" + "Unable to update resource")
}

func ErrMarshal(err error) error {
return errors.New(ErrMarshalCode + ":" + "Error during marshaling")
}
120 changes: 120 additions & 0 deletions controllers/error_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,120 @@
/*
Copyright 2023 Layer5, Inc.
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
http://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 controllers

import (
"errors"
"testing"
)

func TestErrGetMeshsync(t *testing.T) {
err := errors.New("test error")
if ErrGetMeshsync(err).Error() != "1001:Unable to get meshsync resource" {
t.Error("ErrGetMeshsync error")
}
}
func TestErrCreateMeshsync(t *testing.T) {
err := errors.New("test error")
if ErrCreateMeshsync(err).Error() != "1002:Unable to create meshsync controller" {
t.Error("ErrCreateMeshsync error")
}
}

func TestErrDeleteMeshsync(t *testing.T) {
err := errors.New("test error")
if ErrDeleteMeshsync(err).Error() != "1008:Unable to delete meshsync controller" {
t.Error("ErrDeleteMeshsync error")
}
}

func TestErrReconcileMeshsync(t *testing.T) {
err := errors.New("test error")
if ErrReconcileMeshsync(err).Error() != "1003:Error during meshsync resource reconciliation" {
t.Error("ErrReconcileMeshsync error")
}
}

// Test case for ErrGetBroker
func TestErrGetBroker(t *testing.T) {
err := errors.New("test error")
if ErrGetBroker(err).Error() != "1004:Broker resource not found" {
t.Error("ErrGetBroker error")
}
}

// Test case for ErrCreateBroker
func TestErrCreateBroker(t *testing.T) {
err := errors.New("test error")
if ErrCreateBroker(err).Error() != "1005:Unable to create broker controller" {
t.Error("ErrCreateBroker error")
}
}

// Test case for ErrDeleteBroker
func TestErrDeleteBroker(t *testing.T) {
err := errors.New("test error")
if ErrDeleteBroker(err).Error() != "1009:Unable to delete broker controller" {
t.Error("ErrDeleteBroker error")
}
}

// Test case for ErrReconcileBroker
func TestErrReconcileBroker(t *testing.T) {
err := errors.New("test error")
if ErrReconcileBroker(err).Error() != "1006:Error during broker resource reconciliation" {
t.Error("ErrReconcileBroker error")
}
}

// Test case for ErrReconcileCR
func TestErrReconcileCR(t *testing.T) {
err := errors.New("test error")
if ErrReconcileCR(err).Error() != "1007:Error during custom resource reconciliation" {
t.Error("ErrReconcileCR error")
}
}

// Test case for ErrCheckHealth
func TestErrCheckHealth(t *testing.T) {
err := errors.New("test error")
if ErrCheckHealth(err).Error() != "1010:Error during health check" {
t.Error("ErrCheckHealth error")
}
}

// Test case for ErrGetEndpoint
func TestErrGetEndpoint(t *testing.T) {
err := errors.New("test error")
if ErrGetEndpoint(err).Error() != "1011:Unable to get endpoint" {
t.Error("ErrGetEndpoint error")
}
}

// Test case for ErrUpdateResource
func TestErrUpdateResource(t *testing.T) {
err := errors.New("test error")
if ErrUpdateResource(err).Error() != "1012:Unable to update resource" {
t.Error("ErrUpdateResource error")
}
}

// Test case for ErrMarshal
func TestErrMarshal(t *testing.T) {
err := errors.New("test error")
if ErrMarshal(err).Error() != "11049:Error during marshaling" {
t.Error("ErrMarshal error")
}
}
2 changes: 1 addition & 1 deletion controllers/meshsync_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ import (
mesheryv1alpha1 "github.com/layer5io/meshery-operator/api/v1alpha1"
brokerpackage "github.com/layer5io/meshery-operator/pkg/broker"
meshsyncpackage "github.com/layer5io/meshery-operator/pkg/meshsync"
"github.com/layer5io/meshkit/utils"
"github.com/meshery/meshery-operator/pkg/utils"
kubeerror "k8s.io/apimachinery/pkg/api/errors"
types "k8s.io/apimachinery/pkg/types"
)
Expand Down
Loading

0 comments on commit dcc2130

Please sign in to comment.