Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Core db stubs and create flow #405

Draft
wants to merge 39 commits into
base: go-1.18
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from 33 commits
Commits
Show all changes
39 commits
Select commit Hold shift + click to select a range
abd986a
Add type for paginated data
neb42 May 8, 2022
67b71b2
Add function to perform validation on generic structs
neb42 May 8, 2022
bdf78c4
Add SQLBuilder
neb42 May 8, 2022
ebb2eea
Add TransactionStore
neb42 May 8, 2022
52ef1ee
Add helper methods for validation
neb42 May 8, 2022
bc80c11
Add migrations for entity tables
neb42 May 8, 2022
3f78da8
Add stubs for store layer
neb42 May 8, 2022
75aac31
Add stubs for service layer
neb42 May 8, 2022
6c12f46
Add stubs for controller layer
neb42 May 8, 2022
dc938fe
Add entity types
neb42 May 8, 2022
fc79757
Add core db server
neb42 May 8, 2022
92338a1
Implement InsertAttribute
neb42 May 8, 2022
c1eb3c5
Implement InsertEntityDefinition
neb42 May 8, 2022
644fa9a
Implement InsertRelationship
neb42 May 8, 2022
9396ead
Create EntityService.Create
neb42 May 8, 2022
2379599
Create EntityController.Create
neb42 May 8, 2022
1128b85
core-db config
neb42 May 8, 2022
5c18d87
Core DB configuration fixes
neb42 May 9, 2022
fa65c0f
Fix sql syntax
neb42 May 9, 2022
d044fdb
Add migrate command for core db
neb42 May 9, 2022
7b6903a
Use pointers to allow for null values
neb42 May 9, 2022
1b4bad9
Set schema
neb42 May 9, 2022
1476fb0
Set created entity id
neb42 May 9, 2022
b13fd19
Add attribute id to relationship
neb42 May 9, 2022
bb795e6
Fix
neb42 May 9, 2022
7b6e559
Add client to test things
neb42 May 9, 2022
9980740
Refactor logic into functions
neb42 May 9, 2022
f988fc4
Get db is tx is nil
neb42 May 9, 2022
c559f09
Rollback on error
neb42 May 9, 2022
fc6612c
Validate response
neb42 May 9, 2022
5f1b22a
Docs
neb42 May 9, 2022
e0b9ee5
Rename store to model
neb42 May 9, 2022
f5663be
Add transaction manager to docs
neb42 May 9, 2022
d082129
Add example without service layer
neb42 May 11, 2022
45e092c
Run go mod tidy
neb42 May 12, 2022
3bcc76e
Add function to setup postgres and dbfactory + cleanup
neb42 May 12, 2022
1f9e9bd
Add test suite for entity model
neb42 May 12, 2022
0f6af85
Add InsertEntityDefinition test
neb42 May 12, 2022
376a73f
Init entity model in suite
neb42 May 12, 2022
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 30 additions & 0 deletions cmd/devinit/core_db_api.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
package devinit

import (
"net"
"path"
)

