Skip to content

Commit

Permalink
fix: linter
Browse files Browse the repository at this point in the history
  • Loading branch information
gllm-dev committed Mar 27, 2024
1 parent dc422f1 commit 6cdc0fd
Show file tree
Hide file tree
Showing 8 changed files with 214 additions and 30 deletions.
37 changes: 32 additions & 5 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -3,39 +3,66 @@ module go.openfort.xyz/shield
go 1.22.0

require (
cloud.google.com/go/cloudsqlconn v1.8.1
github.com/MicahParks/keyfunc/v3 v3.2.9
github.com/caarlos0/env/v10 v10.0.0
github.com/go-sql-driver/mysql v1.8.0
github.com/golang-jwt/jwt/v5 v5.2.1
github.com/google/uuid v1.6.0
github.com/google/wire v0.6.0
github.com/gorilla/mux v1.8.1
github.com/pressly/goose v2.7.0+incompatible
github.com/rs/cors v1.10.1
github.com/spf13/cobra v1.8.0
github.com/stretchr/testify v1.8.1
golang.org/x/crypto v0.18.0
github.com/stretchr/testify v1.8.4
golang.org/x/crypto v0.21.0
gorm.io/driver/mysql v1.5.5
gorm.io/driver/postgres v1.5.7
gorm.io/gorm v1.25.8
)

