Skip to content

Commit

Permalink
Move loadbalancer delete auth relationships into resolver (#230)
Browse files Browse the repository at this point in the history
* move loadbalancer delete auth relationships into resolver

Signed-off-by: Matt Siwiec <rizzza@users.noreply.github.com>

* bump to go 1.21 to get context.WithoutCancel

Signed-off-by: Matt Siwiec <rizzza@users.noreply.github.com>

* disable entc extension for generating hooks

Signed-off-by: Matt Siwiec <rizzza@users.noreply.github.com>

* use go 1.21 context.WithCancel for delete auth relationship

Signed-off-by: Matt Siwiec <rizzza@users.noreply.github.com>

* testcontainers bug fix, back to go.mod version

Signed-off-by: Matt Siwiec <rizzza@users.noreply.github.com>

---------

Signed-off-by: Matt Siwiec <rizzza@users.noreply.github.com>
  • Loading branch information
rizzza authored Oct 4, 2023
1 parent 7340843 commit 9935d1c
Show file tree
Hide file tree
Showing 9 changed files with 134 additions and 50 deletions.
2 changes: 2 additions & 0 deletions .devcontainer/.env
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ COCKROACH_URL="postgresql://root@crdb:26257/load_balancer_api_dev?sslmode=disabl
ATLAS_DB_URI="postgresql://root@crdb:26257/atlas_migrations?sslmode=disable"
LOADBALANCERAPI_CRDB_URI="postgresql://root@crdb:26257/load_balancer_api_dev?sslmode=disable"
LOADBALANCERAPI_EVENTS_NATS_CREDSFILE="/workspaces/load-balancer-api/.devcontainer/nsc/nkeys/creds/LOCAL/LBAAS/USER.creds"
LOADBALANCERAPI_EVENTS_NATS_PUBLISHPREFIX=com.infratographer
LOADBALANCERAPI_EVENTS_NATS_QUEUEGROUP=loadbalancerapi

NKEYS_PATH="/workspaces/load-balancer-api/.devcontainer/nsc/nkeys"
NSC_HOME="/workspaces/load-balancer-api/.devcontainer/nsc/nats"
Expand Down
4 changes: 3 additions & 1 deletion .devcontainer/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
ARG GO_VERSION=1.21

# Used to install CRDB into the devcontainer
FROM cockroachdb/cockroach:latest-v22.2 as CRDB

FROM mcr.microsoft.com/vscode/devcontainers/go:0-1.20-bullseye
FROM mcr.microsoft.com/vscode/devcontainers/go:1-${GO_VERSION}-bullseye

# Set up crdb
RUN mkdir /usr/local/lib/cockroach
Expand Down
4 changes: 1 addition & 3 deletions .github/workflows/test-go.yml
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,7 @@ jobs:
- name: Set up Go for ${{ matrix.ci-database }}
uses: actions/setup-go@v4
with:
#pinning to 1.20.5 until https://github.com/testcontainers/testcontainers-go/issues/1359 is resolved
#go-version-file: "go.mod"
go-version: "1.20.5"
go-version-file: "go.mod"
- name: Install atlas for db migrations on ${{ matrix.ci-database }}
run: go install ariga.io/atlas/cmd/atlas@latest

Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
module go.infratographer.com/load-balancer-api

go 1.20
go 1.21

require (
entgo.io/contrib v0.4.5
Expand Down
55 changes: 55 additions & 0 deletions go.sum

Large diffs are not rendered by default.

19 changes: 10 additions & 9 deletions internal/ent/entc.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,6 @@ import (
"entgo.io/ent/entc/gen"
"entgo.io/ent/schema/field"
"go.infratographer.com/x/entx"

"go.infratographer.com/load-balancer-api/x/pubsubinfo"
)

func main() {
Expand All @@ -24,12 +22,15 @@ func main() {
log.Fatalf("creating entx extension: %v", err)
}

pubsubExt, err := pubsubinfo.NewExtension(
pubsubinfo.WithEventHooks(),
)
if err != nil {
log.Fatalf("creating pubsubinfo extension: %v", err)
}
// load-balancer-api currently uses manual maintained hooks, however, if the schema changes, we'll need to enable the pubsubExt
// to re-generate the hooks and merge the generated changes with the manual hooks.

// pubsubExt, err := pubsubinfo.NewExtension(
// pubsubinfo.WithEventHooks(),
// )
// if err != nil {
// log.Fatalf("creating pubsubinfo extension: %v", err)
// }

gqlExt, err := entgql.NewExtension(
// Tell Ent to generate a GraphQL schema for
Expand All @@ -48,7 +49,7 @@ func main() {
entc.Extensions(
xExt,
gqlExt,
pubsubExt,
// pubsubExt,
),
entc.TemplateDir("./internal/ent/templates"),
entc.FeatureNames("intercept"),
Expand Down
21 changes: 13 additions & 8 deletions internal/graphapi/errors.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,19 @@ package graphapi

import "errors"

// ErrPortNumberInUse is returned when a port number is already in use.
var ErrPortNumberInUse = errors.New("port number already in use")
var (
// ErrPortNumberInUse is returned when a port number is already in use.
ErrPortNumberInUse = errors.New("port number already in use")

// ErrRestrictedPortNumber is returned when a port number is restricted.
var ErrRestrictedPortNumber = errors.New("port number restricted")
// ErrRestrictedPortNumber is returned when a port number is restricted.
ErrRestrictedPortNumber = errors.New("port number restricted")

// ErrPortNotFound is returned when one or more ports are not found
var ErrPortNotFound = errors.New("one or more ports not found")
// ErrPortNotFound is returned when one or more ports are not found
ErrPortNotFound = errors.New("one or more ports not found")

// ErrPoolNotFound is returned when one or more pools are not found
var ErrPoolNotFound = errors.New("one or more pools not found")
// ErrPoolNotFound is returned when one or more pools are not found
ErrPoolNotFound = errors.New("one or more pools not found")

// ErrInternalServerError is returned when an internal error occurs.
ErrInternalServerError = errors.New("internal server error")
)
72 changes: 49 additions & 23 deletions internal/graphapi/loadbalancer.resolvers.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 0 additions & 5 deletions internal/manualhooks/hooks.go
Original file line number Diff line number Diff line change
Expand Up @@ -252,11 +252,6 @@ func LoadBalancerHooks() []ent.Hook {

additionalSubjects = append(additionalSubjects, dbObj.OwnerID)

relationships = append(relationships, events.AuthRelationshipRelation{
Relation: "owner",
SubjectID: dbObj.OwnerID,
})

lbs := getLoadBalancerIDs(ctx, objID, additionalSubjects)
for _, lb := range lbs {
lb, err := m.Client().LoadBalancer.Get(ctx, lb)
Expand Down

0 comments on commit 9935d1c

Please sign in to comment.