func (c *Config) makeCoreDBApi() error {

var err error

c.coreDBApiTlsKey, err = getOrCreatePrivateKey(path.Join(CoreDBApiDir, "tls.key"))
if err != nil {
return err
}

c.coreDBApiTlsCert, err = getOrCreateServerCert(
path.Join(CoreDBApiDir, "tls.crt"),
c.coreDBApiTlsKey,
c.rootCa,
c.rootCaKey,
[]string{"localhost", "core.dev"},
[]net.IP{net.IPv6loopback, net.ParseIP("127.0.0.1")},
)
if err != nil {
return err
}

return nil
}
20 changes: 13 additions & 7 deletions cmd/devinit/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,14 @@ import (
"crypto/x509"
"encoding/json"
"fmt"
"github.com/dustinkirkland/golang-petname"
"math/rand"
"os"
"os/exec"
"path"
"path/filepath"
"time"

petname "github.com/dustinkirkland/golang-petname"
"github.com/manifoldco/promptui"
"github.com/nrc-no/core/pkg/api/types"
"github.com/nrc-no/core/pkg/server/options"
Expand All @@ -18,12 +25,6 @@ import (
"go.uber.org/zap"
"golang.org/x/sync/errgroup"
"gopkg.in/yaml.v3"
"math/rand"
"os"
"os/exec"
"path"
"path/filepath"
"time"
)

var (
Expand All @@ -36,6 +37,7 @@ var (
CoreAppFrontendDir string
CoreAdminFrontendDir string
CoreFormsApiDir string
CoreDBApiDir string
CoreAuthnzApiDir string
CoreAuthnzBouncerDir string
LoginDir string
Expand Down Expand Up @@ -130,6 +132,8 @@ type Config struct {
coreApiHashKey string
coreFormsApiTlsCert *x509.Certificate
coreFormsApiTlsKey *rsa.PrivateKey
coreDBApiTlsCert *x509.Certificate
coreDBApiTlsKey *rsa.PrivateKey
coreAppFrontendClientId string
coreAppFrontendTlsCert *x509.Certificate
coreAppFrontendTlsKey *rsa.PrivateKey
Expand Down Expand Up @@ -258,6 +262,7 @@ func createConfig() (*Config, error) {
config.makeLogin,
config.makeHydra,
config.makeCoreFormsApi,
config.makeCoreDBApi,
config.makeCoreAuthnzApi,
config.makeAppFrontend,
config.makeAdminFrontend,
Expand Down Expand Up @@ -460,6 +465,7 @@ func init() {
CoreAppFrontendDir = path.Join(CoreDir, "app_frontend")
CoreAdminFrontendDir = path.Join(CoreDir, "admin_frontend")
CoreFormsApiDir = path.Join(CoreDir, "forms_api")
CoreDBApiDir = path.Join(CoreDir, "core_db_api")
CoreAuthnzApiDir = path.Join(CoreDir, "authnz_api")
CoreAuthnzBouncerDir = path.Join(CoreDir, "authnz_bouncer")
}
5 changes: 5 additions & 0 deletions cmd/migrate.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package cmd

import (
"github.com/nrc-no/core/pkg/logging"
coreDBModel "github.com/nrc-no/core/pkg/server/core-db/models"
loginstore "github.com/nrc-no/core/pkg/server/login/store"
"github.com/nrc-no/core/pkg/store"
"github.com/spf13/cobra"
Expand Down Expand Up @@ -36,6 +37,10 @@ var migrateCmd = &cobra.Command{
l.Error("failed to migrate login store", zap.Error(err))
return err
}
if err := coreDBModel.Migrate(db); err != nil {
l.Error("failed to migrate core DB store", zap.Error(err))
return err
}
l.Info("successfully applied migrations")
return nil
},
Expand Down
8 changes: 8 additions & 0 deletions cmd/serve_all.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package cmd
import (
authnzapiserver "github.com/nrc-no/core/pkg/server/authnzapi"
"github.com/nrc-no/core/pkg/server/authnzbouncer"
coreDBServer "github.com/nrc-no/core/pkg/server/core-db"
formsapiserver "github.com/nrc-no/core/pkg/server/formsapi"
"github.com/nrc-no/core/pkg/server/login"
"github.com/spf13/cobra"
Expand All @@ -16,6 +17,13 @@ var serveAllCmd = &cobra.Command{
if err := initStoreFactory(); err != nil {
return err
}
if err := serveCoreDBApi(ctx,
coreDBServer.Options{
ServerOptions: coreOptions.Serve.CoreDBApi,
StoreFactory: factory,
}); err != nil {
return err
}
if err := serveFormsApi(ctx,
formsapiserver.Options{
ServerOptions: coreOptions.Serve.FormsApi,
Expand Down
40 changes: 40 additions & 0 deletions cmd/serve_core_db_api.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
package cmd

import (
"context"

coreDBServer "github.com/nrc-no/core/pkg/server/core-db"
"github.com/spf13/cobra"
)

var serveCoreDBCmd = &cobra.Command{
Use: "core-db-api",
Short: "starts the core-db-api server",
RunE: func(cmd *cobra.Command, args []string) error {
if err := initStoreFactory(); err != nil {
return err
}
if err := serveCoreDBApi(ctx,
coreDBServer.Options{
ServerOptions: coreOptions.Serve.CoreDBApi,
StoreFactory: factory,
}); err != nil {
return err
}
<-doneSignal
return nil
},
}

func init() {
serveCmd.AddCommand(serveCoreDBCmd)
}

func serveCoreDBApi(ctx context.Context, options coreDBServer.Options) error {
server, err := coreDBServer.NewServer(options)
if err != nil {
return err
}
server.Start(ctx)
return nil
}
30 changes: 30 additions & 0 deletions configs/config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,36 @@ serve:
enabled: true
exposed_headers:
- Location
core_db_api:
host: "0.0.0.0"
port: "9010"
tls:
enabled: true
cert:
path: creds/core/core_db_api/tls.crt
key:
path: creds/core/core_db_api/tls.key
cors:
allowed_origins:
- https://localhost:3000
- http://localhost:3000
- https://localhost:19006
- http://localhost:19006
allow_credentials: true
allowed_headers:
- Authorization
- Content-Type
- Accept
allowed_methods:
- "GET"
- "POST"
- "PUT"
- "OPTIONS"
- "DELETE"
debug: true
enabled: true
exposed_headers:
- Location
login:
host: "127.0.0.1"
port: "9002"
Expand Down
16 changes: 16 additions & 0 deletions deployments/envoy-local.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -225,6 +225,22 @@ static_resources:
name: envoy.transport_sockets.tls
typed_config:
"@type": type.googleapis.com/envoy.extensions.transport_sockets.tls.v3.UpstreamTlsContext
- name: core-db-api
type: STRICT_DNS
lb_policy: ROUND_ROBIN
load_assignment:
cluster_name: core-db-api
endpoints:
- lb_endpoints:
- endpoint:
address:
socket_address:
address: localhost
port_value: 9010
transport_socket:
name: envoy.transport_sockets.tls
typed_config:
"@type": type.googleapis.com/envoy.extensions.transport_sockets.tls.v3.UpstreamTlsContext
- name: core-admin-api
type: STRICT_DNS
lb_policy: ROUND_ROBIN
Expand Down
16 changes: 16 additions & 0 deletions deployments/envoy.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -225,6 +225,22 @@ static_resources:
name: envoy.transport_sockets.tls
typed_config:
"@type": type.googleapis.com/envoy.extensions.transport_sockets.tls.v3.UpstreamTlsContext
- name: core-db-api
type: STRICT_DNS
lb_policy: ROUND_ROBIN
load_assignment:
cluster_name: core-db-api
endpoints:
- lb_endpoints:
- endpoint:
address:
socket_address:
address: localhost
port_value: 9010
transport_socket:
name: envoy.transport_sockets.tls
typed_config:
"@type": type.googleapis.com/envoy.extensions.transport_sockets.tls.v3.UpstreamTlsContext
- name: core-admin-api
type: STRICT_DNS
lb_policy: ROUND_ROBIN
Expand Down
Loading