require (
cloud.google.com/go/compute v1.23.4 // indirect
cloud.google.com/go/compute/metadata v0.2.3 // indirect
filippo.io/edwards25519 v1.1.0 // indirect
github.com/MicahParks/jwkset v0.5.15 // indirect
github.com/davecgh/go-spew v1.1.1 // indirect
github.com/go-sql-driver/mysql v1.7.0 // indirect
github.com/felixge/httpsnoop v1.0.4 // indirect
github.com/go-logr/logr v1.4.1 // indirect
github.com/go-logr/stdr v1.2.2 // indirect
github.com/golang/groupcache v0.0.0-20210331224755-41bb18bfe9da // indirect
github.com/golang/protobuf v1.5.3 // indirect
github.com/google/s2a-go v0.1.7 // indirect
github.com/googleapis/enterprise-certificate-proxy v0.3.2 // indirect
github.com/googleapis/gax-go/v2 v2.12.2 // indirect
github.com/inconshreveable/mousetrap v1.1.0 // indirect
github.com/jackc/pgpassfile v1.0.0 // indirect
github.com/jackc/pgservicefile v0.0.0-20221227161230-091c0ba34f0a // indirect
github.com/jackc/pgx/v5 v5.4.3 // indirect
github.com/jackc/pgx/v5 v5.5.5 // indirect
github.com/jackc/puddle/v2 v2.2.1 // indirect
github.com/jinzhu/inflection v1.0.0 // indirect
github.com/jinzhu/now v1.1.5 // indirect
github.com/kr/text v0.2.0 // indirect
github.com/pkg/errors v0.9.1 // indirect
github.com/pmezard/go-difflib v1.0.0 // indirect
github.com/rogpeppe/go-internal v1.12.0 // indirect
github.com/rs/cors v1.10.1 // indirect
github.com/spf13/pflag v1.0.5 // indirect
github.com/stretchr/objx v0.5.0 // indirect
go.opencensus.io v0.24.0 // indirect
go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp v0.49.0 // indirect
go.opentelemetry.io/otel v1.24.0 // indirect
go.opentelemetry.io/otel/metric v1.24.0 // indirect
go.opentelemetry.io/otel/trace v1.24.0 // indirect
golang.org/x/net v0.22.0 // indirect
golang.org/x/oauth2 v0.18.0 // indirect
golang.org/x/sync v0.6.0 // indirect
golang.org/x/sys v0.18.0 // indirect
golang.org/x/text v0.14.0 // indirect
golang.org/x/time v0.5.0 // indirect
google.golang.org/api v0.169.0 // indirect
google.golang.org/appengine v1.6.8 // indirect
google.golang.org/genproto/googleapis/rpc v0.0.0-20240311173647-c811ad7063a7 // indirect
google.golang.org/grpc v1.62.1 // indirect
google.golang.org/protobuf v1.33.0 // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect
)
139 changes: 139 additions & 0 deletions go.sum

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -15,20 +15,20 @@ type MockProjectRepository struct {
var _ repositories.ProjectRepository = (*MockProjectRepository)(nil)

func (m *MockProjectRepository) Create(ctx context.Context, proj *project.Project) error {
args := m.Called(ctx, proj)
args := m.Mock.Called(ctx, proj)
return args.Error(0)
}

func (m *MockProjectRepository) Get(ctx context.Context, projectID string) (*project.Project, error) {
args := m.Called(ctx, projectID)
args := m.Mock.Called(ctx, projectID)
if args.Get(0) == nil {
return nil, args.Error(1)
}
return args.Get(0).(*project.Project), args.Error(1)
}

func (m *MockProjectRepository) GetByAPIKey(ctx context.Context, apiKey string) (*project.Project, error) {
args := m.Called(ctx, apiKey)
args := m.Mock.Called(ctx, apiKey)
if args.Get(0) == nil {
return nil, args.Error(1)
}
Expand Down
22 changes: 11 additions & 11 deletions internal/infrastructure/repositories/mocks/providermockrepo/repo.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,71 +15,71 @@ type MockProviderRepository struct {
var _ repositories.ProviderRepository = (*MockProviderRepository)(nil)

func (m *MockProviderRepository) Create(ctx context.Context, prov *provider.Provider) error {
args := m.Called(ctx, prov)
args := m.Mock.Called(ctx, prov)
return args.Error(0)
}

func (m *MockProviderRepository) GetByProjectAndType(ctx context.Context, projectID string, providerType provider.Type) (*provider.Provider, error) {
args := m.Called(ctx, projectID, providerType)
args := m.Mock.Called(ctx, projectID, providerType)
if args.Get(0) == nil {
return nil, args.Error(1)
}
return args.Get(0).(*provider.Provider), args.Error(1)
}

func (m *MockProviderRepository) Get(ctx context.Context, id string) (*provider.Provider, error) {
args := m.Called(ctx, id)
args := m.Mock.Called(ctx, id)
if args.Get(0) == nil {
return nil, args.Error(1)
}
return args.Get(0).(*provider.Provider), args.Error(1)
}

func (m *MockProviderRepository) List(ctx context.Context, projectID string) ([]*provider.Provider, error) {
args := m.Called(ctx, projectID)
args := m.Mock.Called(ctx, projectID)
if args.Get(0) == nil {
return nil, args.Error(1)
}
return args.Get(0).([]*provider.Provider), args.Error(1)
}

func (m *MockProviderRepository) Delete(ctx context.Context, providerID string) error {
args := m.Called(ctx, providerID)
args := m.Mock.Called(ctx, providerID)
return args.Error(0)
}

func (m *MockProviderRepository) CreateCustom(ctx context.Context, prov *provider.CustomConfig) error {
args := m.Called(ctx, prov)
args := m.Mock.Called(ctx, prov)
return args.Error(0)
}

func (m *MockProviderRepository) GetCustom(ctx context.Context, providerID string) (*provider.CustomConfig, error) {
args := m.Called(ctx, providerID)
args := m.Mock.Called(ctx, providerID)
if args.Get(0) == nil {
return nil, args.Error(1)
}
return args.Get(0).(*provider.CustomConfig), args.Error(1)
}

func (m *MockProviderRepository) UpdateCustom(ctx context.Context, prov *provider.CustomConfig) error {
args := m.Called(ctx, prov)
args := m.Mock.Called(ctx, prov)
return args.Error(0)
}

func (m *MockProviderRepository) CreateOpenfort(ctx context.Context, prov *provider.OpenfortConfig) error {
args := m.Called(ctx, prov)
args := m.Mock.Called(ctx, prov)
return args.Error(0)
}

func (m *MockProviderRepository) GetOpenfort(ctx context.Context, providerID string) (*provider.OpenfortConfig, error) {
args := m.Called(ctx, providerID)
args := m.Mock.Called(ctx, providerID)
if args.Get(0) == nil {
return nil, args.Error(1)
}
return args.Get(0).(*provider.OpenfortConfig), args.Error(1)
}

func (m *MockProviderRepository) UpdateOpenfort(ctx context.Context, prov *provider.OpenfortConfig) error {
args := m.Called(ctx, prov)
args := m.Mock.Called(ctx, prov)
return args.Error(0)
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,12 @@ type MockShareRepository struct {
var _ repositories.ShareRepository = (*MockShareRepository)(nil)

func (m *MockShareRepository) Create(ctx context.Context, shr *share.Share) error {
args := m.Called(ctx, shr)
args := m.Mock.Called(ctx, shr)
return args.Error(0)
}

func (m *MockShareRepository) GetByUserID(ctx context.Context, userID string) (*share.Share, error) {
args := m.Called(ctx, userID)
args := m.Mock.Called(ctx, userID)
if args.Get(0) == nil {
return nil, args.Error(1)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,27 +29,27 @@ func (m *MockUserRepository) WithProviderID(_ string) repositories.Option {
var _ repositories.UserRepository = (*MockUserRepository)(nil)

func (m *MockUserRepository) Create(ctx context.Context, usr *user.User) error {
args := m.Called(ctx, usr)
args := m.Mock.Called(ctx, usr)
return args.Error(0)
}

func (m *MockUserRepository) Get(ctx context.Context, userID string) (*user.User, error) {
args := m.Called(ctx, userID)
args := m.Mock.Called(ctx, userID)
if args.Get(0) == nil {
return nil, args.Error(1)
}
return args.Get(0).(*user.User), args.Error(1)
}

func (m *MockUserRepository) FindExternalBy(ctx context.Context, opts ...repositories.Option) ([]*user.ExternalUser, error) {
args := m.Called(ctx, opts)
args := m.Mock.Called(ctx, opts)
if args.Get(0) == nil {
return nil, args.Error(1)
}
return args.Get(0).([]*user.ExternalUser), args.Error(1)
}

func (m *MockUserRepository) CreateExternal(ctx context.Context, extUsr *user.ExternalUser) error {
args := m.Called(ctx, extUsr)
args := m.Mock.Called(ctx, extUsr)
return args.Error(0)
}
6 changes: 5 additions & 1 deletion internal/infrastructure/repositories/sql/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,11 @@ func newMySQL(cfg *Config) (*Client, error) {
}

func newCloudSQL(cfg *Config) (*Client, error) {
sqlDB, err := sql.Open("mysql", cfg.CloudSQLDSN())
dsn, err := cfg.CloudSQLDSN()
if err != nil {
return nil, err
}
sqlDB, err := sql.Open("mysql", dsn)
if err != nil {
return nil, err
}
Expand Down
22 changes: 18 additions & 4 deletions internal/infrastructure/repositories/sql/config.go
Original file line number Diff line number Diff line change
@@ -1,9 +1,13 @@
package sql

import (
"context"
"fmt"
"net"

"cloud.google.com/go/cloudsqlconn"
"github.com/caarlos0/env/v10"
"github.com/go-sql-driver/mysql"
)

type Config struct {
Expand All @@ -24,7 +28,7 @@ type Config struct {
TimeZone string `env:"DB_POSTGRES_TIME_ZONE" envDefault:"Europe/Madrid"`

// CloudSQL
InstanceHost string `env:"INSTANCE_HOST"`
InstanceConnectionName string `env:"INSTANCE_CONNECTION_NAME"`
}

const migrationDirectory = "internal/infrastructure/repositories/sql/migrations"
Expand All @@ -42,9 +46,19 @@ func (c *Config) MySQLDSN() string {
c.User, c.Pass, c.Host, c.Port, c.DBName, c.Charset, c.ParseTime, c.Location)
}

func (c *Config) CloudSQLDSN() string {
return fmt.Sprintf("%s:%s@tcp(%s:%d)/%s?parseTime=true",
c.User, c.Pass, c.InstanceHost, c.Port, c.DBName)
func (c *Config) CloudSQLDSN() (string, error) {
d, err := cloudsqlconn.NewDialer(context.Background())
if err != nil {
return "", fmt.Errorf("cloudsqlconn.NewDialer: %w", err)
}
var opts []cloudsqlconn.DialOption
mysql.RegisterDialContext("cloudsqlconn",
func(ctx context.Context, addr string) (net.Conn, error) { // nolint
return d.Dial(ctx, c.InstanceConnectionName, opts...)
})

return fmt.Sprintf("%s:%s@cloudsqlconn(localhost:3306)/%s?parseTime=true",
c.User, c.Pass, c.DBName), nil
}

func (c *Config) PostgresDSN() string {
Expand Down

0 comments on commit 6cdc0fd

Please sign in to comment.