From 60d24be8f95757689a9d48896dd33e95d08b0ea2 Mon Sep 17 00:00:00 2001 From: Romain Dartigues Date: Wed, 15 May 2024 13:59:24 +0200 Subject: [PATCH 01/20] go vet: remove unreachable code --- decoder/decoder.go | 1 - 1 file changed, 1 deletion(-) diff --git a/decoder/decoder.go b/decoder/decoder.go index 29c5843..b34c93a 100644 --- a/decoder/decoder.go +++ b/decoder/decoder.go @@ -558,5 +558,4 @@ func convertStringValue(defVal string, vField reflect.Value) (interface{}, error } return defVal, nil } - return "", NewErrTypeNotSupported(vField) } From e5685bf9afcd5dbb8f932a23a5afcbac2822e0d6 Mon Sep 17 00:00:00 2001 From: Romain Dartigues Date: Wed, 15 May 2024 13:59:47 +0200 Subject: [PATCH 02/20] gofmt --- bin/doc-generator/doc-generator.go | 110 +++++++++--------- cloudenv/cloudenv.go | 2 +- cloudenv/env_var_cloudenv.go | 10 +- cloudenv/fake/fake_cloudenv.go | 10 +- connectors/all/init.go | 15 ++- connectors/amqp/init.go | 2 +- .../auth/config/oauth2/config_connector.go | 11 +- connectors/auth/init.go | 2 +- connectors/auth/raw/oauth2.go | 1 - connectors/connector.go | 8 +- connectors/connector_example_test.go | 32 ++--- connectors/databases/client/init.go | 4 +- .../client/mongodb/mongodb_connector.go | 8 +- .../databases/client/mssql/mssql_connector.go | 7 +- .../client/postgresql/postgresql_connector.go | 6 +- .../databases/client/redis/redis_connector.go | 8 +- connectors/databases/dbtype/type.go | 2 +- connectors/databases/gorm/init.go | 4 +- .../databases/gorm/mssql/mssql_connector.go | 9 +- .../databases/gorm/mysql/mysql_connector.go | 8 +- .../gorm/postgresql/postgresql_connector.go | 10 +- connectors/intercepter_example_test.go | 4 +- .../client/s3/goamz/aws_connector.go | 5 +- .../client/s3/minio/minio_connector.go | 6 +- connectors/objstorage/raw/s3_connector.go | 22 ++-- .../objstorage/raw/s3_connector_test.go | 62 +++++----- connectors/objstorage/schema/schema.go | 8 +- connectors/smtp/init.go | 3 +- connectors/smtp/raw/smtp_connector_test.go | 28 ++--- decoder/decoder.go | 17 +-- decoder/decoder_test.go | 8 +- decoder/errors.go | 2 +- default_loader.go | 1 + gautocloud_test.go | 2 +- interceptor/intercepter.go | 8 +- loader/errors.go | 6 +- loader/loader.go | 34 +++--- main.go | 30 +++-- mocked_loader.go | 1 + .../test_integration_suite_test.go | 4 +- test-mock/test_mock_suite_test.go | 1 + test-mock/test_mock_test.go | 5 +- test-utils/os_url_env.go | 2 +- 43 files changed, 272 insertions(+), 256 deletions(-) diff --git a/bin/doc-generator/doc-generator.go b/bin/doc-generator/doc-generator.go index 8eb9afa..0a5b740 100644 --- a/bin/doc-generator/doc-generator.go +++ b/bin/doc-generator/doc-generator.go @@ -1,16 +1,16 @@ package main import ( - "path" - "os" - . "github.com/cloudfoundry-community/gautocloud/test-utils" - _ "github.com/cloudfoundry-community/gautocloud/connectors/all" "github.com/cloudfoundry-community/gautocloud" + _ "github.com/cloudfoundry-community/gautocloud/connectors/all" + . "github.com/cloudfoundry-community/gautocloud/test-utils" "html/template" - "strings" + "os" + "path" "reflect" - "sort" "runtime" + "sort" + "strings" ) type DocStruct struct { @@ -55,26 +55,26 @@ type GlobalDoc struct { func before() { os.Setenv("MYSQL_URL", CreateEnvValue(ServiceUrl{ - Type: "mysql", - User: "user", + Type: "mysql", + User: "user", Password: "password", - Port: 3406, - Target: "mydb", + Port: 3406, + Target: "mydb", })) os.Setenv("POSTGRES_URL", CreateEnvValue(ServiceUrl{ - Type: "postgres", - User: "user", + Type: "postgres", + User: "user", Password: "password", - Port: 5532, - Target: "mydb", - Options: "sslmode=disable", + Port: 5532, + Target: "mydb", + Options: "sslmode=disable", })) os.Setenv("MSSQL_URL", CreateEnvValue(ServiceUrl{ - Type: "sqlserver", - User: "sa", + Type: "sqlserver", + User: "sa", Password: "password", - Port: 1433, - Target: "test", + Port: 1433, + Target: "test", })) os.Setenv("SSO_TOKEN_URI", "http://localhost/tokenUri") os.Setenv("SSO_AUTH_URI", "http://localhost/authUri") @@ -84,37 +84,37 @@ func before() { os.Setenv("SSO_GRANT_TYPE", "grant1,grant2") os.Setenv("SSO_SCOPES", "scope1,scope2") os.Setenv("MONGODB_URL", CreateEnvValue(ServiceUrl{ - Type: "mongo", - Port: 27017, + Type: "mongo", + Port: 27017, Target: "test", })) os.Setenv("ORACLE_URL", CreateEnvValue(ServiceUrl{ - Type: "oci", - Port: 27017, + Type: "oci", + Port: 27017, Target: "test", })) os.Setenv("REDIS_URL", CreateEnvValue(ServiceUrl{ - Type: "redis", - User: "redis", + Type: "redis", + User: "redis", Password: "redis", - Port: 6379, + Port: 6379, })) os.Setenv("AMQP_URL", CreateEnvValue(ServiceUrl{ - Type: "amqp", - User: "user", + Type: "amqp", + User: "user", Password: "password", - Port: 5672, + Port: 5672, })) os.Setenv("SMTP_URL", CreateEnvValue(ServiceUrl{ Type: "smtp", Port: 587, })) os.Setenv("S3_URL", CreateEnvValue(ServiceUrl{ - Type: "s3", - User: "accessKey1", + Type: "s3", + User: "accessKey1", Password: "verySecretKey1", - Port: 8090, - Target: "bucket", + Port: 8090, + Target: "bucket", })) gautocloud.ReloadConnectors() } @@ -129,7 +129,7 @@ func main() { docs := getDocMap() mk := make([]string, len(docs)) i := 0 - for k, _ := range docs { + for k := range docs { mk[i] = k i++ } @@ -141,21 +141,21 @@ func main() { summaries[index] = Summary{ Name: docs[key].Name, Slug: toSlug(docs[key].Name), - Sub: make([]Summary, 0), + Sub: make([]Summary, 0), } for _, docConn := range docs[key].Connectors { summary := summaries[index] summary.Sub = append(summary.Sub, Summary{ Name: docConn.Name, Slug: toSlug(docConn.Name), - Sub: make([]Summary, 0), + Sub: make([]Summary, 0), }) summaries[index] = summary } } gd := GlobalDoc{ DocsConnector: docSlice, - Summaries: summaries, + Summaries: summaries, } err = tmpl.Execute(os.Stdout, gd) fatalIf(err) @@ -168,13 +168,13 @@ func getDocMap() map[string]Doc { docs := make(map[string]Doc) for id, conn := range gautocloud.Connectors() { rootIdSplit := strings.Split(id, ":") - rootId := rootIdSplit[len(rootIdSplit) - 1] + rootId := rootIdSplit[len(rootIdSplit)-1] if _, ok := docs[rootId]; !ok { docs[rootId] = Doc{ - Name: strings.Title(rootId), + Name: strings.Title(rootId), RespondName: conn.Name(), RespondTags: conn.Tags(), - Connectors: make([]DocConnector, 0), + Connectors: make([]DocConnector, 0), } } connType := reflect.TypeOf(conn).Elem() @@ -201,7 +201,7 @@ func getDocMap() map[string]Doc { typeWrapped := "" if givenValue.NumField() == 1 { typeShortSplit := strings.Split(givenValue.Field(0).Type().String(), ".") - typeShort := typeShortSplit[len(typeShortSplit) - 1] + typeShort := typeShortSplit[len(typeShortSplit)-1] if len(typeShortSplit) > 1 && typeShort == givenValue.Type().Field(0).Name { typeField := givenValue.Field(0).Type() if typeField.Kind() == reflect.Ptr { @@ -223,18 +223,18 @@ func getDocMap() map[string]Doc { globalType = pkgSplit[4] } connDoc := DocConnector{ - Name: strings.Title(rootId + " - " + connName), - Id: conn.Id(), - Pkg: pkgConn, - TypeName: givenType.String(), - TypePkg: giventTypePkg.PkgPath(), + Name: strings.Title(rootId + " - " + connName), + Id: conn.Id(), + Pkg: pkgConn, + TypeName: givenType.String(), + TypePkg: giventTypePkg.PkgPath(), TypeWrapped: typeWrapped, - DocUrl: docUrl, - Tip: tip, - GlobalType: strings.Title(globalType), - SimpleName: strings.Title(connName), + DocUrl: docUrl, + Tip: tip, + GlobalType: strings.Title(globalType), + SimpleName: strings.Title(connName), StructGiven: generateDocStruct(givenData), - Closeable: isCloseable(givenData), + Closeable: isCloseable(givenData), } doc := docs[rootId] connectors := append(doc.Connectors, connDoc) @@ -284,7 +284,7 @@ func generateDocStruct(data interface{}) DocStruct { nameSplit := strings.Split(givenType.String(), ".") structGiven := DocStruct{ - Name: nameSplit[len(nameSplit) - 1], + Name: nameSplit[len(nameSplit)-1], } fields := make([]DocField, 0) v := reflect.ValueOf(data) @@ -304,8 +304,8 @@ func generateDocStruct(data interface{}) DocStruct { docUrl = "See doc: " + docUrl } fields = append(fields, DocField{ - Name: tField.Name, - Type: vField.Type().String(), + Name: tField.Name, + Type: vField.Type().String(), Comment: docUrl, }) } @@ -326,4 +326,4 @@ func (d DocConnectors) Less(i, j int) bool { } func (d DocConnectors) Swap(i, j int) { d[i], d[j] = d[j], d[i] -} \ No newline at end of file +} diff --git a/cloudenv/cloudenv.go b/cloudenv/cloudenv.go index 97b3dfc..be6536d 100644 --- a/cloudenv/cloudenv.go +++ b/cloudenv/cloudenv.go @@ -1,4 +1,4 @@ -// It manages the detection of the environment but also the detections of services asked by a Loader. +// It manages the detection of the environment but also the detections of services asked by a Loader. package cloudenv import "regexp" diff --git a/cloudenv/env_var_cloudenv.go b/cloudenv/env_var_cloudenv.go index 2ada446..079f78d 100644 --- a/cloudenv/env_var_cloudenv.go +++ b/cloudenv/env_var_cloudenv.go @@ -1,10 +1,10 @@ package cloudenv import ( + "bytes" + "encoding/json" "os" "strings" - "encoding/json" - "bytes" ) type EnvVarCloudEnv struct { @@ -33,20 +33,20 @@ func (c *EnvVarCloudEnv) InitEnv(environ []string) { for _, envVar := range environ { splitEnv := strings.Split(envVar, "=") envVars = append(envVars, EnvVar{ - Key: strings.ToLower(splitEnv[0]), + Key: strings.ToLower(splitEnv[0]), Value: strings.TrimSpace(strings.Join(splitEnv[1:], "=")), }) } c.envVars = envVars } -func (c EnvVarCloudEnv) GetServicesFromTags(tags []string) ([]Service) { +func (c EnvVarCloudEnv) GetServicesFromTags(tags []string) []Service { services := make([]Service, 0) for _, tag := range tags { services = append(services, c.getServicesFromPrefix(tag)...) } return services } -func (c EnvVarCloudEnv) GetServicesFromName(name string) ([]Service) { +func (c EnvVarCloudEnv) GetServicesFromName(name string) []Service { return c.getServicesFromPrefix(name) } func (c EnvVarCloudEnv) getServicesFromPrefix(prefix string) []Service { diff --git a/cloudenv/fake/fake_cloudenv.go b/cloudenv/fake/fake_cloudenv.go index 0baf5e4..996f45b 100644 --- a/cloudenv/fake/fake_cloudenv.go +++ b/cloudenv/fake/fake_cloudenv.go @@ -13,18 +13,18 @@ type FakeCloudEnv struct { func NewFakeCloudEnv() cloudenv.CloudEnv { return &FakeCloudEnv{ - services: make([]cloudenv.Service, 0), + services: make([]cloudenv.Service, 0), inCloudEnv: true, - callLoad: 0, + callLoad: 0, } } func (c FakeCloudEnv) Name() string { return "fakecloudenv" } -func (c FakeCloudEnv) GetServicesFromTags(tags []string) ([]cloudenv.Service) { +func (c FakeCloudEnv) GetServicesFromTags(tags []string) []cloudenv.Service { return c.services } -func (c FakeCloudEnv) GetServicesFromName(name string) ([]cloudenv.Service) { +func (c FakeCloudEnv) GetServicesFromName(name string) []cloudenv.Service { return c.services } func (c *FakeCloudEnv) SetAppInfo(appInfo cloudenv.AppInfo) { @@ -51,4 +51,4 @@ func (c *FakeCloudEnv) Load() error { } func (c FakeCloudEnv) GetAppInfo() cloudenv.AppInfo { return c.appInfo -} \ No newline at end of file +} diff --git a/connectors/all/init.go b/connectors/all/init.go index b03d074..885091f 100644 --- a/connectors/all/init.go +++ b/connectors/all/init.go @@ -1,16 +1,15 @@ package all import ( - _ "github.com/cloudfoundry-community/gautocloud/connectors/databases/gorm" - _ "github.com/cloudfoundry-community/gautocloud/connectors/databases" - _ "github.com/cloudfoundry-community/gautocloud/connectors/databases/client" _ "github.com/cloudfoundry-community/gautocloud/connectors/amqp" _ "github.com/cloudfoundry-community/gautocloud/connectors/amqp/client" - _ "github.com/cloudfoundry-community/gautocloud/connectors/smtp" - _ "github.com/cloudfoundry-community/gautocloud/connectors/smtp/client" - _ "github.com/cloudfoundry-community/gautocloud/connectors/objstorage" - _ "github.com/cloudfoundry-community/gautocloud/connectors/objstorage/client" _ "github.com/cloudfoundry-community/gautocloud/connectors/auth" _ "github.com/cloudfoundry-community/gautocloud/connectors/auth/config" + _ "github.com/cloudfoundry-community/gautocloud/connectors/databases" + _ "github.com/cloudfoundry-community/gautocloud/connectors/databases/client" + _ "github.com/cloudfoundry-community/gautocloud/connectors/databases/gorm" + _ "github.com/cloudfoundry-community/gautocloud/connectors/objstorage" + _ "github.com/cloudfoundry-community/gautocloud/connectors/objstorage/client" + _ "github.com/cloudfoundry-community/gautocloud/connectors/smtp" + _ "github.com/cloudfoundry-community/gautocloud/connectors/smtp/client" ) - diff --git a/connectors/amqp/init.go b/connectors/amqp/init.go index dc1c4f0..0a74a51 100644 --- a/connectors/amqp/init.go +++ b/connectors/amqp/init.go @@ -2,8 +2,8 @@ package amqp import ( "github.com/cloudfoundry-community/gautocloud" - "github.com/cloudfoundry-community/gautocloud/connectors/amqp/raw" _ "github.com/cloudfoundry-community/gautocloud/connectors/amqp/client" + "github.com/cloudfoundry-community/gautocloud/connectors/amqp/raw" ) func init() { diff --git a/connectors/auth/config/oauth2/config_connector.go b/connectors/auth/config/oauth2/config_connector.go index 4d1740d..0d06ec0 100644 --- a/connectors/auth/config/oauth2/config_connector.go +++ b/connectors/auth/config/oauth2/config_connector.go @@ -1,11 +1,11 @@ package oauth2 import ( + "github.com/cloudfoundry-community/gautocloud" "github.com/cloudfoundry-community/gautocloud/connectors" "github.com/cloudfoundry-community/gautocloud/connectors/auth/raw" - "github.com/cloudfoundry-community/gautocloud" - "golang.org/x/oauth2" . "github.com/cloudfoundry-community/gautocloud/connectors/auth/schema" + "golang.org/x/oauth2" ) func init() { @@ -37,11 +37,11 @@ func (c Oauth2ConfigConnector) Load(schema interface{}) (interface{}, error) { } fSchema := schema.(Oauth2Schema) config := &oauth2.Config{ - ClientID: fSchema.ClientId, + ClientID: fSchema.ClientId, ClientSecret: fSchema.ClientSecret, - Scopes: fSchema.Scopes, + Scopes: fSchema.Scopes, Endpoint: oauth2.Endpoint{ - AuthURL: fSchema.AuthorizationUri, + AuthURL: fSchema.AuthorizationUri, TokenURL: fSchema.TokenUri, }, } @@ -50,4 +50,3 @@ func (c Oauth2ConfigConnector) Load(schema interface{}) (interface{}, error) { func (c Oauth2ConfigConnector) Schema() interface{} { return c.rawConn.Schema() } - diff --git a/connectors/auth/init.go b/connectors/auth/init.go index ae3128f..52027bc 100644 --- a/connectors/auth/init.go +++ b/connectors/auth/init.go @@ -7,4 +7,4 @@ import ( func init() { gautocloud.RegisterConnector(raw.NewOauth2RawConnector()) -} \ No newline at end of file +} diff --git a/connectors/auth/raw/oauth2.go b/connectors/auth/raw/oauth2.go index fc7af17..28e6f7b 100644 --- a/connectors/auth/raw/oauth2.go +++ b/connectors/auth/raw/oauth2.go @@ -25,4 +25,3 @@ func (c Oauth2RawConnector) Load(schema interface{}) (interface{}, error) { func (c Oauth2RawConnector) Schema() interface{} { return Oauth2Schema{} } - diff --git a/connectors/connector.go b/connectors/connector.go index d441698..5e261d8 100644 --- a/connectors/connector.go +++ b/connectors/connector.go @@ -6,9 +6,11 @@ import "github.com/cloudfoundry-community/gautocloud/interceptor" // this is the interface to be implemented to create a new connector // You should add an init function in the same package of your connector and register it automatically in gautocloud when importing your connector // Example of init function: -// func init() { -// gautocloud.RegisterConnector(NewMyConnector()) -// } +// +// func init() { +// gautocloud.RegisterConnector(NewMyConnector()) +// } +// // see implementation of any raw connectors to see how to implement a connector type Connector interface { // This is the id of your connector and it must be unique and not have the same id of another connector diff --git a/connectors/connector_example_test.go b/connectors/connector_example_test.go index 497dab8..3995c73 100644 --- a/connectors/connector_example_test.go +++ b/connectors/connector_example_test.go @@ -1,27 +1,28 @@ package connectors_test import ( + "github.com/cloudfoundry-community/gautocloud" "github.com/cloudfoundry-community/gautocloud/connectors" "github.com/cloudfoundry-community/gautocloud/decoder" - "github.com/cloudfoundry-community/gautocloud" ) -//an init function in the same package of your connector and register it automatically in gautocloud when importing your connector + +// an init function in the same package of your connector and register it automatically in gautocloud when importing your connector func init() { gautocloud.RegisterConnector(NewExampleConnector()) } type ExampleSchema struct { // ServiceUri is a special type. Decoder will expect an uri as a value and will give a ServiceUri - Uri decoder.ServiceUri + Uri decoder.ServiceUri // note: by default if you don't provide a cloud tag the key will be the field name in snake_case - Name string `cloud:"name"` - Host string `cloud:"host"` + Name string `cloud:"name"` + Host string `cloud:"host"` // by passing `regex` in cloud tag it will say to decoder that the expected key must be match the regex - User string `cloud:".*user.*,regex"` + User string `cloud:".*user.*,regex"` // by passing `default=avalue` decoder will understand that if the key is not found it must fill the field with this value Password string `cloud:".*user.*,regex,default=apassword"` // you can also pass a slice - Aslice []string `cloud:"aslice,default=value1,value2"` + Aslice []string `cloud:"aslice,default=value1,value2"` } type ExampleTypeOutput struct { Host string @@ -34,22 +35,26 @@ type ExampleConnector struct{} func NewExampleConnector() connectors.Connector { return &ExampleConnector{} } + // This is the id of your connector and it must be unique and not have the same id of another connector // Note: if a connector id is already taken gautocloud will complain func (c ExampleConnector) Id() string { return "example" } + // Name is the name of a service to lookup in the cloud environment // Note: a regex can be passed func (c ExampleConnector) Name() string { return ".*example.*" } + // This should return a list of tags which designed what kind of service you want // example: mysql, database, rmdb ... // Note: a regex can be passed on each tag func (c ExampleConnector) Tags() []string { return []string{"example", "doc.*"} } + // The parameter is a filled schema you gave in the function Schema // The first value to return is what you want and you have no obligation to give always the same type. gautocloud is interface agnostic // You can give an error if an error occurred, this error will appear in logs @@ -57,19 +62,20 @@ func (c ExampleConnector) Load(schema interface{}) (interface{}, error) { fSchema := schema.(ExampleSchema) if fSchema.Uri.Host != "" { return ExampleTypeOutput{ - Host: fSchema.Uri.Host, - Name: fSchema.Uri.Name, - User: fSchema.Uri.Username, + Host: fSchema.Uri.Host, + Name: fSchema.Uri.Name, + User: fSchema.Uri.Username, Password: fSchema.Uri.Password, }, nil } return ExampleTypeOutput{ - Host: fSchema.Host, - Name: fSchema.Name, - User: fSchema.User, + Host: fSchema.Host, + Name: fSchema.Name, + User: fSchema.User, Password: fSchema.Password, }, nil } + // It must return a structure // this structure will be used by the decoder to create a structure of the same type and filled // with service's credentials found by a cloud environment diff --git a/connectors/databases/client/init.go b/connectors/databases/client/init.go index b42f3b6..dd52397 100644 --- a/connectors/databases/client/init.go +++ b/connectors/databases/client/init.go @@ -1,9 +1,9 @@ package client import ( + _ "github.com/cloudfoundry-community/gautocloud/connectors/databases/client/mongodb" + _ "github.com/cloudfoundry-community/gautocloud/connectors/databases/client/mssql" _ "github.com/cloudfoundry-community/gautocloud/connectors/databases/client/mysql" _ "github.com/cloudfoundry-community/gautocloud/connectors/databases/client/postgresql" - _ "github.com/cloudfoundry-community/gautocloud/connectors/databases/client/mssql" - _ "github.com/cloudfoundry-community/gautocloud/connectors/databases/client/mongodb" _ "github.com/cloudfoundry-community/gautocloud/connectors/databases/client/redis" ) diff --git a/connectors/databases/client/mongodb/mongodb_connector.go b/connectors/databases/client/mongodb/mongodb_connector.go index 3e7cbad..34c4a28 100644 --- a/connectors/databases/client/mongodb/mongodb_connector.go +++ b/connectors/databases/client/mongodb/mongodb_connector.go @@ -1,12 +1,12 @@ package mongodb import ( - "github.com/cloudfoundry-community/gautocloud/connectors" - "github.com/cloudfoundry-community/gautocloud/connectors/databases/raw" - "gopkg.in/mgo.v2" "fmt" "github.com/cloudfoundry-community/gautocloud" + "github.com/cloudfoundry-community/gautocloud/connectors" "github.com/cloudfoundry-community/gautocloud/connectors/databases/dbtype" + "github.com/cloudfoundry-community/gautocloud/connectors/databases/raw" + "gopkg.in/mgo.v2" ) func init() { @@ -58,5 +58,3 @@ func (c MongodbConnector) Load(schema interface{}) (interface{}, error) { func (c MongodbConnector) Schema() interface{} { return c.rawConn.Schema() } - - diff --git a/connectors/databases/client/mssql/mssql_connector.go b/connectors/databases/client/mssql/mssql_connector.go index 93b0961..c53c0a2 100644 --- a/connectors/databases/client/mssql/mssql_connector.go +++ b/connectors/databases/client/mssql/mssql_connector.go @@ -1,13 +1,13 @@ package mssql import ( - "github.com/cloudfoundry-community/gautocloud/connectors" - "github.com/cloudfoundry-community/gautocloud/connectors/databases/raw" - _ "github.com/denisenkom/go-mssqldb" "database/sql" "fmt" "github.com/cloudfoundry-community/gautocloud" + "github.com/cloudfoundry-community/gautocloud/connectors" "github.com/cloudfoundry-community/gautocloud/connectors/databases/dbtype" + "github.com/cloudfoundry-community/gautocloud/connectors/databases/raw" + _ "github.com/denisenkom/go-mssqldb" ) func init() { @@ -57,4 +57,3 @@ func (c MssqlConnector) Load(schema interface{}) (interface{}, error) { func (c MssqlConnector) Schema() interface{} { return c.rawConn.Schema() } - diff --git a/connectors/databases/client/postgresql/postgresql_connector.go b/connectors/databases/client/postgresql/postgresql_connector.go index dd46c1e..c8ba7c7 100644 --- a/connectors/databases/client/postgresql/postgresql_connector.go +++ b/connectors/databases/client/postgresql/postgresql_connector.go @@ -1,13 +1,13 @@ package postgresql import ( - "github.com/cloudfoundry-community/gautocloud/connectors" - "github.com/cloudfoundry-community/gautocloud/connectors/databases/raw" - _ "github.com/lib/pq" "database/sql" "fmt" "github.com/cloudfoundry-community/gautocloud" + "github.com/cloudfoundry-community/gautocloud/connectors" "github.com/cloudfoundry-community/gautocloud/connectors/databases/dbtype" + "github.com/cloudfoundry-community/gautocloud/connectors/databases/raw" + _ "github.com/lib/pq" ) func init() { diff --git a/connectors/databases/client/redis/redis_connector.go b/connectors/databases/client/redis/redis_connector.go index a1f7185..fb7741b 100644 --- a/connectors/databases/client/redis/redis_connector.go +++ b/connectors/databases/client/redis/redis_connector.go @@ -1,12 +1,12 @@ package redis import ( + "github.com/cloudfoundry-community/gautocloud" "github.com/cloudfoundry-community/gautocloud/connectors" + "github.com/cloudfoundry-community/gautocloud/connectors/databases/dbtype" "github.com/cloudfoundry-community/gautocloud/connectors/databases/raw" "github.com/go-redis/redis/v7" - "github.com/cloudfoundry-community/gautocloud" "strconv" - "github.com/cloudfoundry-community/gautocloud/connectors/databases/dbtype" ) func init() { @@ -41,12 +41,10 @@ func (c RedisConnector) Load(schema interface{}) (interface{}, error) { } fSchema := schema.(dbtype.RedisDatabase) return redis.NewClient(&redis.Options{ - Addr: c.GetConnString(fSchema), + Addr: c.GetConnString(fSchema), Password: fSchema.Password, }), nil } func (c RedisConnector) Schema() interface{} { return c.rawConn.Schema() } - - diff --git a/connectors/databases/dbtype/type.go b/connectors/databases/dbtype/type.go index 04086d5..7a38c33 100644 --- a/connectors/databases/dbtype/type.go +++ b/connectors/databases/dbtype/type.go @@ -59,4 +59,4 @@ type RedisDatabase struct { Password string Host string Port int -} \ No newline at end of file +} diff --git a/connectors/databases/gorm/init.go b/connectors/databases/gorm/init.go index 01d3e08..ea11d0e 100644 --- a/connectors/databases/gorm/init.go +++ b/connectors/databases/gorm/init.go @@ -1,7 +1,7 @@ package gorm import ( + _ "github.com/cloudfoundry-community/gautocloud/connectors/databases/gorm/mssql" _ "github.com/cloudfoundry-community/gautocloud/connectors/databases/gorm/mysql" _ "github.com/cloudfoundry-community/gautocloud/connectors/databases/gorm/postgresql" - _ "github.com/cloudfoundry-community/gautocloud/connectors/databases/gorm/mssql" -) \ No newline at end of file +) diff --git a/connectors/databases/gorm/mssql/mssql_connector.go b/connectors/databases/gorm/mssql/mssql_connector.go index c738d2b..30da978 100644 --- a/connectors/databases/gorm/mssql/mssql_connector.go +++ b/connectors/databases/gorm/mssql/mssql_connector.go @@ -1,13 +1,13 @@ package mssql import ( - "github.com/cloudfoundry-community/gautocloud/connectors" "github.com/cloudfoundry-community/gautocloud" - "github.com/jinzhu/gorm" - _ "github.com/jinzhu/gorm/dialects/mssql" + "github.com/cloudfoundry-community/gautocloud/connectors" "github.com/cloudfoundry-community/gautocloud/connectors/databases/client/mssql" "github.com/cloudfoundry-community/gautocloud/connectors/databases/dbtype" "github.com/cloudfoundry-community/gautocloud/connectors/databases/raw" + "github.com/jinzhu/gorm" + _ "github.com/jinzhu/gorm/dialects/mssql" ) func init() { @@ -21,7 +21,7 @@ type GormMssqlConnector struct { func NewGormMssqlConnector() connectors.Connector { return &GormMssqlConnector{ - wrapConn: mssql.NewMssqlConnector(), + wrapConn: mssql.NewMssqlConnector(), wrapRawConn: raw.NewMssqlRawConnector(), } } @@ -49,4 +49,3 @@ func (c GormMssqlConnector) Load(schema interface{}) (interface{}, error) { func (c GormMssqlConnector) Schema() interface{} { return c.wrapConn.Schema() } - diff --git a/connectors/databases/gorm/mysql/mysql_connector.go b/connectors/databases/gorm/mysql/mysql_connector.go index 792e863..6857087 100644 --- a/connectors/databases/gorm/mysql/mysql_connector.go +++ b/connectors/databases/gorm/mysql/mysql_connector.go @@ -1,13 +1,13 @@ package mysql import ( - "github.com/cloudfoundry-community/gautocloud/connectors" "github.com/cloudfoundry-community/gautocloud" - "github.com/jinzhu/gorm" - _ "github.com/jinzhu/gorm/dialects/mysql" + "github.com/cloudfoundry-community/gautocloud/connectors" "github.com/cloudfoundry-community/gautocloud/connectors/databases/client/mysql" "github.com/cloudfoundry-community/gautocloud/connectors/databases/dbtype" "github.com/cloudfoundry-community/gautocloud/connectors/databases/raw" + "github.com/jinzhu/gorm" + _ "github.com/jinzhu/gorm/dialects/mysql" ) func init() { @@ -21,7 +21,7 @@ type GormMysqlConnector struct { func NewGormMysqlConnector() connectors.Connector { return &GormMysqlConnector{ - wrapConn: mysql.NewMysqlConnector(), + wrapConn: mysql.NewMysqlConnector(), wrapRawConn: raw.NewMysqlRawConnector(), } } diff --git a/connectors/databases/gorm/postgresql/postgresql_connector.go b/connectors/databases/gorm/postgresql/postgresql_connector.go index 569094a..a148e8e 100644 --- a/connectors/databases/gorm/postgresql/postgresql_connector.go +++ b/connectors/databases/gorm/postgresql/postgresql_connector.go @@ -1,14 +1,14 @@ package postgresql import ( - "github.com/cloudfoundry-community/gautocloud/connectors" - _ "github.com/lib/pq" "github.com/cloudfoundry-community/gautocloud" - _ "github.com/jinzhu/gorm/dialects/postgres" - "github.com/jinzhu/gorm" + "github.com/cloudfoundry-community/gautocloud/connectors" "github.com/cloudfoundry-community/gautocloud/connectors/databases/client/postgresql" "github.com/cloudfoundry-community/gautocloud/connectors/databases/dbtype" "github.com/cloudfoundry-community/gautocloud/connectors/databases/raw" + "github.com/jinzhu/gorm" + _ "github.com/jinzhu/gorm/dialects/postgres" + _ "github.com/lib/pq" ) func init() { @@ -22,7 +22,7 @@ type GormPostgresqlConnector struct { func NewGormPostgresqlConnector() connectors.Connector { return &GormPostgresqlConnector{ - wrapConn: postgresql.NewPostgresqlConnector(), + wrapConn: postgresql.NewPostgresqlConnector(), wrapRawConn: raw.NewPostgresqlRawConnector(), } } diff --git a/connectors/intercepter_example_test.go b/connectors/intercepter_example_test.go index 2ef54dd..812e4d8 100644 --- a/connectors/intercepter_example_test.go +++ b/connectors/intercepter_example_test.go @@ -7,7 +7,7 @@ import ( "github.com/cloudfoundry-community/gautocloud/interceptor" ) -//an init function in the same package of your connector and register it automatically in gautocloud when importing your connector +// an init function in the same package of your connector and register it automatically in gautocloud when importing your connector func init() { gautocloud.RegisterConnector(NewExampleConnector()) } @@ -39,7 +39,7 @@ func NewExampleIntercepterConnector() connectors.Connector { // this can be nil if user doesn't use Inject functions from gautocloud. // -// Found is interface found by gautocloud +// # Found is interface found by gautocloud // // It should return an interface which must be the same type as found. // Tips: current and found have always the same type, this type is the type given by connector from its function Schema() diff --git a/connectors/objstorage/client/s3/goamz/aws_connector.go b/connectors/objstorage/client/s3/goamz/aws_connector.go index 637908c..fd54584 100644 --- a/connectors/objstorage/client/s3/goamz/aws_connector.go +++ b/connectors/objstorage/client/s3/goamz/aws_connector.go @@ -1,12 +1,12 @@ package aws_sdk import ( + "github.com/cloudfoundry-community/gautocloud" "github.com/cloudfoundry-community/gautocloud/connectors" "github.com/cloudfoundry-community/gautocloud/connectors/objstorage/objstoretype" - "github.com/cloudfoundry-community/gautocloud" "github.com/cloudfoundry-community/gautocloud/connectors/objstorage/raw" - "github.com/goamz/goamz/s3" "github.com/goamz/goamz/aws" + "github.com/goamz/goamz/s3" "strconv" ) @@ -59,4 +59,3 @@ func (c AmzS3Connector) Load(schema interface{}) (interface{}, error) { func (c AmzS3Connector) Schema() interface{} { return c.wrapConn.Schema() } - diff --git a/connectors/objstorage/client/s3/minio/minio_connector.go b/connectors/objstorage/client/s3/minio/minio_connector.go index d55c79d..b7fddf6 100644 --- a/connectors/objstorage/client/s3/minio/minio_connector.go +++ b/connectors/objstorage/client/s3/minio/minio_connector.go @@ -3,11 +3,11 @@ package minio import ( "github.com/cloudfoundry-community/gautocloud" "github.com/cloudfoundry-community/gautocloud/connectors" - "github.com/cloudfoundry-community/gautocloud/connectors/objstorage/raw" "github.com/cloudfoundry-community/gautocloud/connectors/objstorage/objstoretype" + "github.com/cloudfoundry-community/gautocloud/connectors/objstorage/objstoretype/miniotype" + "github.com/cloudfoundry-community/gautocloud/connectors/objstorage/raw" "github.com/minio/minio-go" "strconv" - "github.com/cloudfoundry-community/gautocloud/connectors/objstorage/objstoretype/miniotype" ) func init() { @@ -42,7 +42,7 @@ func (c MinioConnector) Load(schema interface{}) (interface{}, error) { if fSchema.Port != 0 { port += ":" + strconv.Itoa(fSchema.Port) } - minioClient, err := minio.New(fSchema.Host + port, fSchema.AccessKeyID, fSchema.SecretAccessKey, fSchema.UseSsl) + minioClient, err := minio.New(fSchema.Host+port, fSchema.AccessKeyID, fSchema.SecretAccessKey, fSchema.UseSsl) if err != nil { return nil, err } diff --git a/connectors/objstorage/raw/s3_connector.go b/connectors/objstorage/raw/s3_connector.go index b67a6db..fb6b996 100644 --- a/connectors/objstorage/raw/s3_connector.go +++ b/connectors/objstorage/raw/s3_connector.go @@ -2,8 +2,8 @@ package raw import ( "github.com/cloudfoundry-community/gautocloud/connectors" - . "github.com/cloudfoundry-community/gautocloud/connectors/objstorage/schema" "github.com/cloudfoundry-community/gautocloud/connectors/objstorage/objstoretype" + . "github.com/cloudfoundry-community/gautocloud/connectors/objstorage/schema" "strings" ) @@ -45,21 +45,21 @@ func (c S3RawConnector) Load(schema interface{}) (interface{}, error) { useSsl = true } return objstoretype.S3{ - Host: fSchema.Uri.Host, - AccessKeyID: fSchema.Uri.Username, + Host: fSchema.Uri.Host, + AccessKeyID: fSchema.Uri.Username, SecretAccessKey: fSchema.Uri.Password, - Bucket: fSchema.Uri.Name, - UseSsl: useSsl, - Port: fSchema.Uri.Port, + Bucket: fSchema.Uri.Name, + UseSsl: useSsl, + Port: fSchema.Uri.Port, }, nil } gSchema = objstoretype.S3{ - Host: fSchema.Host, - AccessKeyID: fSchema.AccessKeyID, + Host: fSchema.Host, + AccessKeyID: fSchema.AccessKeyID, SecretAccessKey: fSchema.SecretAccessKey, - Bucket: fSchema.Bucket, - Port: fSchema.Port, - UseSsl: true, + Bucket: fSchema.Bucket, + Port: fSchema.Port, + UseSsl: true, } if c.IsVirtualHostBucket(gSchema) { host, bucket := c.GetBucketFromHost(gSchema.Host) diff --git a/connectors/objstorage/raw/s3_connector_test.go b/connectors/objstorage/raw/s3_connector_test.go index 17113f3..476b15e 100644 --- a/connectors/objstorage/raw/s3_connector_test.go +++ b/connectors/objstorage/raw/s3_connector_test.go @@ -3,12 +3,12 @@ package raw_test import ( . "github.com/cloudfoundry-community/gautocloud/connectors/objstorage/raw" - . "github.com/onsi/ginkgo" - . "github.com/onsi/gomega" "github.com/cloudfoundry-community/gautocloud/connectors" - "github.com/cloudfoundry-community/gautocloud/decoder" - "github.com/cloudfoundry-community/gautocloud/connectors/objstorage/schema" "github.com/cloudfoundry-community/gautocloud/connectors/objstorage/objstoretype" + "github.com/cloudfoundry-community/gautocloud/connectors/objstorage/schema" + "github.com/cloudfoundry-community/gautocloud/decoder" + . "github.com/onsi/ginkgo" + . "github.com/onsi/gomega" ) var _ = Describe("S3Connector", func() { @@ -18,19 +18,19 @@ var _ = Describe("S3Connector", func() { }) It("Should return a S3 struct when passing a S3Schema without uri", func() { data, err := connector.Load(schema.S3Schema{ - Host: "localhost", + Host: "localhost", SecretAccessKey: "pass", - AccessKeyID: "user", - Bucket: "bucket", + AccessKeyID: "user", + Bucket: "bucket", }) Expect(err).NotTo(HaveOccurred()) Expect(data).Should(BeEquivalentTo( objstoretype.S3{ - Host: "localhost", + Host: "localhost", SecretAccessKey: "pass", - AccessKeyID: "user", - Bucket: "bucket", - UseSsl: true, + AccessKeyID: "user", + Bucket: "bucket", + UseSsl: true, }, )) }) @@ -38,20 +38,20 @@ var _ = Describe("S3Connector", func() { It("Should return a S3 struct when passing a S3Schema", func() { data, err := connector.Load(schema.S3Schema{ Uri: decoder.ServiceUri{ - Scheme: "http", - Host: "localhost", + Scheme: "http", + Host: "localhost", Username: "user", Password: "pass", - Name: "bucket", + Name: "bucket", }, }) Expect(err).NotTo(HaveOccurred()) Expect(data).Should(BeEquivalentTo( objstoretype.S3{ - Host: "localhost", + Host: "localhost", SecretAccessKey: "pass", - AccessKeyID: "user", - Bucket: "bucket", + AccessKeyID: "user", + Bucket: "bucket", }, )) }) @@ -60,42 +60,42 @@ var _ = Describe("S3Connector", func() { It("Should return a S3 struct when passing a S3Schema with scheme https", func() { data, err := connector.Load(schema.S3Schema{ Uri: decoder.ServiceUri{ - Scheme: "https", - Host: "localhost", + Scheme: "https", + Host: "localhost", Username: "user", Password: "pass", - Name: "bucket", + Name: "bucket", }, }) Expect(err).NotTo(HaveOccurred()) Expect(data).Should(BeEquivalentTo( objstoretype.S3{ - Host: "localhost", + Host: "localhost", SecretAccessKey: "pass", - AccessKeyID: "user", - Bucket: "bucket", - UseSsl: true, + AccessKeyID: "user", + Bucket: "bucket", + UseSsl: true, }, )) }) It("Should return a S3 struct when passing a S3Schema with scheme s3", func() { data, err := connector.Load(schema.S3Schema{ Uri: decoder.ServiceUri{ - Scheme: "s3", - Host: "localhost", + Scheme: "s3", + Host: "localhost", Username: "user", Password: "pass", - Name: "bucket", + Name: "bucket", }, }) Expect(err).NotTo(HaveOccurred()) Expect(data).Should(BeEquivalentTo( objstoretype.S3{ - Host: "localhost", + Host: "localhost", SecretAccessKey: "pass", - AccessKeyID: "user", - Bucket: "bucket", - UseSsl: true, + AccessKeyID: "user", + Bucket: "bucket", + UseSsl: true, }, )) }) diff --git a/connectors/objstorage/schema/schema.go b/connectors/objstorage/schema/schema.go index 6287f2b..31af8d1 100644 --- a/connectors/objstorage/schema/schema.go +++ b/connectors/objstorage/schema/schema.go @@ -4,9 +4,9 @@ import "github.com/cloudfoundry-community/gautocloud/decoder" type S3Schema struct { Uri decoder.ServiceUri `cloud:"ur(i|l),regex"` - Host string `cloud:".*host.*,regex"` - AccessKeyID string `cloud:"(.*user.*|access.*),regex"` - SecretAccessKey string `cloud:"(.*pass.*|secret.*),regex"` - Bucket string `cloud:".*(bucket|name).*,regex"` + Host string `cloud:".*host.*,regex"` + AccessKeyID string `cloud:"(.*user.*|access.*),regex"` + SecretAccessKey string `cloud:"(.*pass.*|secret.*),regex"` + Bucket string `cloud:".*(bucket|name).*,regex"` Port int } diff --git a/connectors/smtp/init.go b/connectors/smtp/init.go index df71ed9..5f2ee79 100644 --- a/connectors/smtp/init.go +++ b/connectors/smtp/init.go @@ -2,11 +2,10 @@ package smtp import ( "github.com/cloudfoundry-community/gautocloud" - "github.com/cloudfoundry-community/gautocloud/connectors/smtp/raw" _ "github.com/cloudfoundry-community/gautocloud/connectors/smtp/client" + "github.com/cloudfoundry-community/gautocloud/connectors/smtp/raw" ) func init() { gautocloud.RegisterConnector(raw.NewSmtpRawConnector()) } - diff --git a/connectors/smtp/raw/smtp_connector_test.go b/connectors/smtp/raw/smtp_connector_test.go index b915675..e3af1a4 100644 --- a/connectors/smtp/raw/smtp_connector_test.go +++ b/connectors/smtp/raw/smtp_connector_test.go @@ -3,12 +3,12 @@ package raw_test import ( . "github.com/cloudfoundry-community/gautocloud/connectors/smtp/raw" - . "github.com/onsi/ginkgo" - . "github.com/onsi/gomega" - "github.com/cloudfoundry-community/gautocloud/decoder" "github.com/cloudfoundry-community/gautocloud/connectors" "github.com/cloudfoundry-community/gautocloud/connectors/smtp/schema" "github.com/cloudfoundry-community/gautocloud/connectors/smtp/smtptype" + "github.com/cloudfoundry-community/gautocloud/decoder" + . "github.com/onsi/ginkgo" + . "github.com/onsi/gomega" ) var _ = Describe("SmtpConnector", func() { @@ -18,37 +18,37 @@ var _ = Describe("SmtpConnector", func() { }) It("Should return a Smtp struct when passing a SmtpSchema without uri", func() { data, err := connector.Load(schema.SmtpSchema{ - Host: "localhost", + Host: "localhost", Password: "pass", - User: "user", - Port: 3306, + User: "user", + Port: 3306, }) Expect(err).NotTo(HaveOccurred()) Expect(data).Should(BeEquivalentTo( smtptype.Smtp{ - Host: "localhost", + Host: "localhost", Password: "pass", - User: "user", - Port: 3306, + User: "user", + Port: 3306, }, )) }) It("Should return a Smtp struct when passing a SmtpSchema with an uri", func() { data, err := connector.Load(schema.SmtpSchema{ Uri: decoder.ServiceUri{ - Host: "localhost", + Host: "localhost", Username: "user", Password: "pass", - Port: 3306, + Port: 3306, }, }) Expect(err).NotTo(HaveOccurred()) Expect(data).Should(BeEquivalentTo( smtptype.Smtp{ - Host: "localhost", + Host: "localhost", Password: "pass", - User: "user", - Port: 3306, + User: "user", + Port: 3306, }, )) }) diff --git a/decoder/decoder.go b/decoder/decoder.go index b34c93a..bfc6ea4 100644 --- a/decoder/decoder.go +++ b/decoder/decoder.go @@ -2,13 +2,14 @@ // It provide a cloud tag to help user match the correct credentials // // This is what you can pass as a structure: -// // Name is key of a service credentials, decoder will look at any matching credentials which have the key name and will pass the value of this credentials -// Name string `cloud:"name"` // note: by default if you don't provide a cloud tag the key will be the field name in snake_case -// Uri decoder.ServiceUri // ServiceUri is a special type. Decoder will expect an uri as a value and will give a ServiceUri -// User string `cloud:".*user.*,regex"` // by passing `regex` in cloud tag it will say to decoder that the expected key must be match the regex -// Password string `cloud:".*user.*,regex" cloud-default:"apassword"` // by passing a tag named `cloud-default` decoder will understand that if the key is not found it must fill the field with this value -// Aslice []string `cloud:"aslice" cloud-default:"value1,value2"` // you can also pass a slice -// } +// +// // Name is key of a service credentials, decoder will look at any matching credentials which have the key name and will pass the value of this credentials +// Name string `cloud:"name"` // note: by default if you don't provide a cloud tag the key will be the field name in snake_case +// Uri decoder.ServiceUri // ServiceUri is a special type. Decoder will expect an uri as a value and will give a ServiceUri +// User string `cloud:".*user.*,regex"` // by passing `regex` in cloud tag it will say to decoder that the expected key must be match the regex +// Password string `cloud:".*user.*,regex" cloud-default:"apassword"` // by passing a tag named `cloud-default` decoder will understand that if the key is not found it must fill the field with this value +// Aslice []string `cloud:"aslice" cloud-default:"value1,value2"` // you can also pass a slice +// } package decoder import ( @@ -411,7 +412,7 @@ func match(matcher, content string) bool { return regex.MatchString(content) } func getKeyFromRegex(serviceCredentials map[string]interface{}, regexKey string) string { - for key, _ := range serviceCredentials { + for key := range serviceCredentials { if match(regexKey, key) { return key } diff --git a/decoder/decoder_test.go b/decoder/decoder_test.go index 7f2576b..fcdf9e9 100644 --- a/decoder/decoder_test.go +++ b/decoder/decoder_test.go @@ -87,7 +87,7 @@ var _ = Describe("Decoder", func() { Name: "data", Password: "pass", Port: 12, - Query: []QueryUri{QueryUri{ + Query: []QueryUri{{ Key: "options", Value: "1", }}, @@ -151,7 +151,7 @@ var _ = Describe("Decoder", func() { "nuint": uint(6), "amap": map[string]interface{}{"name": "name"}, "asubstruct": map[string]interface{}{"name": "subname"}, - "slicesubstruct": []map[string]interface{}{map[string]interface{}{"name": "name"}}, + "slicesubstruct": []map[string]interface{}{{"name": "name"}}, "aslice": []string{"titi", "toto"}, "nuint8": uint8(7), "nuint16": uint16(8), @@ -211,7 +211,7 @@ var _ = Describe("Decoder", func() { "nint64": "5", "nuint": "6", "amap": map[string]interface{}{"name": "name"}, - "slicesubstruct": []map[string]interface{}{map[string]interface{}{"name": "name"}}, + "slicesubstruct": []map[string]interface{}{{"name": "name"}}, "float_json_number": json.Number("0.12e+1"), "int_json_number": json.Number("2"), "aslice": "titi, toto", @@ -301,7 +301,7 @@ var _ = Describe("Decoder", func() { "int_json_number": json.Number("2"), "amap": map[string]interface{}{"name": "name"}, "asubstruct": map[string]interface{}{"name": "subname"}, - "slicesubstruct": []map[string]interface{}{map[string]interface{}{"name": "name"}}, + "slicesubstruct": []map[string]interface{}{{"name": "name"}}, "aslice": []string{"titi", "toto"}, "nuint8": float64(7), "nuint16": float32(8), diff --git a/decoder/errors.go b/decoder/errors.go index 024dd00..0d53bbd 100644 --- a/decoder/errors.go +++ b/decoder/errors.go @@ -1,8 +1,8 @@ package decoder import ( - "reflect" "fmt" + "reflect" ) type ErrTypeNotSupported struct { diff --git a/default_loader.go b/default_loader.go index c445f8d..28b87d7 100644 --- a/default_loader.go +++ b/default_loader.go @@ -1,3 +1,4 @@ +//go:build !gautocloud_mock // +build !gautocloud_mock package gautocloud diff --git a/gautocloud_test.go b/gautocloud_test.go index 023e0cb..1e92ae0 100644 --- a/gautocloud_test.go +++ b/gautocloud_test.go @@ -3,9 +3,9 @@ package gautocloud_test import ( . "github.com/cloudfoundry-community/gautocloud" + "github.com/cloudfoundry-community/gautocloud/cloudenv" . "github.com/onsi/ginkgo" . "github.com/onsi/gomega" - "github.com/cloudfoundry-community/gautocloud/cloudenv" ) var _ = Describe("Gautocloud", func() { diff --git a/interceptor/intercepter.go b/interceptor/intercepter.go index b99579c..89affc9 100644 --- a/interceptor/intercepter.go +++ b/interceptor/intercepter.go @@ -1,8 +1,10 @@ // This permit to intercept data which will be given back by gautocloud and modified it before giving back to user. // Interceptor should be used in a connector, to do so, connector have to implement ConnectorIntercepter: -// type ConnectorIntercepter interface { -// Intercepter() interceptor.Intercepter -// } +// +// type ConnectorIntercepter interface { +// Intercepter() interceptor.Intercepter +// } +// // An interceptor work like a http middleware. package interceptor diff --git a/loader/errors.go b/loader/errors.go index 5b67af2..88e1168 100644 --- a/loader/errors.go +++ b/loader/errors.go @@ -1,17 +1,15 @@ package loader import ( - "strings" "fmt" + "strings" ) type ErrPtrNotGiven struct { } func NewErrPtrNotGiven() error { - return ErrPtrNotGiven{ - - } + return ErrPtrNotGiven{} } func (e ErrPtrNotGiven) Error() string { return "You must pass a pointer." diff --git a/loader/loader.go b/loader/loader.go index 9c05a14..95b273c 100644 --- a/loader/loader.go +++ b/loader/loader.go @@ -157,9 +157,11 @@ func (l *GautocloudLoader) ReloadConnectors() { // Inject service(s) found by connectors with given type // Example: -// var svc *dbtype.MysqlDB -// err = loader.Inject(&svc) -// // svc will have the value of the first service found with type *dbtype.MysqlDB +// +// var svc *dbtype.MysqlDB +// err = loader.Inject(&svc) +// // svc will have the value of the first service found with type *dbtype.MysqlDB +// // If service parameter is not a slice it will give the first service found // If you pass a slice of a type in service parameter, it will inject in the slice all services found with this type // It returns an error if parameter is not a pointer or if no service(s) can be found @@ -169,7 +171,7 @@ func (l GautocloudLoader) Inject(service interface{}) error { return err } notFound := true - for id, _ := range l.connectors { + for id := range l.connectors { err = l.InjectFromId(id, service) if err == nil && service != nil { notFound = false @@ -236,9 +238,11 @@ func (l GautocloudLoader) getFirstValidCloudEnv() cloudenv.CloudEnv { // Inject service(s) found by a connector with given type // id is the id of a connector // Example: -// var svc *dbtype.MysqlDB -// err = gautocloud.InjectFromId("mysql", &svc) -// // svc will have the value of the first service found with type *dbtype.MysqlDB in this case +// +// var svc *dbtype.MysqlDB +// err = gautocloud.InjectFromId("mysql", &svc) +// // svc will have the value of the first service found with type *dbtype.MysqlDB in this case +// // If service parameter is not a slice it will give the first service found // If you pass a slice of a type in service parameter, it will inject in the slice all services found with this type // It returns an error if service parameter is not a pointer, if no service(s) can be found and if connector with given id doesn't exist @@ -329,9 +333,11 @@ func (l GautocloudLoader) getData(store StoredService, current interface{}) (int // Return the first service found by a connector // id is the id of a connector // Example: -// var svc *dbtype.MysqlDB -// data, err = gautocloud.GetFirst("mysql") -// svc = data.(*dbtype.MysqlDB) +// +// var svc *dbtype.MysqlDB +// data, err = gautocloud.GetFirst("mysql") +// svc = data.(*dbtype.MysqlDB) +// // It returns the first service found or an error if no service can be found or if the connector doesn't exists func (l GautocloudLoader) GetFirst(id string) (interface{}, error) { err := l.checkInCloudEnv() @@ -361,9 +367,11 @@ func (l GautocloudLoader) checkConnectorIdExist(id string) error { // Return all services found by a connector // id is the id of a connector // Example: -// var svc []interface{} -// data, err = gautocloud.GetAll("mysql") -// svc = data[0].(*dbtype.MysqlDB) +// +// var svc []interface{} +// data, err = gautocloud.GetAll("mysql") +// svc = data[0].(*dbtype.MysqlDB) +// // warning: a connector may give you different types that's why GetAll return a slice of interface{} // It returns the first service found or an error if no service can be found or if the connector doesn't exists func (l GautocloudLoader) GetAll(id string) ([]interface{}, error) { diff --git a/main.go b/main.go index 8a97d4e..db191bc 100644 --- a/main.go +++ b/main.go @@ -24,9 +24,11 @@ func RegisterConnector(connector connectors.Connector) { // Inject service(s) found by connectors with given type // Example: -// var svc *dbtype.MysqlDB -// err = gautocloud.Inject(&svc) -// // svc will have the value of the first service found with type *dbtype.MysqlDB +// +// var svc *dbtype.MysqlDB +// err = gautocloud.Inject(&svc) +// // svc will have the value of the first service found with type *dbtype.MysqlDB +// // If service parameter is not a slice it will give the first service found // If you pass a slice of a type in service parameter, it will inject in the slice all services found with this type // It returns an error if parameter is not a pointer or if no service(s) can be found @@ -37,9 +39,11 @@ func Inject(service interface{}) error { // Inject service(s) found by a connector with given type // id is the id of a connector // Example: -// var svc *dbtype.MysqlDB -// err = gautocloud.InjectFromId("mysql", &svc) -// // svc will have the value of the first service found with type *dbtype.MysqlDB in this case +// +// var svc *dbtype.MysqlDB +// err = gautocloud.InjectFromId("mysql", &svc) +// // svc will have the value of the first service found with type *dbtype.MysqlDB in this case +// // If service parameter is not a slice it will give the first service found // If you pass a slice of a type in service parameter, it will inject in the slice all services found with this type // It returns an error if service parameter is not a pointer, if no service(s) can be found and if connector with given id doesn't exist @@ -50,9 +54,10 @@ func InjectFromId(id string, service interface{}) error { // Return the first service found by a connector // id is the id of a connector // Example: -// var svc *dbtype.MysqlDB -// data, err = gautocloud.GetFirst("mysql") -// svc = data.(*dbtype.MysqlDB) +// +// var svc *dbtype.MysqlDB +// data, err = gautocloud.GetFirst("mysql") +// svc = data.(*dbtype.MysqlDB) // // It returns the first service found or an error if no service can be found or if the connector doesn't exists func GetFirst(id string) (interface{}, error) { @@ -62,9 +67,10 @@ func GetFirst(id string) (interface{}, error) { // Return all services found by a connector // id is the id of a connector // Example: -// var svc []interface{} -// data, err = gautocloud.GetAll("mysql") -// svc = data[0].(*dbtype.MysqlDB) +// +// var svc []interface{} +// data, err = gautocloud.GetAll("mysql") +// svc = data[0].(*dbtype.MysqlDB) // // warning: a connector may give you different types that's why GetAll return a slice of interface{} // It returns the first service found or an error if no service can be found or if the connector doesn't exists diff --git a/mocked_loader.go b/mocked_loader.go index d493b74..4a75436 100644 --- a/mocked_loader.go +++ b/mocked_loader.go @@ -1,3 +1,4 @@ +//go:build gautocloud_mock // +build gautocloud_mock package gautocloud diff --git a/test-integration/test_integration_suite_test.go b/test-integration/test_integration_suite_test.go index c250297..26031b3 100644 --- a/test-integration/test_integration_suite_test.go +++ b/test-integration/test_integration_suite_test.go @@ -4,9 +4,9 @@ import ( . "github.com/onsi/ginkgo" . "github.com/onsi/gomega" - "testing" - "os" "fmt" + "os" + "testing" ) func TestTestIntegration(t *testing.T) { diff --git a/test-mock/test_mock_suite_test.go b/test-mock/test_mock_suite_test.go index 9035700..9419442 100644 --- a/test-mock/test_mock_suite_test.go +++ b/test-mock/test_mock_suite_test.go @@ -1,3 +1,4 @@ +//go:build gautocloud_mock // +build gautocloud_mock package test_mock_test diff --git a/test-mock/test_mock_test.go b/test-mock/test_mock_test.go index 7d51368..994e915 100644 --- a/test-mock/test_mock_test.go +++ b/test-mock/test_mock_test.go @@ -1,13 +1,14 @@ +//go:build gautocloud_mock // +build gautocloud_mock package test_mock_test import ( - . "github.com/onsi/ginkgo" - . "github.com/onsi/gomega" "github.com/cloudfoundry-community/gautocloud" "github.com/cloudfoundry-community/gautocloud/loader/fake" "github.com/golang/mock/gomock" + . "github.com/onsi/ginkgo" + . "github.com/onsi/gomega" ) type FakeService struct { diff --git a/test-utils/os_url_env.go b/test-utils/os_url_env.go index b807130..87c811f 100644 --- a/test-utils/os_url_env.go +++ b/test-utils/os_url_env.go @@ -1,8 +1,8 @@ package test_utils import ( - "strconv" "os" + "strconv" ) type ServiceUrl struct { From 460a1f56174bc0b00b263b18db429b17547af4a0 Mon Sep 17 00:00:00 2001 From: Romain Dartigues Date: Wed, 15 May 2024 14:01:19 +0200 Subject: [PATCH 03/20] go vet: struct literal uses unkeyed fields --- connectors/databases/client/mssql/mssql_connector.go | 2 +- connectors/databases/client/mysql/mysql_connector.go | 2 +- connectors/databases/client/postgresql/postgresql_connector.go | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/connectors/databases/client/mssql/mssql_connector.go b/connectors/databases/client/mssql/mssql_connector.go index c53c0a2..3f6d3fe 100644 --- a/connectors/databases/client/mssql/mssql_connector.go +++ b/connectors/databases/client/mssql/mssql_connector.go @@ -52,7 +52,7 @@ func (c MssqlConnector) Load(schema interface{}) (interface{}, error) { if err != nil { return db, err } - return &dbtype.MssqlDB{db}, nil + return &dbtype.MssqlDB{DB: db}, nil } func (c MssqlConnector) Schema() interface{} { return c.rawConn.Schema() diff --git a/connectors/databases/client/mysql/mysql_connector.go b/connectors/databases/client/mysql/mysql_connector.go index 38f1ec9..10304f7 100644 --- a/connectors/databases/client/mysql/mysql_connector.go +++ b/connectors/databases/client/mysql/mysql_connector.go @@ -80,7 +80,7 @@ func (c MysqlConnector) Load(schema interface{}) (interface{}, error) { if err != nil { return db, err } - return &dbtype.MysqlDB{db}, nil + return &dbtype.MysqlDB{DB: db}, nil } func (c MysqlConnector) Schema() interface{} { return c.mysqlRawConn.Schema() diff --git a/connectors/databases/client/postgresql/postgresql_connector.go b/connectors/databases/client/postgresql/postgresql_connector.go index c8ba7c7..fd16536 100644 --- a/connectors/databases/client/postgresql/postgresql_connector.go +++ b/connectors/databases/client/postgresql/postgresql_connector.go @@ -52,7 +52,7 @@ func (c PostgresqlConnector) Load(schema interface{}) (interface{}, error) { if err != nil { return db, err } - return &dbtype.PostgresqlDB{db}, nil + return &dbtype.PostgresqlDB{DB: db}, nil } func (c PostgresqlConnector) Schema() interface{} { return c.rawConn.Schema() From 11c10d6c3597b1e681a6ef75db8b36fee5227491 Mon Sep 17 00:00:00 2001 From: Romain Dartigues Date: Wed, 15 May 2024 14:18:53 +0200 Subject: [PATCH 04/20] CI: enable dependabot --- .github/dependabot.yml | 14 ++++++++++++++ 1 file changed, 14 insertions(+) create mode 100644 .github/dependabot.yml diff --git a/.github/dependabot.yml b/.github/dependabot.yml new file mode 100644 index 0000000..22dcd86 --- /dev/null +++ b/.github/dependabot.yml @@ -0,0 +1,14 @@ +# Please see the documentation for all configuration options: +# https://help.github.com/github/administering-a-repository/configuration-options-for-dependency-updates + +version: 2 +updates: + - package-ecosystem: "gomod" + directory: "/" + schedule: + interval: "weekly" + + - package-ecosystem: "github-actions" + directory: "/" + schedule: + interval: "weekly" From 67bae21f74ce58400c1fdc3f56a56ac36bce6724 Mon Sep 17 00:00:00 2001 From: Romain Dartigues Date: Wed, 15 May 2024 14:07:23 +0200 Subject: [PATCH 05/20] CI: enable CodeQL --- .github/workflows/codeql.yml | 93 ++++++++++++++++++++++++++++++++++++ 1 file changed, 93 insertions(+) create mode 100644 .github/workflows/codeql.yml diff --git a/.github/workflows/codeql.yml b/.github/workflows/codeql.yml new file mode 100644 index 0000000..5a26d92 --- /dev/null +++ b/.github/workflows/codeql.yml @@ -0,0 +1,93 @@ +# For most projects, this workflow file will not need changing; you simply need +# to commit it to your repository. +# +# You may wish to alter this file to override the set of languages analyzed, +# or to provide custom queries or build logic. +# +# ******** NOTE ******** +# We have attempted to detect the languages in your repository. Please check +# the `language` matrix defined below to confirm you have the correct set of +# supported CodeQL languages. +# +name: "CodeQL" + +on: + push: + branches: [ "master" ] + pull_request: + branches: [ "master" ] + schedule: + - cron: '20 9 * * 6' + +jobs: + analyze: + name: Analyze (${{ matrix.language }}) + # Runner size impacts CodeQL analysis time. To learn more, please see: + # - https://gh.io/recommended-hardware-resources-for-running-codeql + # - https://gh.io/supported-runners-and-hardware-resources + # - https://gh.io/using-larger-runners (GitHub.com only) + # Consider using larger runners or machines with greater resources for possible analysis time improvements. + runs-on: ${{ (matrix.language == 'swift' && 'macos-latest') || 'ubuntu-latest' }} + timeout-minutes: ${{ (matrix.language == 'swift' && 120) || 360 }} + permissions: + # required for all workflows + security-events: write + + # required to fetch internal or private CodeQL packs + packages: read + + # only required for workflows in private repositories + actions: read + contents: read + + strategy: + fail-fast: false + matrix: + include: + - language: go + build-mode: autobuild + # CodeQL supports the following values keywords for 'language': 'c-cpp', 'csharp', 'go', 'java-kotlin', 'javascript-typescript', 'python', 'ruby', 'swift' + # Use `c-cpp` to analyze code written in C, C++ or both + # Use 'java-kotlin' to analyze code written in Java, Kotlin or both + # Use 'javascript-typescript' to analyze code written in JavaScript, TypeScript or both + # To learn more about changing the languages that are analyzed or customizing the build mode for your analysis, + # see https://docs.github.com/en/code-security/code-scanning/creating-an-advanced-setup-for-code-scanning/customizing-your-advanced-setup-for-code-scanning. + # If you are analyzing a compiled language, you can modify the 'build-mode' for that language to customize how + # your codebase is analyzed, see https://docs.github.com/en/code-security/code-scanning/creating-an-advanced-setup-for-code-scanning/codeql-code-scanning-for-compiled-languages + steps: + - name: Checkout repository + uses: actions/checkout@v4 + + # Initializes the CodeQL tools for scanning. + - name: Initialize CodeQL + uses: github/codeql-action/init@v3 + with: + languages: ${{ matrix.language }} + build-mode: ${{ matrix.build-mode }} + # If you wish to specify custom queries, you can do so here or in a config file. + # By default, queries listed here will override any specified in a config file. + # Prefix the list here with "+" to use these queries and those in the config file. + + # For more details on CodeQL's query packs, refer to: https://docs.github.com/en/code-security/code-scanning/automatically-scanning-your-code-for-vulnerabilities-and-errors/configuring-code-scanning#using-queries-in-ql-packs + # queries: security-extended,security-and-quality + + # If the analyze step fails for one of the languages you are analyzing with + # "We were unable to automatically build your code", modify the matrix above + # to set the build mode to "manual" for that language. Then modify this step + # to build your code. + # ℹī¸ Command-line programs to run using the OS shell. + # 📚 See https://docs.github.com/en/actions/using-workflows/workflow-syntax-for-github-actions#jobsjob_idstepsrun + - if: matrix.build-mode == 'manual' + shell: bash + run: | + echo 'If you are using a "manual" build mode for one or more of the' \ + 'languages you are analyzing, replace this with the commands to build' \ + 'your code, for example:' + echo ' make bootstrap' + echo ' make release' + exit 1 + + - name: Perform CodeQL Analysis + uses: github/codeql-action/analyze@v3 + with: + category: "/language:${{matrix.language}}" From 4a713591b385ef72fdadcf3c476f58f98f0310c8 Mon Sep 17 00:00:00 2001 From: Romain Dartigues Date: Wed, 15 May 2024 14:23:44 +0200 Subject: [PATCH 06/20] CI: add lint --- .github/workflows/golangci-lint.yml | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) create mode 100644 .github/workflows/golangci-lint.yml diff --git a/.github/workflows/golangci-lint.yml b/.github/workflows/golangci-lint.yml new file mode 100644 index 0000000..5bfc69b --- /dev/null +++ b/.github/workflows/golangci-lint.yml @@ -0,0 +1,27 @@ +name: golangci-lint +on: + push: + branches: + - main + - master + pull_request: + +permissions: + contents: read + # Optional: allow read access to pull request. Use with `only-new-issues` option. + # pull-requests: read + +jobs: + golangci: + name: lint + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + - uses: actions/setup-go@v5 + with: + go-version: '>=1.22' + - name: golangci-lint + uses: golangci/golangci-lint-action@v6 + with: + version: v1.58 + args: --disable-all --enable govet,staticcheck,unused From 099bb31512f2953b0ee9c424a9cb0dbdc7d1d867 Mon Sep 17 00:00:00 2001 From: Romain Dartigues Date: Wed, 15 May 2024 14:30:06 +0200 Subject: [PATCH 07/20] upgrade go and dependencies --- go.mod | 31 +++++++++--------- go.sum | 102 ++++++++++++++++++++++++--------------------------------- 2 files changed, 57 insertions(+), 76 deletions(-) diff --git a/go.mod b/go.mod index 8699ae7..a64388f 100644 --- a/go.mod +++ b/go.mod @@ -1,38 +1,38 @@ module github.com/cloudfoundry-community/gautocloud -go 1.21 +go 1.22.3 require ( - github.com/alexflint/go-arg v1.4.3 + github.com/alexflint/go-arg v1.5.0 github.com/azer/snakecase v1.0.0 github.com/cloudfoundry-community/go-cfenv v1.18.0 github.com/denisenkom/go-mssqldb v0.12.3 github.com/go-redis/redis/v7 v7.4.1 - github.com/go-sql-driver/mysql v1.7.1 + github.com/go-sql-driver/mysql v1.8.1 github.com/goamz/goamz v0.0.0-20180131231218-8b901b531db8 github.com/golang/mock v1.6.0 github.com/jinzhu/gorm v1.9.16 github.com/lib/pq v1.10.9 github.com/minio/minio-go v6.0.14+incompatible github.com/onsi/ginkgo v1.16.5 - github.com/onsi/gomega v1.30.0 + github.com/onsi/gomega v1.33.1 github.com/satori/go.uuid v1.2.0 github.com/sirupsen/logrus v1.9.3 github.com/spf13/viper v1.18.2 github.com/streadway/amqp v1.1.0 - github.com/urfave/cli v1.22.14 - golang.org/x/oauth2 v0.16.0 + github.com/urfave/cli v1.22.15 + golang.org/x/oauth2 v0.20.0 gopkg.in/mgo.v2 v2.0.0-20190816093944-a6b53ec6cb22 ) require ( + filippo.io/edwards25519 v1.1.0 // indirect github.com/alexflint/go-scalar v1.2.0 // indirect - github.com/cpuguy83/go-md2man/v2 v2.0.3 // indirect + github.com/cpuguy83/go-md2man/v2 v2.0.4 // indirect github.com/fsnotify/fsnotify v1.7.0 // indirect github.com/go-ini/ini v1.67.0 // indirect github.com/golang-sql/civil v0.0.0-20220223132316-b832511892a9 // indirect github.com/golang-sql/sqlexp v0.1.0 // indirect - github.com/golang/protobuf v1.5.3 // indirect github.com/google/go-cmp v0.6.0 // indirect github.com/hashicorp/hcl v1.0.0 // indirect github.com/jinzhu/inflection v1.0.0 // indirect @@ -40,7 +40,7 @@ require ( github.com/mitchellh/go-homedir v1.1.0 // indirect github.com/mitchellh/mapstructure v1.5.0 // indirect github.com/nxadm/tail v1.4.11 // indirect - github.com/pelletier/go-toml/v2 v2.1.1 // indirect + github.com/pelletier/go-toml/v2 v2.2.2 // indirect github.com/russross/blackfriday/v2 v2.1.0 // indirect github.com/sagikazarmark/locafero v0.4.0 // indirect github.com/sagikazarmark/slog-shim v0.1.0 // indirect @@ -51,13 +51,12 @@ require ( github.com/subosito/gotenv v1.6.0 // indirect github.com/vaughan0/go-ini v0.0.0-20130923145212-a98ad7ee00ec // indirect go.uber.org/multierr v1.11.0 // indirect - golang.org/x/crypto v0.18.0 // indirect - golang.org/x/exp v0.0.0-20240103183307-be819d1f06fc // indirect - golang.org/x/net v0.20.0 // indirect - golang.org/x/sys v0.16.0 // indirect - golang.org/x/text v0.14.0 // indirect - google.golang.org/appengine v1.6.8 // indirect - google.golang.org/protobuf v1.32.0 // indirect + golang.org/x/crypto v0.23.0 // indirect + golang.org/x/exp v0.0.0-20240506185415-9bf2ced13842 // indirect + golang.org/x/net v0.25.0 // indirect + golang.org/x/sys v0.20.0 // indirect + golang.org/x/text v0.15.0 // indirect + google.golang.org/protobuf v1.34.1 // indirect gopkg.in/ini.v1 v1.67.0 // indirect gopkg.in/tomb.v1 v1.0.0-20141024135613-dd632973f1e7 // indirect gopkg.in/yaml.v3 v3.0.1 // indirect diff --git a/go.sum b/go.sum index b53f4ea..e1340fa 100644 --- a/go.sum +++ b/go.sum @@ -1,11 +1,12 @@ +filippo.io/edwards25519 v1.1.0 h1:FNf4tywRC1HmFuKW5xopWpigGjJKiJSV0Cqo0cJWDaA= +filippo.io/edwards25519 v1.1.0/go.mod h1:BxyFTGdWcka3PhytdK4V28tE5sGfRvvvRV7EaN4VDT4= github.com/Azure/azure-sdk-for-go/sdk/azcore v0.19.0/go.mod h1:h6H6c8enJmmocHUbLiiGY6sx7f9i+X3m1CHdd5c6Rdw= github.com/Azure/azure-sdk-for-go/sdk/azidentity v0.11.0/go.mod h1:HcM1YX14R7CJcghJGOYCgdezslRSVzqwLf/q+4Y2r/0= github.com/Azure/azure-sdk-for-go/sdk/internal v0.7.0/go.mod h1:yqy467j36fJxcRV2TzfVZ1pCb5vxm4BtZPUdYWe/Xo8= github.com/BurntSushi/toml v1.3.2/go.mod h1:CxXYINrC8qIiEnFrOxCa7Jy5BFHlXnUU2pbicEuybxQ= github.com/PuerkitoBio/goquery v1.5.1/go.mod h1:GsLWisAFVj4WgDibEWF4pvYnkVQBpKBKeU+7zCJoLcc= -github.com/alexflint/go-arg v1.4.3 h1:9rwwEBpMXfKQKceuZfYcwuc/7YY7tWJbFsgG5cAU/uo= -github.com/alexflint/go-arg v1.4.3/go.mod h1:3PZ/wp/8HuqRZMUUgu7I+e1qcpUbvmS258mRXkFH4IA= -github.com/alexflint/go-scalar v1.1.0/go.mod h1:LoFvNMqS1CPrMVltza4LvnGKhaSpc3oyLEBUZVhhS2o= +github.com/alexflint/go-arg v1.5.0 h1:rwMKGiaQuRbXfZNyRUvIfke63QvOBt1/QTshlGQHohM= +github.com/alexflint/go-arg v1.5.0/go.mod h1:A7vTJzvjoaSTypg4biM5uYNTkJ27SkNTArtYXnlqVO8= github.com/alexflint/go-scalar v1.2.0 h1:WR7JPKkeNpnYIOfHRa7ivM21aWAdHD0gEWHCx+WQBRw= github.com/alexflint/go-scalar v1.2.0/go.mod h1:LoFvNMqS1CPrMVltza4LvnGKhaSpc3oyLEBUZVhhS2o= github.com/andybalholm/cascadia v1.1.0/go.mod h1:GsXiBklL0woXo1j/WYWtSYYC4ouU9PqHO0sqidkEA4Y= @@ -13,9 +14,8 @@ github.com/azer/snakecase v1.0.0 h1:Gr9hfYVh6U96aUoGEbJK400H9KTiz6yCIYk3EN8n9hY= github.com/azer/snakecase v1.0.0/go.mod h1:iApMeoHF0YlMPzCwqH/d59E3w2s8SeO4rGK+iGClS8Y= github.com/cloudfoundry-community/go-cfenv v1.18.0 h1:dOIRSHUSaj4r6Q9Cx+nzz2OytHt+QNKqtOuKTQsa+zw= github.com/cloudfoundry-community/go-cfenv v1.18.0/go.mod h1:qGMSI6lygPzqugFs9M1NFjJBtEPgl0MgT6drMFZGUoU= -github.com/cpuguy83/go-md2man/v2 v2.0.2/go.mod h1:tgQtvFlXSQOSOSIRvRPT7W67SCa46tRHOmNcaadrF8o= -github.com/cpuguy83/go-md2man/v2 v2.0.3 h1:qMCsGGgs+MAzDFyp9LpAe1Lqy/fY/qCovCm0qnXZOBM= -github.com/cpuguy83/go-md2man/v2 v2.0.3/go.mod h1:tgQtvFlXSQOSOSIRvRPT7W67SCa46tRHOmNcaadrF8o= +github.com/cpuguy83/go-md2man/v2 v2.0.4 h1:wfIWP927BUkWJb2NmU/kNDYIBTh/ziUX91+lVfRxZq4= +github.com/cpuguy83/go-md2man/v2 v2.0.4/go.mod h1:tgQtvFlXSQOSOSIRvRPT7W67SCa46tRHOmNcaadrF8o= github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc h1:U9qPSI2PIWSS1VwoXQT9A3Wy9MM3WgvqSxFWenqJduM= @@ -35,16 +35,17 @@ github.com/fsnotify/fsnotify v1.7.0 h1:8JEhPFa5W2WU7YfeZzPNqzMP6Lwt7L2715Ggo0nos github.com/fsnotify/fsnotify v1.7.0/go.mod h1:40Bi/Hjc2AVfZrqy+aj+yEI+/bRxZnMJyTJwOpGvigM= github.com/go-ini/ini v1.67.0 h1:z6ZrTEZqSWOTyH2FlglNbNgARyHG8oLW9gMELqKr06A= github.com/go-ini/ini v1.67.0/go.mod h1:ByCAeIL28uOIIG0E3PJtZPDL8WnHpFKFOtgjp+3Ies8= -github.com/go-logr/logr v1.2.4 h1:g01GSCwiDw2xSZfjJ2/T9M+S6pFdcNtFYsp+Y43HYDQ= -github.com/go-logr/logr v1.2.4/go.mod h1:jdQByPbusPIv2/zmleS9BjJVeZ6kBagPoEUsqbVz/1A= +github.com/go-logr/logr v1.4.1 h1:pKouT5E8xu9zeFC39JXRDukb6JFQPXM5p5I91188VAQ= +github.com/go-logr/logr v1.4.1/go.mod h1:9T104GzyrTigFIr8wt5mBrctHMim0Nb2HLGrmQ40KvY= github.com/go-redis/redis/v7 v7.4.1 h1:PASvf36gyUpr2zdOUS/9Zqc80GbM+9BDyiJSJDDOrTI= github.com/go-redis/redis/v7 v7.4.1/go.mod h1:JDNMw23GTyLNC4GZu9njt15ctBQVn7xjRfnwdHj/Dcg= github.com/go-sql-driver/mysql v1.5.0/go.mod h1:DCzpHaOWr8IXmIStZouvnhqoel9Qv2LBy8hT2VhHyBg= -github.com/go-sql-driver/mysql v1.7.1 h1:lUIinVbN1DY0xBg0eMOzmmtGoHwWBbvnWubQUrtU8EI= -github.com/go-sql-driver/mysql v1.7.1/go.mod h1:OXbVy3sEdcQ2Doequ6Z5BW6fXNQTmx+9S1MCJN5yJMI= +github.com/go-sql-driver/mysql v1.8.1 h1:LedoTUt/eveggdHS9qUFC1EFSa8bU2+1pZjSRpvNJ1Y= +github.com/go-sql-driver/mysql v1.8.1/go.mod h1:wEBSXgmK//2ZFJyE+qWnIsVGmvmEKlqwuVSjsCm7DZg= +github.com/go-task/slim-sprig v0.0.0-20210107165309-348f09dbbbc0 h1:p104kn46Q8WdvHunIJ9dAyjPVtrBPhSr3KT2yUst43I= github.com/go-task/slim-sprig v0.0.0-20210107165309-348f09dbbbc0/go.mod h1:fyg7847qk6SyHyPtNmDHnmrv/HOrqktSC+C9fM+CJOE= -github.com/go-task/slim-sprig v0.0.0-20230315185526-52ccab3ef572 h1:tfuBGBXKqDEevZMzYi5KSi8KkcZtzBcTgAUUtapy0OI= -github.com/go-task/slim-sprig v0.0.0-20230315185526-52ccab3ef572/go.mod h1:9Pwr4B2jHnOSGXyyzV8ROjYa2ojvAY6HCGYYfMoC3Ls= +github.com/go-task/slim-sprig/v3 v3.0.0 h1:sUs3vkvUymDpBKi3qH1YSqBQk9+9D/8M2mN1vB6EwHI= +github.com/go-task/slim-sprig/v3 v3.0.0/go.mod h1:W848ghGpv3Qj3dhTPRyJypKRiqCdHZiAzKg9hl15HA8= github.com/goamz/goamz v0.0.0-20180131231218-8b901b531db8 h1:G1U0vew/vA/1/hBmf1XNeyIzJJbPFVv+kb+HPl6rj6c= github.com/goamz/goamz v0.0.0-20180131231218-8b901b531db8/go.mod h1:/Ya1YZsqLQp17bDgHdyE9/XBR1uIH1HKasTvLxcoM/A= github.com/golang-sql/civil v0.0.0-20190719163853-cb61b32ac6fe/go.mod h1:8vg3r2VgvsThLBIFL93Qb5yWzgyZWhEmBwUJWevAkK0= @@ -62,18 +63,13 @@ github.com/golang/protobuf v1.4.0-rc.2/go.mod h1:LlEzMj4AhA7rCAGe4KMBDvJI+AwstrU github.com/golang/protobuf v1.4.0-rc.4.0.20200313231945-b860323f09d0/go.mod h1:WU3c8KckQ9AFe+yFwt9sWVRKCVIyN9cPHBJSNnbL67w= github.com/golang/protobuf v1.4.0/go.mod h1:jodUvKwWbYaEsadDk5Fwe5c77LiNKVO9IDvqG2KuDX0= github.com/golang/protobuf v1.4.2/go.mod h1:oDoupMAO8OvCJWAcko0GGGIgR6R6ocIYbsSw735rRwI= -github.com/golang/protobuf v1.5.0/go.mod h1:FsONVRAS9T7sI+LIUmWTfcYkHO4aIWwzhcaSAoJOfIk= -github.com/golang/protobuf v1.5.2/go.mod h1:XVQd3VNwM+JqD3oG2Ue2ip4fOMUkwXdXDdiuN0vRsmY= -github.com/golang/protobuf v1.5.3 h1:KhyjKVUg7Usr/dYsdSqoFveMYd5ko72D+zANwlG1mmg= -github.com/golang/protobuf v1.5.3/go.mod h1:XVQd3VNwM+JqD3oG2Ue2ip4fOMUkwXdXDdiuN0vRsmY= github.com/google/go-cmp v0.3.0/go.mod h1:8QqcDgzrUqlUb/G2PQTWiueGozuR1884gddMywk6iLU= github.com/google/go-cmp v0.3.1/go.mod h1:8QqcDgzrUqlUb/G2PQTWiueGozuR1884gddMywk6iLU= github.com/google/go-cmp v0.4.0/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE= -github.com/google/go-cmp v0.5.5/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE= github.com/google/go-cmp v0.6.0 h1:ofyhxvXcZhMsU5ulbFiLKl/XBFqE1GSq7atu8tAmTRI= github.com/google/go-cmp v0.6.0/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeNGIjoY= -github.com/google/pprof v0.0.0-20210407192527-94a9f03dee38 h1:yAJXTCF9TqKcTiHJAE8dj7HMvPfh66eeA2JYW7eFpSE= -github.com/google/pprof v0.0.0-20210407192527-94a9f03dee38/go.mod h1:kpwsk12EmLew5upagYY7GY0pfYCcupk39gWOCRROcvE= +github.com/google/pprof v0.0.0-20240424215950-a892ee059fd6 h1:k7nVchz72niMH6YLQNvHSdIE7iqsQxK1P41mySCvssg= +github.com/google/pprof v0.0.0-20240424215950-a892ee059fd6/go.mod h1:kf6iHlnVGwgKolg33glAes7Yg/8iWP8ukqeldJSO7jw= github.com/hashicorp/hcl v1.0.0 h1:0Anlzjpi4vEasTeNFn2mLJgTSwt0+6sfsiTG8qcWGx4= github.com/hashicorp/hcl v1.0.0/go.mod h1:E5yfLk+7swimpb2L/Alb/PJmXilQ/rhwaUYs4T20WEQ= github.com/hpcloud/tail v1.0.0/go.mod h1:ab1qPbhIpdTxEkNHXyeSf5vhxWSCs/tWer42PpOxQnU= @@ -117,16 +113,16 @@ github.com/onsi/ginkgo v1.10.1/go.mod h1:lLunBs/Ym6LB5Z9jYTR76FiuTmxDTDusOGeTQH+ github.com/onsi/ginkgo v1.12.1/go.mod h1:zj2OWP4+oCPe1qIXoGWkgMRwljMUYCdkwsT2108oapk= github.com/onsi/ginkgo v1.16.5 h1:8xi0RTUf59SOSfEtZMvwTvXYMzG4gV23XVHOZiXNtnE= github.com/onsi/ginkgo v1.16.5/go.mod h1:+E8gABHa3K6zRBolWtd+ROzc/U5bkGt0FwiG042wbpU= -github.com/onsi/ginkgo/v2 v2.13.0 h1:0jY9lJquiL8fcf3M4LAXN5aMlS/b2BV86HFFPCPMgE4= -github.com/onsi/ginkgo/v2 v2.13.0/go.mod h1:TE309ZR8s5FsKKpuB1YAQYBzCaAfUgatB/xlT/ETL/o= +github.com/onsi/ginkgo/v2 v2.17.2 h1:7eMhcy3GimbsA3hEnVKdw/PQM9XN9krpKVXsZdph0/g= +github.com/onsi/ginkgo/v2 v2.17.2/go.mod h1:nP2DPOQoNsQmsVyv5rDA8JkXQoCs6goXIvr/PRJ1eCc= github.com/onsi/gomega v1.5.0/go.mod h1:ex+gbHU/CVuBBDIJjb2X0qEXbFg53c61hWP/1CpauHY= github.com/onsi/gomega v1.7.0/go.mod h1:ex+gbHU/CVuBBDIJjb2X0qEXbFg53c61hWP/1CpauHY= github.com/onsi/gomega v1.7.1/go.mod h1:XdKZgCCFLUoM/7CFJVPcG8C1xQ1AJ0vpAezJrB7JYyY= github.com/onsi/gomega v1.10.1/go.mod h1:iN09h71vgCQne3DLsj+A5owkum+a2tYe+TOCB1ybHNo= -github.com/onsi/gomega v1.30.0 h1:hvMK7xYz4D3HapigLTeGdId/NcfQx1VHMJc60ew99+8= -github.com/onsi/gomega v1.30.0/go.mod h1:9sxs+SwGrKI0+PWe4Fxa9tFQQBG5xSsSbMXOI8PPpoQ= -github.com/pelletier/go-toml/v2 v2.1.1 h1:LWAJwfNvjQZCFIDKWYQaM62NcYeYViCmWIwmOStowAI= -github.com/pelletier/go-toml/v2 v2.1.1/go.mod h1:tJU2Z3ZkXwnxa4DPO899bsyIoywizdUvyaeZurnPPDc= +github.com/onsi/gomega v1.33.1 h1:dsYjIxxSR755MDmKVsaFQTE22ChNBcuuTWgkUDSubOk= +github.com/onsi/gomega v1.33.1/go.mod h1:U4R44UsT+9eLIaYRB2a5qajjtQYn0hauxvRm16AVYg0= +github.com/pelletier/go-toml/v2 v2.2.2 h1:aYUidT7k73Pcl9nb2gScu7NSrKCSHIDE89b3+6Wq+LM= +github.com/pelletier/go-toml/v2 v2.2.2/go.mod h1:1t835xjRzz80PqgE6HHgN2JOsmgYu/h4qDAS4n929Rs= github.com/pkg/browser v0.0.0-20180916011732-0a3d74bf9ce4/go.mod h1:4OwLy04Bl9Ef3GJJCoec+30X3LQs/0/m4HFRt/2LUSA= github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= github.com/pmezard/go-difflib v1.0.1-0.20181226105442-5d4384ee4fb2 h1:Jamvg5psRIccs7FGNTlIRMkT8wgtp5eCXdBlqhYGL6U= @@ -160,22 +156,23 @@ github.com/streadway/amqp v1.1.0/go.mod h1:WYSrTEYHOXHd0nwFeUXAe2G2hRnQT+deZJJf8 github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= github.com/stretchr/objx v0.4.0/go.mod h1:YvHI0jy2hoMjB+UWwv71VJQ9isScKT/TqJzVSSt89Yw= github.com/stretchr/objx v0.5.0/go.mod h1:Yh+to48EsGEfYuaHDzXPcE3xhTkx73EhmCGUpEOglKo= +github.com/stretchr/objx v0.5.2/go.mod h1:FRsXN1f5AsAjCGJKqEizvkpNtU+EGNCLh3NxZ/8L+MA= github.com/stretchr/testify v1.2.2/go.mod h1:a8OnRcib4nhh0OaRAV+Yts87kKdq0PP7pXfy6kDkUVs= github.com/stretchr/testify v1.5.1/go.mod h1:5W2xD1RspED5o8YsWQXVCued0rvSQ+mT+I5cxcmMvtA= github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg= github.com/stretchr/testify v1.7.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg= github.com/stretchr/testify v1.8.0/go.mod h1:yNjHg4UonilssWZ8iaSj1OCr/vHnekPRkoO+kdMU+MU= -github.com/stretchr/testify v1.8.4 h1:CcVxjf3Q8PM0mHUKJCdn+eZZtm5yQwehR5yeSVQQcUk= github.com/stretchr/testify v1.8.4/go.mod h1:sz/lmYIOXD/1dqDmKjjqLyZ2RngseejIcXlSw2iwfAo= +github.com/stretchr/testify v1.9.0 h1:HtqpIVDClZ4nwg75+f6Lvsy/wHu+3BoSGCbBAcpTsTg= +github.com/stretchr/testify v1.9.0/go.mod h1:r2ic/lqez/lEtzL7wO/rwa5dbSLXVDPFyf8C91i36aY= github.com/subosito/gotenv v1.6.0 h1:9NlTDc1FTs4qu0DDq7AEtTPNw6SVm7uBMsUCUjABIf8= github.com/subosito/gotenv v1.6.0/go.mod h1:Dk4QP5c2W3ibzajGcXpNraDfq2IrhjMIvMSWPKKo0FU= -github.com/urfave/cli v1.22.14 h1:ebbhrRiGK2i4naQJr+1Xj92HXZCrK7MsyTS/ob3HnAk= -github.com/urfave/cli v1.22.14/go.mod h1:X0eDS6pD6Exaclxm99NJ3FiCDRED7vIHpx2mDOHLvkA= +github.com/urfave/cli v1.22.15 h1:nuqt+pdC/KqswQKhETJjo7pvn/k4xMUxgW6liI7XpnM= +github.com/urfave/cli v1.22.15/go.mod h1:wSan1hmo5zeyLGBjRJbzRTNk8gwoYa2B9n4q9dmRIc0= github.com/vaughan0/go-ini v0.0.0-20130923145212-a98ad7ee00ec h1:DGmKwyZwEB8dI7tbLt/I/gQuP559o/0FrAkHKlQM/Ks= github.com/vaughan0/go-ini v0.0.0-20130923145212-a98ad7ee00ec/go.mod h1:owBmyHYMLkxyrugmfwE/DLJyW8Ro9mkphwuVErQ0iUw= github.com/yuin/goldmark v1.2.1/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74= github.com/yuin/goldmark v1.3.5/go.mod h1:mwnBkeHKe2W/ZEtQ+71ViKU8L12m81fl3OWwC1Zlc8k= -github.com/yuin/goldmark v1.4.13/go.mod h1:6yULJ656Px+3vBD8DxQVa3kxgyrAnzto9xy5taEt/CY= go.uber.org/multierr v1.11.0 h1:blXXJkSxSSfBVBlC76pxqeO+LN3aDfLQo+309xJstO0= go.uber.org/multierr v1.11.0/go.mod h1:20+QtiLqy0Nd6FdQB9TLXag12DsQkrbs3htMFfDN80Y= golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w= @@ -184,15 +181,13 @@ golang.org/x/crypto v0.0.0-20191011191535-87dc89f01550/go.mod h1:yigFU9vqHzYiE8U golang.org/x/crypto v0.0.0-20191205180655-e7c4368fe9dd/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto= golang.org/x/crypto v0.0.0-20200622213623-75b288015ac9/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto= golang.org/x/crypto v0.0.0-20201016220609-9e8e0b390897/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto= -golang.org/x/crypto v0.0.0-20210921155107-089bfa567519/go.mod h1:GvvjBRRGRdwPK5ydBHafDWAxML/pGHZbMvKqRZ5+Abc= golang.org/x/crypto v0.0.0-20220622213112-05595931fe9d/go.mod h1:IxCIyHEi3zRg3s0A5j5BB6A9Jmi73HwBIUl50j+osU4= -golang.org/x/crypto v0.18.0 h1:PGVlW0xEltQnzFZ55hkuX5+KLyrMYhHld1YHO4AKcdc= -golang.org/x/crypto v0.18.0/go.mod h1:R0j02AL6hcrfOiy9T4ZYp/rcWeMxM3L6QYxlOuEG1mg= -golang.org/x/exp v0.0.0-20240103183307-be819d1f06fc h1:ao2WRsKSzW6KuUY9IWPwWahcHCgR0s52IfwutMfEbdM= -golang.org/x/exp v0.0.0-20240103183307-be819d1f06fc/go.mod h1:iRJReGqOEeBhDZGkGbynYwcHlctCvnjTYIamk7uXpHI= +golang.org/x/crypto v0.23.0 h1:dIJU/v2J8Mdglj/8rJ6UUOM3Zc9zLZxVZwwxMooUSAI= +golang.org/x/crypto v0.23.0/go.mod h1:CKFgDieR+mRhux2Lsu27y0fO304Db0wZe70UKqHu0v8= +golang.org/x/exp v0.0.0-20240506185415-9bf2ced13842 h1:vr/HnozRka3pE4EsMEg1lgkXJkTFJCVUX+S/ZT6wYzM= +golang.org/x/exp v0.0.0-20240506185415-9bf2ced13842/go.mod h1:XtvwrStGgqGPLc4cjQfWqZHG1YFdYs6swckp8vpsjnc= golang.org/x/mod v0.3.0/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA= golang.org/x/mod v0.4.2/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA= -golang.org/x/mod v0.6.0-dev.0.20220419223038-86c51ed26bb4/go.mod h1:jJ57K6gSWd91VN4djpZkiMVwK6gcyfeH4XE8wZrZaV4= golang.org/x/net v0.0.0-20180218175443-cbe0f9307d01/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= golang.org/x/net v0.0.0-20180906233101-161cd47e91fd/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= golang.org/x/net v0.0.0-20190404232315-eb5bcb51f2a3/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg= @@ -202,20 +197,17 @@ golang.org/x/net v0.0.0-20200202094626-16171245cfb2/go.mod h1:z5CRVTTTmAJ677TzLL golang.org/x/net v0.0.0-20200324143707-d3edc9973b7e/go.mod h1:qpuaurCH72eLCgpAm/N6yyVIVM9cpaDIP3A8BGJEC5A= golang.org/x/net v0.0.0-20200520004742-59133d7f0dd7/go.mod h1:qpuaurCH72eLCgpAm/N6yyVIVM9cpaDIP3A8BGJEC5A= golang.org/x/net v0.0.0-20201021035429-f5854403a974/go.mod h1:sp8m0HH+o8qH0wwXwYZr8TS3Oi6o0r6Gce1SSxlDquU= -golang.org/x/net v0.0.0-20210226172049-e18ecbb05110/go.mod h1:m0MpNAwzfU5UDzcl9v0D8zg8gWTRqZa9RBIspLL5mdg= golang.org/x/net v0.0.0-20210405180319-a5a99cb37ef4/go.mod h1:p54w0d4576C0XHj96bSt6lcn1PtDYWL6XObtHCRCNQM= golang.org/x/net v0.0.0-20210610132358-84b48f89b13b/go.mod h1:9nx3DQGgdP8bBQD5qxJ1jj9UTztislL4KSBs9R2vV5Y= golang.org/x/net v0.0.0-20211112202133-69e39bad7dc2/go.mod h1:9nx3DQGgdP8bBQD5qxJ1jj9UTztislL4KSBs9R2vV5Y= -golang.org/x/net v0.0.0-20220722155237-a158d28d115b/go.mod h1:XRhObCWvk6IyKnWLug+ECip1KBveYUHfp+8e9klMJ9c= -golang.org/x/net v0.20.0 h1:aCL9BSgETF1k+blQaYUBx9hJ9LOGP3gAVemcZlf1Kpo= -golang.org/x/net v0.20.0/go.mod h1:z8BVo6PvndSri0LbOE3hAn0apkU+1YvI6E70E9jsnvY= -golang.org/x/oauth2 v0.16.0 h1:aDkGMBSYxElaoP81NpoUoz2oo2R2wHdZpGToUxfyQrQ= -golang.org/x/oauth2 v0.16.0/go.mod h1:hqZ+0LWXsiVoZpeld6jVt06P3adbS2Uu911W1SsJv2o= +golang.org/x/net v0.25.0 h1:d/OCCoBEUq33pjydKrGQhw7IlUPI2Oylr+8qLx49kac= +golang.org/x/net v0.25.0/go.mod h1:JkAGAh7GEvH74S6FOH42FLoXpXbE/aqXSrIQjXgsiwM= +golang.org/x/oauth2 v0.20.0 h1:4mQdhULixXKP1rwYBW0vAijoXnkTG0BLCDRzfe1idMo= +golang.org/x/oauth2 v0.20.0/go.mod h1:XYTD2NtWslqkgxebSiOHnXEap4TF09sJSc7H1sXbhtI= golang.org/x/sync v0.0.0-20180314180146-1d60e4601c6f/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= golang.org/x/sync v0.0.0-20201020160332-67f06af15bc9/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= golang.org/x/sync v0.0.0-20210220032951-036812b2e83c/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= -golang.org/x/sync v0.0.0-20220722155255-886fb9371eb4/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= golang.org/x/sys v0.0.0-20180909124046-d0be0721c37e/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= golang.org/x/sys v0.0.0-20190412213103-97732733099d/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= @@ -231,45 +223,35 @@ golang.org/x/sys v0.0.0-20210330210617-4fbd30eecc44/go.mod h1:h1NjWce9XRLGQEsW7w golang.org/x/sys v0.0.0-20210423082822-04245dca01da/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20210510120138-977fb7262007/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.0.0-20210615035016-665e8c7367d1/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= -golang.org/x/sys v0.0.0-20220520151302-bc2c85ada10a/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.0.0-20220715151400-c0bba94af5f8/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= -golang.org/x/sys v0.0.0-20220722155257-8c9f86f7a55f/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.0.0-20220908164124-27713097b956/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= -golang.org/x/sys v0.16.0 h1:xWw16ngr6ZMtmxDyKyIgsE93KNKz5HKmMa3b8ALHidU= -golang.org/x/sys v0.16.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA= +golang.org/x/sys v0.20.0 h1:Od9JTbYCk261bKm4M/mw7AklTlFYIa0bIp9BgSm1S8Y= +golang.org/x/sys v0.20.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA= golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo= -golang.org/x/term v0.0.0-20210927222741-03fcf44c2211/go.mod h1:jbD1KX2456YbFQfuXm/mYQcufACuNUgVhRMnK/tPxf8= golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= golang.org/x/text v0.3.2/go.mod h1:bEr9sfX3Q8Zfm5fL9x+3itogRgK3+ptLWKqgva+5dAk= golang.org/x/text v0.3.3/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ= golang.org/x/text v0.3.6/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ= -golang.org/x/text v0.3.7/go.mod h1:u+2+/6zg+i71rQMx5EYifcz6MCKuco9NR6JIITiCfzQ= -golang.org/x/text v0.3.8/go.mod h1:E6s5w1FMmriuDzIBO73fBruAKo1PCIq6d2Q6DHfQ8WQ= -golang.org/x/text v0.14.0 h1:ScX5w1eTa3QqT8oi6+ziP7dTV1S2+ALU0bI+0zXKWiQ= -golang.org/x/text v0.14.0/go.mod h1:18ZOQIKpY8NJVqYksKHtTdi31H5itFRjB5/qKTNYzSU= +golang.org/x/text v0.15.0 h1:h1V/4gjBv8v9cjcR6+AR5+/cIYK5N/WAgiv4xlsEtAk= +golang.org/x/text v0.15.0/go.mod h1:18ZOQIKpY8NJVqYksKHtTdi31H5itFRjB5/qKTNYzSU= golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ= golang.org/x/tools v0.0.0-20191119224855-298f0cb1881e/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo= golang.org/x/tools v0.0.0-20201224043029-2b0845dc783e/go.mod h1:emZCQorbCU4vsT4fOWvOPXz4eW1wZW4PmDk9uLelYpA= golang.org/x/tools v0.1.1/go.mod h1:o0xws9oXOQQZyjljx8fwUC0k7L1pTE6eaCbjGeHmOkk= -golang.org/x/tools v0.1.12/go.mod h1:hNGJHUnrk76NpqgfD5Aqm5Crs+Hm0VOH/i9J2+nxYbc= -golang.org/x/tools v0.16.0 h1:GO788SKMRunPIBCXiQyo2AaexLstOrVhuAL5YwsckQM= -golang.org/x/tools v0.16.0/go.mod h1:kYVVN6I1mBNoB1OX+noeBjbRk4IUEPa7JJ+TJMEooJ0= +golang.org/x/tools v0.21.0 h1:qc0xYgIbsSDt9EyWz05J5wfa7LOVW0YTLOXrqdLAWIw= +golang.org/x/tools v0.21.0/go.mod h1:aiJjzUbINMkxbQROHiO6hDPo2LHcIPhhQsa9DLh0yGk= golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= golang.org/x/xerrors v0.0.0-20191011141410-1b5146add898/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= golang.org/x/xerrors v0.0.0-20200804184101-5ec99f83aff1/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= -google.golang.org/appengine v1.6.8 h1:IhEN5q69dyKagZPYMSdIjS2HqprW324FRQZJcGqPAsM= -google.golang.org/appengine v1.6.8/go.mod h1:1jJ3jBArFh5pcgW8gCtRJnepW8FzD1V44FJffLiz/Ds= google.golang.org/protobuf v0.0.0-20200109180630-ec00e32a8dfd/go.mod h1:DFci5gLYBciE7Vtevhsrf46CRTquxDuWsQurQQe4oz8= google.golang.org/protobuf v0.0.0-20200221191635-4d8936d0db64/go.mod h1:kwYJMbMJ01Woi6D6+Kah6886xMZcty6N08ah7+eCXa0= google.golang.org/protobuf v0.0.0-20200228230310-ab0ca4ff8a60/go.mod h1:cfTl7dwQJ+fmap5saPgwCLgHXTUD7jkjRqWcaiX5VyM= google.golang.org/protobuf v1.20.1-0.20200309200217-e05f789c0967/go.mod h1:A+miEFZTKqfCUM6K7xSMQL9OKL/b6hQv+e19PK+JZNE= google.golang.org/protobuf v1.21.0/go.mod h1:47Nbq4nVaFHyn7ilMalzfO3qCViNmqZ2kzikPIcrTAo= google.golang.org/protobuf v1.23.0/go.mod h1:EGpADcykh3NcUnDUJcl1+ZksZNG86OlYog2l/sGQquU= -google.golang.org/protobuf v1.26.0-rc.1/go.mod h1:jlhhOSvTdKEhbULTjvd4ARK9grFBp09yW+WbY/TyQbw= -google.golang.org/protobuf v1.26.0/go.mod h1:9q0QmTI4eRPtz6boOQmLYwt+qCgq0jsYwAQnmE0givc= -google.golang.org/protobuf v1.32.0 h1:pPC6BG5ex8PDFnkbrGU3EixyhKcQ2aDuBS36lqK/C7I= -google.golang.org/protobuf v1.32.0/go.mod h1:c6P6GXX6sHbq/GpV6MGZEdwhWPcYBgnhAHhKbcUYpos= +google.golang.org/protobuf v1.34.1 h1:9ddQBjfCyZPOHPUiPxpYESBLc+T8P3E+Vo4IbKZgFWg= +google.golang.org/protobuf v1.34.1/go.mod h1:c6P6GXX6sHbq/GpV6MGZEdwhWPcYBgnhAHhKbcUYpos= gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= gopkg.in/check.v1 v1.0.0-20190902080502-41f04d3bba15 h1:YR8cESwS4TdDjEe65xsg0ogRM/Nc3DYOhEAlW+xobZo= gopkg.in/check.v1 v1.0.0-20190902080502-41f04d3bba15/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= From 62332864a82f921825391604d7847fa1409c8375 Mon Sep 17 00:00:00 2001 From: Romain Dartigues Date: Wed, 15 May 2024 14:29:29 +0200 Subject: [PATCH 08/20] strings.Title has been deprecated since Go 1.18 and an alternative has been available since Go 1.0 --- bin/doc-generator/doc-generator.go | 10 ++++++---- go.mod | 2 +- 2 files changed, 7 insertions(+), 5 deletions(-) diff --git a/bin/doc-generator/doc-generator.go b/bin/doc-generator/doc-generator.go index 0a5b740..48c8dfe 100644 --- a/bin/doc-generator/doc-generator.go +++ b/bin/doc-generator/doc-generator.go @@ -4,6 +4,8 @@ import ( "github.com/cloudfoundry-community/gautocloud" _ "github.com/cloudfoundry-community/gautocloud/connectors/all" . "github.com/cloudfoundry-community/gautocloud/test-utils" + "golang.org/x/text/cases" + "golang.org/x/text/language" "html/template" "os" "path" @@ -171,7 +173,7 @@ func getDocMap() map[string]Doc { rootId := rootIdSplit[len(rootIdSplit)-1] if _, ok := docs[rootId]; !ok { docs[rootId] = Doc{ - Name: strings.Title(rootId), + Name: cases.Title(language.Und, cases.NoLower).String(rootId), RespondName: conn.Name(), RespondTags: conn.Tags(), Connectors: make([]DocConnector, 0), @@ -223,7 +225,7 @@ func getDocMap() map[string]Doc { globalType = pkgSplit[4] } connDoc := DocConnector{ - Name: strings.Title(rootId + " - " + connName), + Name: cases.Title(language.Und, cases.NoLower).String(rootId + " - " + connName), Id: conn.Id(), Pkg: pkgConn, TypeName: givenType.String(), @@ -231,8 +233,8 @@ func getDocMap() map[string]Doc { TypeWrapped: typeWrapped, DocUrl: docUrl, Tip: tip, - GlobalType: strings.Title(globalType), - SimpleName: strings.Title(connName), + GlobalType: cases.Title(language.Und, cases.NoLower).String(globalType), + SimpleName: cases.Title(language.Und, cases.NoLower).String(connName), StructGiven: generateDocStruct(givenData), Closeable: isCloseable(givenData), } diff --git a/go.mod b/go.mod index a64388f..bb76ccc 100644 --- a/go.mod +++ b/go.mod @@ -22,6 +22,7 @@ require ( github.com/streadway/amqp v1.1.0 github.com/urfave/cli v1.22.15 golang.org/x/oauth2 v0.20.0 + golang.org/x/text v0.15.0 gopkg.in/mgo.v2 v2.0.0-20190816093944-a6b53ec6cb22 ) @@ -55,7 +56,6 @@ require ( golang.org/x/exp v0.0.0-20240506185415-9bf2ced13842 // indirect golang.org/x/net v0.25.0 // indirect golang.org/x/sys v0.20.0 // indirect - golang.org/x/text v0.15.0 // indirect google.golang.org/protobuf v1.34.1 // indirect gopkg.in/ini.v1 v1.67.0 // indirect gopkg.in/tomb.v1 v1.0.0-20141024135613-dd632973f1e7 // indirect From f4deeff4fb7ac7ef15079e92d9982f9ffcc63e43 Mon Sep 17 00:00:00 2001 From: Romain Dartigues Date: Wed, 15 May 2024 14:36:35 +0200 Subject: [PATCH 09/20] replace satori/go.uuid with google/uuid (CVE-2021-3538) Dependency go:github.com/satori/go.uuid:v1.2.0 is vulnerable CVE-2021-3538 9.8 Use of Cryptographically Weak Pseudo-Random Number Generator (PRNG) vulnerability with High severity foundResults powered by Checkmarx(c) --- cloudenv/local_cloudenv.go | 4 ++-- connectors/generic/config.go | 4 ++-- go.mod | 2 +- go.sum | 4 ++-- 4 files changed, 7 insertions(+), 7 deletions(-) diff --git a/cloudenv/local_cloudenv.go b/cloudenv/local_cloudenv.go index f1470d8..0573aee 100644 --- a/cloudenv/local_cloudenv.go +++ b/cloudenv/local_cloudenv.go @@ -6,7 +6,7 @@ import ( "encoding/json" "errors" - "github.com/satori/go.uuid" + "github.com/google/uuid" "github.com/spf13/viper" "io" "path/filepath" @@ -237,7 +237,7 @@ func (c LocalCloudEnv) IsInCloudEnv() bool { func (c *LocalCloudEnv) GetAppInfo() AppInfo { id := c.id if id == "" { - id = uuid.NewV4().String() + id = uuid.NewString() c.id = id } return AppInfo{ diff --git a/connectors/generic/config.go b/connectors/generic/config.go index 6c63f6b..0310aae 100644 --- a/connectors/generic/config.go +++ b/connectors/generic/config.go @@ -3,7 +3,7 @@ package generic import ( "github.com/cloudfoundry-community/gautocloud/connectors" "github.com/cloudfoundry-community/gautocloud/interceptor" - "github.com/satori/go.uuid" + "github.com/google/uuid" ) type ConfigGenericConnector struct { @@ -14,7 +14,7 @@ func NewConfigGenericConnector(config interface{}, interceptors ...interceptor.I return &ConfigGenericConnector{ SchemaBasedGenericConnector{ schema: config, - id: uuid.NewV4().String() + ":config", + id: uuid.NewString() + ":config", name: ".*config.*", tags: []string{"config.*"}, interceptors: interceptors, diff --git a/go.mod b/go.mod index bb76ccc..10b9aa4 100644 --- a/go.mod +++ b/go.mod @@ -11,12 +11,12 @@ require ( github.com/go-sql-driver/mysql v1.8.1 github.com/goamz/goamz v0.0.0-20180131231218-8b901b531db8 github.com/golang/mock v1.6.0 + github.com/google/uuid v1.6.0 github.com/jinzhu/gorm v1.9.16 github.com/lib/pq v1.10.9 github.com/minio/minio-go v6.0.14+incompatible github.com/onsi/ginkgo v1.16.5 github.com/onsi/gomega v1.33.1 - github.com/satori/go.uuid v1.2.0 github.com/sirupsen/logrus v1.9.3 github.com/spf13/viper v1.18.2 github.com/streadway/amqp v1.1.0 diff --git a/go.sum b/go.sum index e1340fa..24887ed 100644 --- a/go.sum +++ b/go.sum @@ -70,6 +70,8 @@ github.com/google/go-cmp v0.6.0 h1:ofyhxvXcZhMsU5ulbFiLKl/XBFqE1GSq7atu8tAmTRI= github.com/google/go-cmp v0.6.0/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeNGIjoY= github.com/google/pprof v0.0.0-20240424215950-a892ee059fd6 h1:k7nVchz72niMH6YLQNvHSdIE7iqsQxK1P41mySCvssg= github.com/google/pprof v0.0.0-20240424215950-a892ee059fd6/go.mod h1:kf6iHlnVGwgKolg33glAes7Yg/8iWP8ukqeldJSO7jw= +github.com/google/uuid v1.6.0 h1:NIvaJDMOsjHA8n1jAhLSgzrAzy1Hgr+hNrb57e+94F0= +github.com/google/uuid v1.6.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo= github.com/hashicorp/hcl v1.0.0 h1:0Anlzjpi4vEasTeNFn2mLJgTSwt0+6sfsiTG8qcWGx4= github.com/hashicorp/hcl v1.0.0/go.mod h1:E5yfLk+7swimpb2L/Alb/PJmXilQ/rhwaUYs4T20WEQ= github.com/hpcloud/tail v1.0.0/go.mod h1:ab1qPbhIpdTxEkNHXyeSf5vhxWSCs/tWer42PpOxQnU= @@ -135,8 +137,6 @@ github.com/sagikazarmark/locafero v0.4.0 h1:HApY1R9zGo4DBgr7dqsTH/JJxLTTsOt7u6ke github.com/sagikazarmark/locafero v0.4.0/go.mod h1:Pe1W6UlPYUk/+wc/6KFhbORCfqzgYEpgQ3O5fPuL3H4= github.com/sagikazarmark/slog-shim v0.1.0 h1:diDBnUNK9N/354PgrxMywXnAwEr1QZcOr6gto+ugjYE= github.com/sagikazarmark/slog-shim v0.1.0/go.mod h1:SrcSrq8aKtyuqEI1uvTDTK1arOWRIczQRv+GVI1AkeQ= -github.com/satori/go.uuid v1.2.0 h1:0uYX9dsZ2yD7q2RtLRtPSdGDWzjeM3TbMJP9utgA0ww= -github.com/satori/go.uuid v1.2.0/go.mod h1:dA0hQrYB0VpLJoorglMZABFdXlWrHn1NEOzdhQKdks0= github.com/sclevine/spec v1.2.0 h1:1Jwdf9jSfDl9NVmt8ndHqbTZ7XCCPbh1jI3hkDBHVYA= github.com/sclevine/spec v1.2.0/go.mod h1:W4J29eT/Kzv7/b9IWLB055Z+qvVC9vt0Arko24q7p+U= github.com/sirupsen/logrus v1.9.3 h1:dueUQJ1C2q9oE3F7wvmSGAaVtTmUizReu6fjN8uqzbQ= From 756e22125d705f97c5d5edf2375f25cb2ea50fba Mon Sep 17 00:00:00 2001 From: Romain Dartigues Date: Wed, 15 May 2024 14:37:49 +0200 Subject: [PATCH 10/20] code cleanup, typos and coding style --- .github/workflows/codeql.yml | 2 +- README.md | 98 ++++++++-------- bin/doc-generator/doc.tmpl.md | 6 +- cloudenv/cf_cloudenv.go | 5 +- cloudenv/cf_cloudenv_test.go | 2 +- cloudenv/cloudenv.go | 18 +-- connectors/connector.go | 18 +-- connectors/connector_example_test.go | 4 +- connectors/intercepter_example_test.go | 4 +- decoder/decoder.go | 12 +- docs/connectors.md | 156 ++++++++++++------------- interceptor/cli/arg/arg.go | 12 +- interceptor/cli/urfave/cli.go | 4 +- interceptor/cli/urfave/doc_test.go | 2 +- interceptor/intercepter.go | 6 +- interceptor/overwrite.go | 2 +- interceptor/schema.go | 12 +- loader/fake/fake_loader.go | 4 +- loader/loader.go | 32 ++--- loader/loader_test.go | 4 +- main.go | 30 ++--- 21 files changed, 215 insertions(+), 218 deletions(-) diff --git a/.github/workflows/codeql.yml b/.github/workflows/codeql.yml index 5a26d92..f205961 100644 --- a/.github/workflows/codeql.yml +++ b/.github/workflows/codeql.yml @@ -71,7 +71,7 @@ jobs: # For more details on CodeQL's query packs, refer to: https://docs.github.com/en/code-security/code-scanning/automatically-scanning-your-code-for-vulnerabilities-and-errors/configuring-code-scanning#using-queries-in-ql-packs # queries: security-extended,security-and-quality - # If the analyze step fails for one of the languages you are analyzing with + # If the analysis step fails for one of the languages you are analyzing with # "We were unable to automatically build your code", modify the matrix above # to set the build mode to "manual" for that language. Then modify this step # to build your code. diff --git a/README.md b/README.md index 4035999..f9bac2b 100644 --- a/README.md +++ b/README.md @@ -1,14 +1,14 @@ # Gautocloud [![Build Status](https://travis-ci.org/cloudfoundry-community/gautocloud.svg?branch=master)](https://travis-ci.org/cloudfoundry-community/gautocloud) [![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT) [![GoDoc](https://godoc.org/github.com/cloudfoundry-community/gautocloud?status.svg)](https://godoc.org/github.com/cloudfoundry-community/gautocloud) -Gautocloud provides a simple abstraction that golang based applications can use -to discover information about the cloud environment on which they are running, -to connect to services automatically with ease of use in mind. It provides out-of-the-box support -for discovering common services on Heroku, Cloud Foundry and kubernetes cloud platforms, +Gautocloud provides a simple abstraction that golang based applications can use +to discover information about the cloud environment on which they are running, +to connect to services automatically with ease of use in mind. It provides out-of-the-box support +for discovering common services on Heroku, Cloud Foundry and kubernetes cloud platforms, and it supports custom automatic connectors. This project can be assimilated to the [spring-cloud-connector](https://github.com/spring-cloud/spring-cloud-connectors) project - but for golang (and with is own concepts). + but for golang (and with its own concepts). ## Summary @@ -34,7 +34,7 @@ This project can be assimilated to the [spring-cloud-connector](https://github.c ## Usage by example -Let's define a context: We are in a Cloud Foundry environment where we connect a MySql service on our +Let's define a context: We are in a Cloud Foundry environment where we connect a MySql service on our application. We now wants to use this service without parsing a json or anything else to have a MySql client to use our service. @@ -43,7 +43,7 @@ Gautocloud is here to help for this kind of use case. This software will retrieve all services found in your environment and will pass informations from service to what we call a connector. A connector is responsible to create, in our context, a MySql client which make it available in your program. -You only needs to import a connector to make it useable by gautocloud. +You only needs to import a connector to make it usable by gautocloud. This system of import let you have only what you need to run your app (=do not create a huge binary) and let the possibility to create custom connector. Example (provide a `*net/sql.DB` struct): @@ -61,7 +61,7 @@ import ( func init(){ // Gautocloud use logrus as logger, see: https://github.com/sirupsen/logrus // When using facade, first log messages are emitted with default level from logrus (INFO) and debug message cannot be seen. - // To be able to see log message on load simply add the env var `GAUTOCLOUD_DEBUG` to `true`, you will be able to + // To be able to see log message on load simply add the env var `GAUTOCLOUD_DEBUG` to `true`, you will be able to // see debug message from gautocloud (you can also set `json` instead of `true` to see logs as json). log.SetLevel(log.DebugLevel) } @@ -69,7 +69,7 @@ func init(){ func main() { appInfo := gautocloud.GetAppInfo() // retrieve all informations about your application instance fmt.Println(appInfo.Name) // give the app name - // by injection + // by injection var c *dbtype.MysqlDB // this is just a wrapper of *net/sql.DB you can use as normal sql.DB client err := gautocloud.Inject(&c) // you can also use gautocloud.InjectFromId("mysql", &c) where "mysql" is the id of the connector to use if err != nil { @@ -78,14 +78,14 @@ func main() { defer c.Close() // c is now useable as a *sql.DB // e.g.: err = c.Ping() - + // or you can also do by return // data, err := gautocloud.GetFirst("mysql") // if err != nil { // panic(err) // } // c = data.(*dbtype.MysqlDB) - + } ``` @@ -98,21 +98,21 @@ import ( "github.com/cloudfoundry-community/gautocloud/connectors/databases/dbtype" ) func main() { - // by injection + // by injection var cs []*dbtype.MysqlDB // this is just a wrapper of *net/sql.DB you can use as normal sql.DB client err := gautocloud.Inject(&cs) // you can also use gautocloud.InjectFromId("mysql", &cs) where "mysql" is the id of the connector to use if err != nil { panic(err) } // you have now a slice containing all mysql client you can have - + // or you can also do by return // data, err := gautocloud.GetAll("mysql") // a connector may give you different types that's why GetAll return a slice of interface{} // cs = make([]*dbtype.MysqlDB,0) // for _, elt := range data { // svcSlice = append(cs, elt.(*dbtype.MysqlDB)) // } - + } ``` @@ -148,7 +148,7 @@ You can see connectors made by the community on the dedicated wiki page: https:/ ### Heroku -**Tip**: you can also use in local but settings the env var `DYNO` and create env var corresponding +**Tip**: you can also use in local but settings the env var `DYNO` and create env var corresponding to a service you want to connect. (see: [/test-integration/test_integration_test.go](/test-integration/test_integration_test.go) as an example) - **Cloud Detection**: if the `DYNO` env var exists @@ -160,7 +160,7 @@ you have env var: - `MY_SVC_HOST=localhost` Connector required name `SVC`. -CloudEnv decode `MY_SVC_NAME` to [MY, SVC, NAME] and [MY, SVC, VALUE] +CloudEnv decode `MY_SVC_NAME` to [MY, SVC, NAME] and [MY, SVC, VALUE] and detect that there is SVC in those two env var. It returns a service with credentials: { @@ -168,8 +168,8 @@ It returns a service with credentials: "host": "localhost" } ``` -**Note**: -- if a env var key doesn't contains `_` (e.g.: `SVC=localhost`) it will give those credentials: `{"svc": "localhost", "uri": "localhost"}`. +**Note**: +- if a env var key doesn't contain `_` (e.g.: `SVC=localhost`) it will give those credentials: `{"svc": "localhost", "uri": "localhost"}`. - If the value of an env var is in json it will be decode the json and pass content as credentials **Retrieves**: @@ -190,7 +190,7 @@ you have env var: - `MY_SVC_SERVICE_HOST=localhost` Connector required name `SVC`. -CloudEnv remove `_SERVICE` from the key and decode `MY_SVC_NAME` to [MY, SVC, NAME] and [MY, SVC, VALUE] +CloudEnv remove `_SERVICE` from the key and decode `MY_SVC_NAME` to [MY, SVC, NAME] and [MY, SVC, VALUE] and detect that there is SVC in those two env var. It returns a service with credentials: { @@ -209,7 +209,7 @@ It returns a service with credentials: - **App information properties**: - `host`: (type: *string*) host of the app. - All values starting by `KUBERNETES` in env vars key. - + ### Local This is a special *CloudEnv* and can be considered as a fake one. This is cloud env is always triggered if none cloud env was found. @@ -218,13 +218,13 @@ You can also use it to be able to use a config file directly without pain (but i You can set the env var `CLOUD_FILE` which contains the path of a configuration files containing services. -You can create a `config file` called `config.yml` in your current working directory or set the env var `CONFIG_FILE` -which contains the path of your config file. It can contains anything you wants, this will register by itself a service +You can create a `config file` called `config.yml` in your current working directory or set the env var `CONFIG_FILE` +which contains the path of your config file. It can contain anything you want, this will register by itself a service named `config` with tag `config` which contains you configuration from the file. A `config file` or a `cloud file` can be a `yml`, `json`, `toml` or `hcl` file. -A `config file` can contains anything you wants, this will register by itself a service named `config` with tag `config` +A `config file` can contains anything you want, this will register by itself a service named `config` with tag `config` which contains you configuration from the file. A `cloud file` must follow this pattern (example in yml): @@ -248,7 +248,7 @@ You can see how to follow the same pattern with other format here: [/cloudenv/lo - **App information name**: The name given in the config file, if not set it will be `` - **App information properties**: *None* -**NOTE**: A `config` service is always created which permit to use [ConfigFileInterceptor](https://godoc.org/github.com/cloudfoundry-community/gautocloud/interceptor/configfile#ConfigFileInterceptor) +**NOTE**: A `config` service is always created which permit to use [ConfigFileInterceptor](https://godoc.org/github.com/cloudfoundry-community/gautocloud/interceptor/configfile#ConfigFileInterceptor) this is a great interceptor to use with a [generic config connector](https://github.com/cloudfoundry-community/gautocloud/blob/master/docs/connectors.md#config). ## Concept @@ -259,16 +259,16 @@ Gautocloud have a lot of black magics but in fact the concept is quite simple. ![Architecture](/docs/arch.png) -- **Loader**: It has the responsibility to find the *CloudEnv* where your program run, store *Connector*s and retrieve -services from *CloudEnv* which corresponds to one or many *Connector* and finally it will pass to *Connector* the service +- **Loader**: It has the responsibility to find the *CloudEnv* where your program run, store *Connector*s and retrieve +services from *CloudEnv* which corresponds to one or many *Connector*, and finally it will pass to *Connector* the service and store the result from connector. -- **Gautocloud *facade***: This facade was made to make things easier for users. It store one instance of a *Loader* - and give the ability to make lazy loading (this is why to register a *Connector* you only need to do `import _ "a/connector"`) -- **CloudEnv**: Each *CloudEnv* correspond to a real cloud. It manages the detection of the environment but +- **Gautocloud *facade***: This facade was made to make things easier for users. It stores one instance of a *Loader* + and give the ability to make lazy loading (this is why to register a *Connector* you only need to do `import _ "a/connector"`) +- **CloudEnv**: Each *CloudEnv* correspond to a real cloud. It manages the detection of the environment but also the detections of services asked by the *Loader*. -- **Connector**: A connector register itself on the loader when using *Gautocloud Facade*. It handles the conversion of +- **Connector**: A connector register itself on the loader when using *Gautocloud Facade*. It handles the conversion of a service to a real client or structure which can be manipulated after by user. -- **CloudDecoder**: This decoder do the conversion of a service to an expected schema. +- **CloudDecoder**: This decoder do the conversion of a service to an expected schema. In *Gautocloud* context this decoder is used to convert a given service to an expected schema given by a connector. This decoder can be used in other context. (see: [/decoder/decoder.go](/decoder/decoder.go) to know about it) @@ -286,8 +286,8 @@ The best way is to look at an example here: [/connectors/connector_example_test. You can also want to see how to create connector with interceptor here: [/connectors/intercepter_example_test.go](/connectors/intercepter_example_test.go). -**Note**: -- An interceptor work like a http middleware. +**Note**: +- An interceptor work like a http middleware. This permit to intercept data which will be given back by gautocloud and modified it before giving back to user. Interceptor should be used in a connector, to do so, connector have to implement ConnectorIntercepter: ```go @@ -299,14 +299,14 @@ type ConnectorIntercepter interface { ## Create your own Cloud Environment -The best way to implement yourself a cloud environment is too look at interface here [/cloudenv/cloudenv.go](/cloudenv/cloudenv.go). +The best way to implement yourself a cloud environment, is to look at the following interface: [/cloudenv/cloudenv.go](/cloudenv/cloudenv.go). -You will need to load you cloud env after by [use gautocloud without facade](#use-it-without-the-facade), +You will need to load you cloud env after by [use gautocloud without facade](#use-it-without-the-facade), you can either do a pull request to had your cloud environment as builtin by doing a pull request. ## Use it without the facade -We will take the same example as we see in [Usage by example](#usage-by-example) but we will not use the facade this time: +We will take the same example as we see in [Usage by example](#usage-by-example), but we will not use the facade this time: ```go package main @@ -333,18 +333,18 @@ func main() { }, ) ld.RegisterConnector(mysql.NewMysqlConnector()) // you need to manually register connectors - + appInfo := ld.GetAppInfo() // retrieve all informations about your application instance fmt.Println(appInfo.Name) // give the app name fmt.Println(appInfo.Port) // give the port to listen to - // by injection + // by injection var c *dbtype.MysqlDB // this is just a wrapper of *net/sql.DB you can use as normal sql.DB client err := ld.Inject(&c) // you can also use gautocloud.InjectFromId("mysql", &c) where "mysql" is the id of the connector to use if err != nil { panic(err) } defer c.Close() - + } ``` @@ -354,8 +354,8 @@ If you need to write your tests with a mocked gautocloud (and use the facade), y To perform this, simply run your test with the tags `gautocloud_mock` (e.g.: `go test -tags gautocloud_mock`). -The facade will load a [gomock](https://github.com/golang/mock) version of the loader. -You can find, for example, how to perform injection with this mocked version here: +The facade will load a [gomock](https://github.com/golang/mock) version of the loader. +You can find, for example, how to perform injection with this mocked version here: [/test-mock/test_mock_test.go](/test-mock/test_mock_test.go) (see also [gomock documentation](https://github.com/golang/mock) to learn more) ## Run tests @@ -381,18 +381,18 @@ Don't be shy to send a PR to add another cloud environment as a builtin one. **Why do I need to import a connector even if it's a builtin one ?** -You need to import it because if you didn't have to it, it will requires to load all default connectors with -associated dependencies to the connector which can make a huge binary. +You need to import it because if you didn't have to it, it will require to load all default connectors with +associated dependencies to the connector which can make a huge binary. In our case, it will compile only what you need by importing the connector. - + **Why the *CloudEnv* interface works with a concept of tags and name?** - -This concept comes directly from Cloud Foundry and the way it gives services. Cloud Foundry has a api called -[service brokers](https://docs.cloudfoundry.org/services/api.html) this api return services with tags and name. -This concept will now be used in the future by a lot of cloud environment (PaaS and CaaS) because this api have now -a dedicated governance managed by people from Google (Kubernetes in mind), Pivotal (Cloud Foundry), Red Hat (Openshift) ... +This concept comes directly from Cloud Foundry and the way it gives services. Cloud Foundry has an API called +[service brokers](https://docs.cloudfoundry.org/services/api.html) this api return services with tags and name. + +This concept will now be used in the future by a lot of cloud environment (PaaS and CaaS) because this api have now +a dedicated governance managed by people from Google (Kubernetes in mind), Pivotal (Cloud Foundry), Red Hat (Openshift) ... You can found their website here: https://www.openservicebrokerapi.org/ diff --git a/bin/doc-generator/doc.tmpl.md b/bin/doc-generator/doc.tmpl.md index fcdf46b..6761511 100644 --- a/bin/doc-generator/doc.tmpl.md +++ b/bin/doc-generator/doc.tmpl.md @@ -16,13 +16,13 @@ This permit to intercept data which will be given back by gautocloud and modifie These connectors are specials connectors that final users need to register manually when needed. -One of usecase is to be able to retrieve configuration from services or simply add your own connector easily. +One of use-case is to be able to retrieve configuration from services or simply add your own connector easily. #### Schema based Add a straight forward connector which give back schema fed by loader. -This connector is also connector intercepter, it use interceptor [schema](https://godoc.org/github.com/cloudfoundry-community/gautocloud/interceptor#NewSchema) +This connector is also connector intercepter, it uses interceptor [schema](https://godoc.org/github.com/cloudfoundry-community/gautocloud/interceptor#NewSchema) as default interceptor. You can also set your interceptors to connector, they will be used only if struct does not implement interface [SchemaIntercepter](https://godoc.org/github.com/cloudfoundry-community/gautocloud/interceptor#SchemaIntercepter). @@ -90,7 +90,7 @@ func main() { This is a schema based connectors but `id`, `name` and `tags` are already set (can be registered multiple times). -This connector is a connector intercepter, it use the default interceptor [overwrite](https://godoc.org/github.com/cloudfoundry-community/gautocloud/interceptor#NewOverwrite) +This connector is a connector intercepter, it uses the default interceptor [overwrite](https://godoc.org/github.com/cloudfoundry-community/gautocloud/interceptor#NewOverwrite) which only be used if struct does not implement interface [SchemaIntercepter](https://godoc.org/github.com/cloudfoundry-community/gautocloud/interceptor#SchemaIntercepter) and if no interceptors has been given to connector. diff --git a/cloudenv/cf_cloudenv.go b/cloudenv/cf_cloudenv.go index 9d9dfce..77cb611 100644 --- a/cloudenv/cf_cloudenv.go +++ b/cloudenv/cf_cloudenv.go @@ -77,10 +77,7 @@ func (c CfCloudEnv) GetServicesFromName(name string) []Service { return c.convertCfServices(servicesFound) } func (c CfCloudEnv) IsInCloudEnv() bool { - if os.Getenv("VCAP_APPLICATION") != "" { - return true - } - return false + return os.Getenv("VCAP_APPLICATION") != "" } func (c CfCloudEnv) GetAppInfo() AppInfo { return AppInfo{ diff --git a/cloudenv/cf_cloudenv_test.go b/cloudenv/cf_cloudenv_test.go index a15a0c0..d4e20e6 100644 --- a/cloudenv/cf_cloudenv_test.go +++ b/cloudenv/cf_cloudenv_test.go @@ -34,7 +34,7 @@ var _ = Describe("CfCloudenv", func() { services := cloudEnv.GetServicesFromTags([]string{"postgres.*"}) Expect(services).Should(HaveLen(1)) }) - It("should give correct service(s) when have mulitple tag", func() { + It("should give correct service(s) when have multiple tag", func() { services := cloudEnv.GetServicesFromTags([]string{"postgresql", "smtp"}) Expect(services).Should(HaveLen(2)) }) diff --git a/cloudenv/cloudenv.go b/cloudenv/cloudenv.go index be6536d..81eecf1 100644 --- a/cloudenv/cloudenv.go +++ b/cloudenv/cloudenv.go @@ -1,26 +1,26 @@ -// It manages the detection of the environment but also the detections of services asked by a Loader. +// Package cloudenv It manages the detection of the environment but also the detections of services asked by a Loader. package cloudenv import "regexp" -// You must implement this interface if you want to add another cloud environment +// CloudEnv You must implement this interface if you want to add another cloud environment // See the cf_cloudenv or heroku_cloudenv or local_cloudenv to have an example of implementation type CloudEnv interface { - // name of your cloud environment (e.g.: cloud foundry, heroku, local ...) + // Name The name of your cloud environment (e.g.: cloud foundry, heroku, local ...) Name() string - // The loader will call this function and pass a list of tags + // GetServicesFromTags The loader will call this function and pass a list of tags // You will need to give services which match with those tags - // NOTE: tag can be an regex, better to take this in consideration + // Note: tag can be an regex, better to take this in consideration GetServicesFromTags(tags []string) []Service - // the loader will call this function and pass a service name as a regex + // GetServicesFromName The loader will call this function and pass a service name as a regex // You will need to give services which match with this name GetServicesFromName(name string) []Service - // The loader will call this function to see if this cloud envionment can be use + // IsInCloudEnv The loader will call this function to see if this cloud environment can be use // This function should detect the targeted environment IsInCloudEnv() bool - // The loader will call this method to load the environment + // Load The loader will call this method to load the environment Load() error - // This need to return information about application instance information + // GetAppInfo This need to return information about application instance information GetAppInfo() AppInfo } type AppInfo struct { diff --git a/connectors/connector.go b/connectors/connector.go index 5e261d8..8954bd9 100644 --- a/connectors/connector.go +++ b/connectors/connector.go @@ -1,9 +1,9 @@ -// It handles the conversion of a service to a real client or structure which can be manipulated after by user. +// Package connectors It handles the conversion of a service to a real client or structure which can be manipulated after by user. package connectors import "github.com/cloudfoundry-community/gautocloud/interceptor" -// this is the interface to be implemented to create a new connector +// Connector This is the interface to be implemented to create a new connector // You should add an init function in the same package of your connector and register it automatically in gautocloud when importing your connector // Example of init function: // @@ -13,21 +13,21 @@ import "github.com/cloudfoundry-community/gautocloud/interceptor" // // see implementation of any raw connectors to see how to implement a connector type Connector interface { - // This is the id of your connector and it must be unique and not have the same id of another connector - // Note: if a connector id is already taken gautocloud will complain + // Id This is the ID of your connector, and it must be unique and not have the same id of another connector + // Note: if a connector ID is already taken gautocloud will complain Id() string // Name is the name of a service to lookup in the cloud environment // Note: a regex can be passed Name() string - // This should return a list of tags which designed what kind of service you want + // Tags This should return a list of tags which designed what kind of service you want // example: mysql, database, rmdb ... // Note: a regex can be passed on each tag Tags() []string - // The parameter is a filled schema you gave in the function Schema - // The first value to return is what you want and you have no obligation to give always the same type. gautocloud is interface agnostic + // Load The parameter is a filled schema you gave in the function Schema + // The first value to return is what you want, and you have no obligation to give always the same type. gautocloud is interface agnostic // You can give an error if an error occurred, this error will appear in logs Load(interface{}) (interface{}, error) - // It must return a structure + // Schema It must return a structure // this structure will be used by the decoder to create a structure of the same type and filled with service's credentials found by a cloud environment // Here an example of what kind of structure you can return: // type MyStruct struct { @@ -40,7 +40,7 @@ type Connector interface { Schema() interface{} } -// If a connector want to intercept +// ConnectorIntercepter If a connector want to intercept type ConnectorIntercepter interface { Intercepter() interceptor.Intercepter } diff --git a/connectors/connector_example_test.go b/connectors/connector_example_test.go index 3995c73..8915467 100644 --- a/connectors/connector_example_test.go +++ b/connectors/connector_example_test.go @@ -36,7 +36,7 @@ func NewExampleConnector() connectors.Connector { return &ExampleConnector{} } -// This is the id of your connector and it must be unique and not have the same id of another connector +// IThis is the id of your connector, and it must be unique and not have the same id of another connector // Note: if a connector id is already taken gautocloud will complain func (c ExampleConnector) Id() string { return "example" @@ -56,7 +56,7 @@ func (c ExampleConnector) Tags() []string { } // The parameter is a filled schema you gave in the function Schema -// The first value to return is what you want and you have no obligation to give always the same type. gautocloud is interface agnostic +// The first value to return is what you want, and you have no obligation to give always the same type. gautocloud is interface agnostic // You can give an error if an error occurred, this error will appear in logs func (c ExampleConnector) Load(schema interface{}) (interface{}, error) { fSchema := schema.(ExampleSchema) diff --git a/connectors/intercepter_example_test.go b/connectors/intercepter_example_test.go index 812e4d8..a6e021b 100644 --- a/connectors/intercepter_example_test.go +++ b/connectors/intercepter_example_test.go @@ -58,7 +58,7 @@ func (c ExampleIntercepterConnector) Intercepter() interceptor.Intercepter { }) } -// This is the id of your connector and it must be unique and not have the same id of another connector +// This is the id of your connector, and it must be unique and not have the same id of another connector // Note: if a connector id is already taken gautocloud will complain func (c ExampleIntercepterConnector) Id() string { return "example" @@ -78,7 +78,7 @@ func (c ExampleIntercepterConnector) Tags() []string { } // The parameter is a filled schema you gave in the function Schema -// The first value to return is what you want and you have no obligation to give always the same type. gautocloud is interface agnostic +// The first value to return is what you want, and you have no obligation to give always the same type. gautocloud is interface agnostic // You can give an error if an error occurred, this error will appear in logs func (c ExampleIntercepterConnector) Load(schema interface{}) (interface{}, error) { fSchema := schema.(ExampleIntercepterSchema) diff --git a/decoder/decoder.go b/decoder/decoder.go index bfc6ea4..8874693 100644 --- a/decoder/decoder.go +++ b/decoder/decoder.go @@ -1,5 +1,5 @@ // Package decoder provide a way to decode credentials from a service to a structure -// It provide a cloud tag to help user match the correct credentials +// It provides a cloud tag to help user match the correct credentials // // This is what you can pass as a structure: // @@ -53,8 +53,8 @@ type QueryUri struct { Value string } -// The Unmarshaler interface may be implemented by types to customize their -// behavior when being unmarshaled from a Map cloud. The UnmarshalCloud +// Unmarshaler This interface may be implemented by types to customize their +// behavior when being unmarshalled from a Map cloud. The UnmarshalCloud // method receives a function that may be called to unmarshal the original // value into a field or variable. It is safe to call the unmarshal // function parameter more than once if necessary. @@ -62,7 +62,7 @@ type Unmarshaler interface { UnmarshalCloud(data interface{}) error } -// Decode a map of credentials into a reflected Value +// UnmarshalToValue Decode a map of credentials into a reflected Value func UnmarshalToValue(serviceCredentials map[string]interface{}, ps reflect.Value, noDefaultVal bool) error { v := ps if ps.Kind() == reflect.Ptr { @@ -117,13 +117,13 @@ func UnmarshalToValue(serviceCredentials map[string]interface{}, ps reflect.Valu return nil } -// Decode a map of credentials into a structure +// Unmarshal Decode a map of credentials into a structure func Unmarshal(serviceCredentials map[string]interface{}, obj interface{}) error { ps := reflect.ValueOf(obj) return UnmarshalToValue(serviceCredentials, ps, false) } -// Decode a map of credentials into a structure without default values +// UnmarshalNoDefault Decode a map of credentials into a structure without default values func UnmarshalNoDefault(serviceCredentials map[string]interface{}, obj interface{}) error { ps := reflect.ValueOf(obj) return UnmarshalToValue(serviceCredentials, ps, true) diff --git a/docs/connectors.md b/docs/connectors.md index d41b04f..bfe4d40 100644 --- a/docs/connectors.md +++ b/docs/connectors.md @@ -1,6 +1,6 @@ ## Connectors -A connector can be also a connector intercepter. An interceptor work like a http middleware. +A connector can be also a connector intercepter. An interceptor work like a http middleware. This permit to intercept data which will be given back by gautocloud and modified it before giving back to user. **Tip**: To load all default connectors import: `_ "github.com/cloudfoundry-community/gautocloud/connectors/all"` @@ -46,14 +46,14 @@ This permit to intercept data which will be given back by gautocloud and modifie These connectors are specials connectors that final users need to register manually when needed. -One of usecase is to be able to retrieve configuration from services or simply add your own connector easily. +One of use-case is to be able to retrieve configuration from services or simply add your own connector easily. #### Schema based Add a straight forward connector which give back schema fed by loader. -This connector is also connector intercepter, it use interceptor [schema](https://godoc.org/github.com/cloudfoundry-community/gautocloud/interceptor#NewSchema) -as default interceptor. +This connector is also connector intercepter, it uses interceptor [schema](https://godoc.org/github.com/cloudfoundry-community/gautocloud/interceptor#NewSchema) +as default interceptor. You can also set your interceptors to connector, they will be used only if struct does not implement interface [SchemaIntercepter](https://godoc.org/github.com/cloudfoundry-community/gautocloud/interceptor#SchemaIntercepter). @@ -120,8 +120,8 @@ func main() { This is a schema based connectors but `id`, `name` and `tags` are already set (can be registered multiple times). -This connector is a connector intercepter, it use the default interceptor [overwrite](https://godoc.org/github.com/cloudfoundry-community/gautocloud/interceptor#NewOverwrite) -which only be used if struct does not implement interface [SchemaIntercepter](https://godoc.org/github.com/cloudfoundry-community/gautocloud/interceptor#SchemaIntercepter) +This connector is a connector intercepter, it uses the default interceptor [overwrite](https://godoc.org/github.com/cloudfoundry-community/gautocloud/interceptor#NewOverwrite) +which only be used if struct does not implement interface [SchemaIntercepter](https://godoc.org/github.com/cloudfoundry-community/gautocloud/interceptor#SchemaIntercepter) and if no interceptors has been given to connector. You can find interceptors already created at https://godoc.org/github.com/cloudfoundry-community/gautocloud/interceptor . @@ -242,11 +242,11 @@ The type `amqptype.Amqp` can be found in package: `github.com/cloudfoundry-commu This type refers to this structure: ```go -type Amqp struct { - User string - Password string - Host string - Port int +type Amqp struct { + User string + Password string + Host string + Port int } ``` @@ -352,13 +352,13 @@ The type `dbtype.MongodbDatabase` can be found in package: `github.com/cloudfoun This type refers to this structure: ```go -type MongodbDatabase struct { - User string - Password string - Host string - Port int - Database string - Options string +type MongodbDatabase struct { + User string + Password string + Host string + Port int + Database string + Options string } ``` @@ -416,8 +416,8 @@ All of these connectors responds on: ##### Type documentation The type `*dbtype.MssqlDB` can be found in package: `github.com/cloudfoundry-community/gautocloud/connectors/databases/dbtype`. -The type `*dbtype.MssqlDB` is a wrapper on the real package `*sql.DB`, -you can find doc on real type here: [https://golang.org/pkg/database/sql](https://golang.org/pkg/database/sql). +The type `*dbtype.MssqlDB` is a wrapper on the real package `*sql.DB`, +you can find doc on real type here: [https://golang.org/pkg/database/sql](https://golang.org/pkg/database/sql). ##### Example @@ -513,13 +513,13 @@ The type `dbtype.MssqlDatabase` can be found in package: `github.com/cloudfoundr This type refers to this structure: ```go -type MssqlDatabase struct { - User string - Password string - Host string - Port int - Database string - Options string +type MssqlDatabase struct { + User string + Password string + Host string + Port int + Database string + Options string } ``` @@ -577,8 +577,8 @@ All of these connectors responds on: ##### Type documentation The type `*dbtype.MysqlDB` can be found in package: `github.com/cloudfoundry-community/gautocloud/connectors/databases/dbtype`. -The type `*dbtype.MysqlDB` is a wrapper on the real package `*sql.DB`, -you can find doc on real type here: [https://golang.org/pkg/database/sql](https://golang.org/pkg/database/sql). +The type `*dbtype.MysqlDB` is a wrapper on the real package `*sql.DB`, +you can find doc on real type here: [https://golang.org/pkg/database/sql](https://golang.org/pkg/database/sql). ##### Example @@ -674,13 +674,13 @@ The type `dbtype.MysqlDatabase` can be found in package: `github.com/cloudfoundr This type refers to this structure: ```go -type MysqlDatabase struct { - User string - Password string - Host string - Port int - Database string - Options string +type MysqlDatabase struct { + User string + Password string + Host string + Port int + Database string + Options string } ``` @@ -786,14 +786,14 @@ The type `schema.Oauth2Schema` can be found in package: `github.com/cloudfoundry This type refers to this structure: ```go -type Oauth2Schema struct { - AuthorizationUri string - UserInfoUri string - TokenUri string - ClientId string - ClientSecret string - GrantTypes []string - Scopes []string +type Oauth2Schema struct { + AuthorizationUri string + UserInfoUri string + TokenUri string + ClientId string + ClientSecret string + GrantTypes []string + Scopes []string } ``` @@ -853,13 +853,13 @@ The type `dbtype.OracleDatabase` can be found in package: `github.com/cloudfound This type refers to this structure: ```go -type OracleDatabase struct { - User string - Password string - Host string - Port int - Database string - Options string +type OracleDatabase struct { + User string + Password string + Host string + Port int + Database string + Options string } ``` @@ -916,8 +916,8 @@ All of these connectors responds on: ##### Type documentation The type `*dbtype.PostgresqlDB` can be found in package: `github.com/cloudfoundry-community/gautocloud/connectors/databases/dbtype`. -The type `*dbtype.PostgresqlDB` is a wrapper on the real package `*sql.DB`, -you can find doc on real type here: [https://golang.org/pkg/database/sql](https://golang.org/pkg/database/sql). +The type `*dbtype.PostgresqlDB` is a wrapper on the real package `*sql.DB`, +you can find doc on real type here: [https://golang.org/pkg/database/sql](https://golang.org/pkg/database/sql). ##### Example @@ -1013,13 +1013,13 @@ The type `dbtype.PostgresqlDatabase` can be found in package: `github.com/cloudf This type refers to this structure: ```go -type PostgresqlDatabase struct { - User string - Password string - Host string - Port int - Database string - Options string +type PostgresqlDatabase struct { + User string + Password string + Host string + Port int + Database string + Options string } ``` @@ -1125,10 +1125,10 @@ The type `dbtype.RedisDatabase` can be found in package: `github.com/cloudfoundr This type refers to this structure: ```go -type RedisDatabase struct { - Password string - Host string - Port int +type RedisDatabase struct { + Password string + Host string + Port int } ``` @@ -1234,9 +1234,9 @@ The type `*miniotype.MinioClient` can be found in package: `github.com/cloudfoun This type refers to this structure: ```go -type MinioClient struct { +type MinioClient struct { Client *minio.Client // See doc: https://github.com/minio/minio-go - Bucket string + Bucket string } ``` @@ -1286,13 +1286,13 @@ The type `objstoretype.S3` can be found in package: `github.com/cloudfoundry-com This type refers to this structure: ```go -type S3 struct { - Host string - AccessKeyID string - SecretAccessKey string - Bucket string - Port int - UseSsl bool +type S3 struct { + Host string + AccessKeyID string + SecretAccessKey string + Bucket string + Port int + UseSsl bool } ``` @@ -1399,11 +1399,11 @@ The type `smtptype.Smtp` can be found in package: `github.com/cloudfoundry-commu This type refers to this structure: ```go -type Smtp struct { - User string - Password string - Host string - Port int +type Smtp struct { + User string + Password string + Host string + Port int } ``` diff --git a/interceptor/cli/arg/arg.go b/interceptor/cli/arg/arg.go index c79f12c..277fd2e 100644 --- a/interceptor/cli/arg/arg.go +++ b/interceptor/cli/arg/arg.go @@ -1,6 +1,6 @@ -// This is an interceptor dedicated to push flags found to the final schema given by gautocloud. +// Package arg This is an interceptor dedicated to push flags found to the final schema given by gautocloud. // if flags is not a zero value it will override value from schema given by gautocloud. -// It use https://github.com/alexflint/go-arg to translate flags into a struct. +// It uses https://github.com/alexflint/go-arg to translate flags into a struct. package arg import ( @@ -19,7 +19,7 @@ type ArgInterceptor struct { exit bool } -// Option to set arg.Config from https://github.com/alexflint/go-arg +// Config Option to set arg.Config from https://github.com/alexflint/go-arg // Default: arg.Config{} func Config(config arg.Config) optSetter { return func(f *ArgInterceptor) { @@ -27,7 +27,7 @@ func Config(config arg.Config) optSetter { } } -// Option to set args to be parsed as flags +// Args Option to set args to be parsed as flags // Default: os.Args func Args(args []string) optSetter { return func(f *ArgInterceptor) { @@ -35,7 +35,7 @@ func Args(args []string) optSetter { } } -// Option to set writer for output +// Writer Option to set writer for output // Default: os.Stdout func Writer(w io.Writer) optSetter { return func(f *ArgInterceptor) { @@ -43,7 +43,7 @@ func Writer(w io.Writer) optSetter { } } -// Option to exit program or not when --help or --version flags has been found +// Exit Option to exit program or not when --help or --version flags has been found // Default: true func Exit(exit bool) optSetter { return func(f *ArgInterceptor) { diff --git a/interceptor/cli/urfave/cli.go b/interceptor/cli/urfave/cli.go index 922ade9..114d2c8 100644 --- a/interceptor/cli/urfave/cli.go +++ b/interceptor/cli/urfave/cli.go @@ -1,4 +1,4 @@ -// This is an interceptor dedicated to push flags from https://github.com/urfave/cli to the final schema given by gautocloud. +// Package urfave This is an interceptor dedicated to push flags from https://github.com/urfave/cli to the final schema given by gautocloud. // if flags is not a zero value it will override value from schema given by gautocloud. package urfave @@ -20,7 +20,7 @@ func NewCli() *CliInterceptor { } func (i CliInterceptor) Intercept(current, found interface{}) (interface{}, error) { if i.context == nil { - return nil, fmt.Errorf("Context must be passed to CliInterceptor, please set it with SetContext") + return nil, fmt.Errorf("context must be passed to CliInterceptor, please set it with SetContext") } schema := current if schema == nil { diff --git a/interceptor/cli/urfave/doc_test.go b/interceptor/cli/urfave/doc_test.go index 1d73c21..f5082a0 100644 --- a/interceptor/cli/urfave/doc_test.go +++ b/interceptor/cli/urfave/doc_test.go @@ -32,7 +32,7 @@ func Example() { // We pass context to interceptor, this is mandatory cliInterceptor.SetContext(c) - // We asking to retrieve a config schema through injection + // We are asking to retrieve a config schema through injection err := gautocloud.Inject(&config) if err != nil { panic(err) diff --git a/interceptor/intercepter.go b/interceptor/intercepter.go index 89affc9..444ba6d 100644 --- a/interceptor/intercepter.go +++ b/interceptor/intercepter.go @@ -1,4 +1,4 @@ -// This permit to intercept data which will be given back by gautocloud and modified it before giving back to user. +// Package interceptor This permit to intercept data which will be given back by gautocloud and modified it before giving back to user. // Interceptor should be used in a connector, to do so, connector have to implement ConnectorIntercepter: // // type ConnectorIntercepter interface { @@ -8,7 +8,7 @@ // An interceptor work like a http middleware. package interceptor -// This is the interface to implement to create an interceptor +// Intercepter This is the interface to implement to create an interceptor type Intercepter interface { // Current is interface given by user when using gautocloud.Inject(interfaceFromUser{}), // this can be nil if user doesn't use Inject functions from gautocloud. @@ -20,7 +20,7 @@ type Intercepter interface { Intercept(current, found interface{}) (interface{}, error) } -// The IntercepterFunc type is an adapter to allow the use of +// IntercepterFunc The IntercepterFunc type is an adapter to allow the use of // ordinary functions as Intercepter. If f is a function // with the appropriate signature, IntercepterFunc(f) is a // Intercepter that calls f. diff --git a/interceptor/overwrite.go b/interceptor/overwrite.go index a120888..e3403c8 100644 --- a/interceptor/overwrite.go +++ b/interceptor/overwrite.go @@ -4,7 +4,7 @@ import ( "reflect" ) -// This interceptor function let the user pre filled values inside is config structure to be used instead of use values +// NewOverwrite This interceptor function let the user pre-filled values inside is config structure to be used instead of use values // found by gautocloud. // This is useful for schema used in connector generic Config to let user write some values from config // before fill the rest by gautocloud. diff --git a/interceptor/schema.go b/interceptor/schema.go index 6ae63ee..eb3e569 100644 --- a/interceptor/schema.go +++ b/interceptor/schema.go @@ -5,15 +5,15 @@ import ( "reflect" ) -// User must implement this interface on his struct/schema to be able to intercept injected value from gautocloud. -// User could now modified his own schema, gautocloud will use user schema as injection. +// SchemaIntercepter User must implement this interface on his struct/schema to be able to intercept injected value from gautocloud. +// User could now modify his own schema, gautocloud will use user schema as injection. type SchemaIntercepter interface { - // Found is the interface found by gautocloud. It has the exactly same type than the struct/schema which implements + // "Found" is the interface found by gautocloud. It has the exactly same type than the struct/schema which implements // this interface. Intercept(found interface{}) error } -// Interceptor to let user implements himself write an interception on his struct/schema. +// NewSchema Interceptor to let user implements himself write an interception on his struct/schema. // This interceptor will call function Intercept if schema/struct implements SchemaIntercepter from current. // It will return an error from intercept function if there is or the current interface after modification. // Tips: If current not found (user doesn't use inject functions from gautocloud) this is schema found which will be used @@ -37,7 +37,7 @@ func schema(current, found interface{}) (interface{}, error) { currentCopyElem := currentValue.Elem() currentCopy := currentCopyElem.Interface() if _, ok := currentCopy.(SchemaIntercepter); !ok { - return nil, fmt.Errorf("schema does not implement SchemaIntercepter.") + return nil, fmt.Errorf("schema does not implement SchemaIntercepter") } err := currentCopy.(SchemaIntercepter).Intercept(found) if err != nil { @@ -51,7 +51,7 @@ func schema(current, found interface{}) (interface{}, error) { currentCopyPtr.Elem().Set(currentValue) currentCopy := currentCopyPtr.Interface() if _, ok := currentCopy.(SchemaIntercepter); !ok { - return nil, fmt.Errorf("schema does not implement SchemaIntercepter.") + return nil, fmt.Errorf("schema does not implement SchemaIntercepter") } err := currentCopy.(SchemaIntercepter).Intercept(found) if err != nil { diff --git a/loader/fake/fake_loader.go b/loader/fake/fake_loader.go index 88053cd..96750f2 100644 --- a/loader/fake/fake_loader.go +++ b/loader/fake/fake_loader.go @@ -8,13 +8,13 @@ import ( "log" ) -// Mock of Loader interface +// MockLoader Mock of Loader interface type MockLoader struct { ctrl *gomock.Controller recorder *_MockLoaderRecorder } -// Recorder for MockLoader (not exported) +// _MockLoaderRecorder Recorder for MockLoader (not exported) type _MockLoaderRecorder struct { mock *MockLoader } diff --git a/loader/loader.go b/loader/loader.go index 95b273c..a3e5de3 100644 --- a/loader/loader.go +++ b/loader/loader.go @@ -1,4 +1,4 @@ -// It has the responsibility to find the *CloudEnv* where your program run, store *Connector*s and retrieve +// Package loader It has the responsibility to find the *CloudEnv* where your program run, store *Connector*s and retrieve // services from *CloudEnv* which corresponds to one or many *Connector* and finally it will pass to *Connector* the service // and store the result from connector. package loader @@ -60,7 +60,7 @@ func newLoader(cloudEnvs []cloudenv.CloudEnv, logger *log.Logger) Loader { return loader } -// Create a new loader with cloud environment given +// NewLoader Create a new loader with cloud environment given func NewLoader(cloudEnvs []cloudenv.CloudEnv) Loader { if os.Getenv(DEBUG_MODE_ENV_VAR) != "" { log.SetLevel(log.DebugLevel) @@ -68,17 +68,17 @@ func NewLoader(cloudEnvs []cloudenv.CloudEnv) Loader { return newLoader(cloudEnvs, log.StandardLogger()) } -// Return all cloud environments loaded +// CloudEnvs Return all cloud environments loaded func (l GautocloudLoader) CloudEnvs() []cloudenv.CloudEnv { return l.cloudEnvs } -// Remove all registered connectors +// CleanConnectors Remove all registered connectors func (l *GautocloudLoader) CleanConnectors() { l.connectors = make(map[string]connectors.Connector) } -// Return all services loaded +// Store Return all services loaded func (l *GautocloudLoader) Store() map[string][]StoredService { return l.store } @@ -87,7 +87,7 @@ func logMessage(message string) string { return LOG_MESSAGE_PREFIX + ": " + message } -// Register a connector in the loader +// RegisterConnector Register a connector in the loader // This is mainly use for connectors creators func (l *GautocloudLoader) RegisterConnector(connector connectors.Connector) { if _, ok := l.connectors[connector.Id()]; ok { @@ -110,7 +110,7 @@ func (l *GautocloudLoader) RegisterConnector(connector connectors.Connector) { entry.Debugf(logMessage("Finished loading connector.")) } -// Return all registered connectors +// Connectors Return all registered connectors func (l GautocloudLoader) Connectors() map[string]connectors.Connector { return l.connectors } @@ -139,7 +139,7 @@ func (l GautocloudLoader) LoadCloudEnvs() { } } -// Reload connectors to find services +// ReloadConnectors Reload connectors to find services func (l *GautocloudLoader) ReloadConnectors() { l.LoadCloudEnvs() err := l.checkInCloudEnv() @@ -191,12 +191,12 @@ func (l GautocloudLoader) Inject(service interface{}) error { return NewErrGiveService("Service with the type " + reflectType.String() + " cannot be found. (perhaps no services match any connectors)") } -// Return the current cloud env detected +// CurrentCloudEnv Return the current cloud env detected func (l GautocloudLoader) CurrentCloudEnv() cloudenv.CloudEnv { return l.getFirstValidCloudEnv() } -// Return informations about instance of the running application +// GetAppInfo Return information about instance of the running application func (l GautocloudLoader) GetAppInfo() cloudenv.AppInfo { return l.getFirstValidCloudEnv().GetAppInfo() } @@ -214,7 +214,7 @@ func (l GautocloudLoader) getCloudEnvNames() []string { return names } -// Return true if you are in a cloud environment +// IsInACloudEnv Return true if you are in a cloud environment func (l GautocloudLoader) IsInACloudEnv() bool { for _, cloudEnv := range l.cloudEnvs { if !cloudEnv.IsInCloudEnv() { @@ -235,7 +235,7 @@ func (l GautocloudLoader) getFirstValidCloudEnv() cloudenv.CloudEnv { return finalCloudEnv } -// Inject service(s) found by a connector with given type +// InjectFromId Inject service(s) found by a connector with given type // id is the id of a connector // Example: // @@ -330,7 +330,7 @@ func (l GautocloudLoader) getData(store StoredService, current interface{}) (int return finalData, err } -// Return the first service found by a connector +// GetFirst Return the first service found by a connector // id is the id of a connector // Example: // @@ -338,7 +338,7 @@ func (l GautocloudLoader) getData(store StoredService, current interface{}) (int // data, err = gautocloud.GetFirst("mysql") // svc = data.(*dbtype.MysqlDB) // -// It returns the first service found or an error if no service can be found or if the connector doesn't exists +// It returns the first service found or an error if no service can be found or if the connector doesn't exist func (l GautocloudLoader) GetFirst(id string) (interface{}, error) { err := l.checkInCloudEnv() if err != nil { @@ -364,7 +364,7 @@ func (l GautocloudLoader) checkConnectorIdExist(id string) error { return nil } -// Return all services found by a connector +// GetAll Return all services found by a connector // id is the id of a connector // Example: // @@ -373,7 +373,7 @@ func (l GautocloudLoader) checkConnectorIdExist(id string) error { // svc = data[0].(*dbtype.MysqlDB) // // warning: a connector may give you different types that's why GetAll return a slice of interface{} -// It returns the first service found or an error if no service can be found or if the connector doesn't exists +// It returns the first service found or an error if no service can be found or if the connector doesn't exist func (l GautocloudLoader) GetAll(id string) ([]interface{}, error) { err := l.checkInCloudEnv() if err != nil { diff --git a/loader/loader_test.go b/loader/loader_test.go index c39e460..6f51ba4 100644 --- a/loader/loader_test.go +++ b/loader/loader_test.go @@ -341,7 +341,7 @@ var _ = Describe("Loader", func() { fakeInterceptor := fakecon.NewFakeInterceptor( FakeSchema{}, interceptor.IntercepterFunc(func(current, old interface{}) (interface{}, error) { - return nil, fmt.Errorf("Error from intercepter") + return nil, fmt.Errorf("error from intercepter") }), ) loader.RegisterConnector(fakeInterceptor) @@ -350,7 +350,7 @@ var _ = Describe("Loader", func() { err := loader.InjectFromId(connector.Id(), &data) Expect(err).To(HaveOccurred()) - Expect(err.Error()).Should(ContainSubstring("Error from intercepter")) + Expect(err.Error()).Should(ContainSubstring("error from intercepter")) }) }) It("should return an error if content to inject is not a pointer", func() { diff --git a/main.go b/main.go index db191bc..dff7f08 100644 --- a/main.go +++ b/main.go @@ -6,17 +6,17 @@ import ( "github.com/cloudfoundry-community/gautocloud/loader" ) -// Return the loader used by the facade +// Loader Return the loader used by the facade func Loader() loader.Loader { return defaultLoader } -// Reload connectors to find services +// ReloadConnectors Reload connectors to find services func ReloadConnectors() { defaultLoader.ReloadConnectors() } -// Register a connector in the loader +// RegisterConnector Register a connector in the loader // This is mainly use for connectors creators func RegisterConnector(connector connectors.Connector) { defaultLoader.RegisterConnector(connector) @@ -36,7 +36,7 @@ func Inject(service interface{}) error { return defaultLoader.Inject(service) } -// Inject service(s) found by a connector with given type +// InjectFromId Inject service(s) found by a connector with given type // id is the id of a connector // Example: // @@ -51,7 +51,7 @@ func InjectFromId(id string, service interface{}) error { return defaultLoader.InjectFromId(id, service) } -// Return the first service found by a connector +// GetFirst Return the first service found by a connector // id is the id of a connector // Example: // @@ -59,12 +59,12 @@ func InjectFromId(id string, service interface{}) error { // data, err = gautocloud.GetFirst("mysql") // svc = data.(*dbtype.MysqlDB) // -// It returns the first service found or an error if no service can be found or if the connector doesn't exists +// It returns the first service found or an error if no service can be found or if the connector does not exist func GetFirst(id string) (interface{}, error) { return defaultLoader.GetFirst(id) } -// Return all services found by a connector +// GetAll Return all services found by a connector // id is the id of a connector // Example: // @@ -73,42 +73,42 @@ func GetFirst(id string) (interface{}, error) { // svc = data[0].(*dbtype.MysqlDB) // // warning: a connector may give you different types that's why GetAll return a slice of interface{} -// It returns the first service found or an error if no service can be found or if the connector doesn't exists +// It returns the first service found or an error if no service can be found or if the connector does not exist func GetAll(id string) ([]interface{}, error) { return defaultLoader.GetAll(id) } -// Return all cloud environments loaded +// CloudEnvs Return all cloud environments loaded func CloudEnvs() []cloudenv.CloudEnv { return defaultLoader.CloudEnvs() } -// Return all registered connectors +// Connectors Return all registered connectors func Connectors() map[string]connectors.Connector { return defaultLoader.Connectors() } -// Return all services loaded +// Store Return all services loaded func Store() map[string][]loader.StoredService { return defaultLoader.Store() } -// Remove all registered connectors +// CleanConnectors Remove all registered connectors func CleanConnectors() { defaultLoader.CleanConnectors() } -// Return the current cloud env detected +// CurrentCloudEnv Return the current cloud env detected func CurrentCloudEnv() cloudenv.CloudEnv { return defaultLoader.CurrentCloudEnv() } -// Return informations about instance of the running application +// GetAppInfo Return information about instance of the running application func GetAppInfo() cloudenv.AppInfo { return defaultLoader.GetAppInfo() } -// Return true if you are in a cloud environment +// IsInACloudEnv Return true if you are in a cloud environment func IsInACloudEnv() bool { return defaultLoader.IsInACloudEnv() } From 489c0c345fce35a9db882c3e832f592bb84bc959 Mon Sep 17 00:00:00 2001 From: Romain Dartigues Date: Wed, 15 May 2024 15:08:41 +0200 Subject: [PATCH 11/20] NewErrGiveService doesn't have side effects and its return value is ignored --- loader/loader.go | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/loader/loader.go b/loader/loader.go index a3e5de3..033a5a0 100644 --- a/loader/loader.go +++ b/loader/loader.go @@ -317,13 +317,16 @@ func (l GautocloudLoader) getData(store StoredService, current interface{}) (int entry.Debug(logMessage("Data intercepting by interceptor given by connector...")) finalData, err := store.Interceptor.Intercept(current, store.Data) if err != nil { - NewErrGiveService( + err := NewErrGiveService( fmt.Sprintf( "Error from interceptor given by connector for the type '%s': %s", store.ReflectType.String(), err.Error(), ), ) + if err != nil { + return nil, err + } return store.Data, err } entry.Debug(logMessage("Finished data intercepting by interceptor given by connector.")) From f7a8bcb8700de25e00417309ef2f301f9b1a16c0 Mon Sep 17 00:00:00 2001 From: Romain Dartigues Date: Wed, 15 May 2024 15:09:55 +0200 Subject: [PATCH 12/20] this value of is never used --- test-integration/test_integration_test.go | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/test-integration/test_integration_test.go b/test-integration/test_integration_test.go index b37f630..05a4fcc 100644 --- a/test-integration/test_integration_test.go +++ b/test-integration/test_integration_test.go @@ -636,7 +636,7 @@ var _ = Describe("Connectors integration", func() { Expect(svc).ShouldNot(BeNil()) err = svc.Put("myfile.txt", []byte("data"), "", s3.PublicRead, s3.Options{}) Expect(err).ToNot(HaveOccurred()) - b, err := svc.Get("myfile.txt") + b, _ := svc.Get("myfile.txt") Expect(string(b)).Should(Equal("data")) err = svc.Del("myfile.txt") Expect(err).ToNot(HaveOccurred()) @@ -650,7 +650,7 @@ var _ = Describe("Connectors integration", func() { Expect(svc).ShouldNot(BeNil()) err = svc.Put("myfile.txt", []byte("data"), "", s3.PublicRead, s3.Options{}) Expect(err).ToNot(HaveOccurred()) - b, err := svc.Get("myfile.txt") + b, _ := svc.Get("myfile.txt") Expect(string(b)).Should(Equal("data")) err = svc.Del("myfile.txt") Expect(err).ToNot(HaveOccurred()) @@ -662,7 +662,7 @@ var _ = Describe("Connectors integration", func() { Expect(svc).ShouldNot(BeNil()) err = svc.Put("myfile.txt", []byte("data"), "", s3.PublicRead, s3.Options{}) Expect(err).ToNot(HaveOccurred()) - b, err := svc.Get("myfile.txt") + b, _ := svc.Get("myfile.txt") Expect(string(b)).Should(Equal("data")) err = svc.Del("myfile.txt") Expect(err).ToNot(HaveOccurred()) @@ -676,7 +676,7 @@ var _ = Describe("Connectors integration", func() { Expect(svc).ShouldNot(BeNil()) err = svc.Put("myfile.txt", []byte("data"), "", s3.PublicRead, s3.Options{}) Expect(err).ToNot(HaveOccurred()) - b, err := svc.Get("myfile.txt") + b, _ := svc.Get("myfile.txt") Expect(string(b)).Should(Equal("data")) err = svc.Del("myfile.txt") Expect(err).ToNot(HaveOccurred()) @@ -691,7 +691,7 @@ var _ = Describe("Connectors integration", func() { Expect(svc).ShouldNot(BeNil()) err = svc.Put("myfile.txt", []byte("data"), "", s3.PublicRead, s3.Options{}) Expect(err).ToNot(HaveOccurred()) - b, err := svc.Get("myfile.txt") + b, _ := svc.Get("myfile.txt") Expect(string(b)).Should(Equal("data")) err = svc.Del("myfile.txt") Expect(err).ToNot(HaveOccurred()) @@ -705,7 +705,7 @@ var _ = Describe("Connectors integration", func() { Expect(svc).ShouldNot(BeNil()) err = svc.Put("myfile.txt", []byte("data"), "", s3.PublicRead, s3.Options{}) Expect(err).ToNot(HaveOccurred()) - b, err := svc.Get("myfile.txt") + b, _ := svc.Get("myfile.txt") Expect(string(b)).Should(Equal("data")) err = svc.Del("myfile.txt") Expect(err).ToNot(HaveOccurred()) From bb7580677ca073a9ebf0271a6fd7066416c5ad5b Mon Sep 17 00:00:00 2001 From: Romain Dartigues Date: Wed, 15 May 2024 15:13:39 +0200 Subject: [PATCH 13/20] lint: disable unused check because I am unsure --- cloudenv/cf_cloudenv.go | 2 ++ cloudenv/local_cloudenv.go | 1 + 2 files changed, 3 insertions(+) diff --git a/cloudenv/cf_cloudenv.go b/cloudenv/cf_cloudenv.go index 77cb611..456affb 100644 --- a/cloudenv/cf_cloudenv.go +++ b/cloudenv/cf_cloudenv.go @@ -44,6 +44,8 @@ func (c CfCloudEnv) convertCfServices(cfServices []cfenv.Service) []Service { } return services } + +// nolint:unused func (c CfCloudEnv) initAppEnv() error { if !c.IsInCloudEnv() { return nil diff --git a/cloudenv/local_cloudenv.go b/cloudenv/local_cloudenv.go index 0573aee..1ea19fe 100644 --- a/cloudenv/local_cloudenv.go +++ b/cloudenv/local_cloudenv.go @@ -225,6 +225,7 @@ func (c LocalCloudEnv) configPath() string { return confPath } +// nolint:unused func (c LocalCloudEnv) hasConfigFile() bool { return os.Getenv(LOCAL_CONFIG_ENV_KEY) != "" } From 14d1473f35bb2ea425807669c24b48b1ec79391c Mon Sep 17 00:00:00 2001 From: Romain Dartigues Date: Wed, 15 May 2024 15:14:43 +0200 Subject: [PATCH 14/20] type assertion to the same type: currentIntercept already has type SchemaIntercepter --- interceptor/schema.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/interceptor/schema.go b/interceptor/schema.go index eb3e569..6362d51 100644 --- a/interceptor/schema.go +++ b/interceptor/schema.go @@ -27,7 +27,7 @@ func schema(current, found interface{}) (interface{}, error) { schema = found } if currentIntercept, ok := schema.(SchemaIntercepter); ok { - err := currentIntercept.(SchemaIntercepter).Intercept(found) + err := currentIntercept.Intercept(found) return schema, err } currentType := reflect.TypeOf(schema) From e2a5b2a6ff371093594138b6a70d07f6a8442854 Mon Sep 17 00:00:00 2001 From: Romain Dartigues Date: Wed, 15 May 2024 15:16:36 +0200 Subject: [PATCH 15/20] redundant type conversion --- decoder/decoder.go | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/decoder/decoder.go b/decoder/decoder.go index 8874693..f4d39bf 100644 --- a/decoder/decoder.go +++ b/decoder/decoder.go @@ -488,9 +488,9 @@ func convertStringValue(defVal string, vField reflect.Value) (interface{}, error if err != nil { return "", err } - return int64(val), nil + return val, nil case reflect.Uint: - val, err := strconv.ParseUint(defVal, 10, int(strconv.IntSize)) + val, err := strconv.ParseUint(defVal, 10, strconv.IntSize) if err != nil { return "", err } @@ -518,7 +518,7 @@ func convertStringValue(defVal string, vField reflect.Value) (interface{}, error if err != nil { return "", err } - return uint64(val), nil + return val, nil case reflect.Bool: return strconv.ParseBool(defVal) case reflect.Float32: From 83c2db500bf50fd9b9e888e8fef63de9f8d6968b Mon Sep 17 00:00:00 2001 From: Romain Dartigues Date: Wed, 15 May 2024 15:19:48 +0200 Subject: [PATCH 16/20] remove redundant break statement --- decoder/decoder.go | 18 ------------------ 1 file changed, 18 deletions(-) diff --git a/decoder/decoder.go b/decoder/decoder.go index f4d39bf..49e008c 100644 --- a/decoder/decoder.go +++ b/decoder/decoder.go @@ -180,37 +180,26 @@ func affect(data interface{}, vField reflect.Value, noDefaultVal bool) error { switch vField.Kind() { case reflect.String: vField.SetString(data.(string)) - break case reflect.Int: vField.SetInt(int64(parseForInt(data, vField).(int))) - break case reflect.Int8: vField.SetInt(int64(parseForInt(data, vField).(int8))) - break case reflect.Int16: vField.SetInt(int64(parseForInt(data, vField).(int16))) - break case reflect.Int32: vField.SetInt(int64(parseForInt(data, vField).(int32))) - break case reflect.Int64: vField.SetInt(parseForInt(data, vField).(int64)) - break case reflect.Uint: vField.SetUint(uint64(parseForInt(data, vField).(uint))) - break case reflect.Uint8: vField.SetUint(uint64(parseForInt(data, vField).(uint8))) - break case reflect.Uint16: vField.SetUint(uint64(parseForInt(data, vField).(uint16))) - break case reflect.Uint32: vField.SetUint(uint64(parseForInt(data, vField).(uint32))) - break case reflect.Uint64: vField.SetUint(parseForInt(data, vField).(uint64)) - break case reflect.Slice: if vField.IsNil() { vField.Set(reflect.MakeSlice(reflect.SliceOf(vField.Type().Elem()), 0, 0)) @@ -253,19 +242,14 @@ func affect(data interface{}, vField reflect.Value, noDefaultVal bool) error { } vField.Set(reflect.Append(vField, newElem)) } - break case reflect.Interface: vField.Set(reflect.ValueOf(data)) - break case reflect.Bool: vField.SetBool(data.(bool)) - break case reflect.Float32: vField.SetFloat(parseForFloat(data, vField)) - break case reflect.Float64: vField.SetFloat(parseForFloat(data, vField)) - break case reflect.Ptr: if vField.IsNil() { vField.Set(reflect.New(vField.Type().Elem())) @@ -281,7 +265,6 @@ func affect(data interface{}, vField reflect.Value, noDefaultVal bool) error { if err != nil { return err } - break default: servUriType := reflect.TypeOf(ServiceUri{}) if vField.Type() != servUriType && reflect.TypeOf(data) != reflect.TypeOf(make(map[string]interface{})) { @@ -300,7 +283,6 @@ func affect(data interface{}, vField reflect.Value, noDefaultVal bool) error { } serviceUri := urlToServiceUri(serviceUrl) vField.Set(reflect.ValueOf(serviceUri)) - break } return nil } From adef72551dee71e562916fc02951083cc7fec259 Mon Sep 17 00:00:00 2001 From: Romain Dartigues Date: Wed, 15 May 2024 15:20:51 +0200 Subject: [PATCH 17/20] use fmt.Errorf instead of errors.New(fmt...) --- decoder/decoder.go | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/decoder/decoder.go b/decoder/decoder.go index 49e008c..ebff166 100644 --- a/decoder/decoder.go +++ b/decoder/decoder.go @@ -14,7 +14,6 @@ package decoder import ( "encoding/json" - "errors" "fmt" "github.com/azer/snakecase" "net/url" @@ -205,7 +204,7 @@ func affect(data interface{}, vField reflect.Value, noDefaultVal bool) error { vField.Set(reflect.MakeSlice(reflect.SliceOf(vField.Type().Elem()), 0, 0)) } if reflect.ValueOf(data).Kind() != reflect.Slice { - return errors.New(fmt.Sprintf("Type '%s' have not receive a slice.", vField.String())) + return fmt.Errorf("type '%s' have not receive a slice", vField.String()) } dataValue := reflect.ValueOf(data) From 3105620f3bc72ce03c189e82f5ea2ff499afa668 Mon Sep 17 00:00:00 2001 From: Romain Dartigues Date: Wed, 15 May 2024 15:31:18 +0200 Subject: [PATCH 18/20] module github.com/streadway/amqp is deprecated in favor to github.com/rabbitmq/amqp091-go --- connectors/amqp/client/amqp_connector.go | 2 +- docs/connectors.md | 7 +++---- go.mod | 2 +- go.sum | 6 ++++-- test-integration/test_integration_test.go | 2 +- 5 files changed, 10 insertions(+), 9 deletions(-) diff --git a/connectors/amqp/client/amqp_connector.go b/connectors/amqp/client/amqp_connector.go index df42d53..5f061e5 100644 --- a/connectors/amqp/client/amqp_connector.go +++ b/connectors/amqp/client/amqp_connector.go @@ -6,7 +6,7 @@ import ( "github.com/cloudfoundry-community/gautocloud/connectors" "github.com/cloudfoundry-community/gautocloud/connectors/amqp/amqptype" "github.com/cloudfoundry-community/gautocloud/connectors/amqp/raw" - "github.com/streadway/amqp" + amqp "github.com/rabbitmq/amqp091-go" ) func init() { diff --git a/docs/connectors.md b/docs/connectors.md index bfe4d40..871c702 100644 --- a/docs/connectors.md +++ b/docs/connectors.md @@ -191,9 +191,8 @@ All of these connectors responds on: **Tip**: You can load all based *Amqp Client* by importing: `_ "github.com/cloudfoundry-community/gautocloud/connectors/amqp"` ##### Type documentation -The type `*amqp.Connection` can be found in package: `github.com/streadway/amqp`. - -You can find documentation related to package `github.com/streadway/amqp` here: [https://github.com/streadway/amqp](https://github.com/streadway/amqp). +The type `*amqp.Connection` can be found in package: `github.com/rabbitmq/amqp091-go`; +you can find it's documentation at: https://pkg.go.dev/github.com/rabbitmq/amqp091-go. ##### Example @@ -202,7 +201,7 @@ package main import ( "github.com/cloudfoundry-community/gautocloud" _ "github.com/cloudfoundry-community/gautocloud/connectors/amqp/client" - "github.com/streadway/amqp" + amqp "github.com/rabbitmq/amqp091-go" ) func main() { var err error diff --git a/go.mod b/go.mod index 10b9aa4..432f205 100644 --- a/go.mod +++ b/go.mod @@ -17,9 +17,9 @@ require ( github.com/minio/minio-go v6.0.14+incompatible github.com/onsi/ginkgo v1.16.5 github.com/onsi/gomega v1.33.1 + github.com/rabbitmq/amqp091-go v1.10.0 github.com/sirupsen/logrus v1.9.3 github.com/spf13/viper v1.18.2 - github.com/streadway/amqp v1.1.0 github.com/urfave/cli v1.22.15 golang.org/x/oauth2 v0.20.0 golang.org/x/text v0.15.0 diff --git a/go.sum b/go.sum index 24887ed..7aa44d7 100644 --- a/go.sum +++ b/go.sum @@ -129,6 +129,8 @@ github.com/pkg/browser v0.0.0-20180916011732-0a3d74bf9ce4/go.mod h1:4OwLy04Bl9Ef github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= github.com/pmezard/go-difflib v1.0.1-0.20181226105442-5d4384ee4fb2 h1:Jamvg5psRIccs7FGNTlIRMkT8wgtp5eCXdBlqhYGL6U= github.com/pmezard/go-difflib v1.0.1-0.20181226105442-5d4384ee4fb2/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= +github.com/rabbitmq/amqp091-go v1.10.0 h1:STpn5XsHlHGcecLmMFCtg7mqq0RnD+zFr4uzukfVhBw= +github.com/rabbitmq/amqp091-go v1.10.0/go.mod h1:Hy4jKW5kQART1u+JkDTF9YYOQUHXqMuhrgxOEeS7G4o= github.com/rogpeppe/go-internal v1.9.0 h1:73kH8U+JUqXU8lRuOHeVHaa/SZPifC7BkcraZVejAe8= github.com/rogpeppe/go-internal v1.9.0/go.mod h1:WtVeX8xhTBvf0smdhujwtBcq4Qrzq/fJaraNFVN+nFs= github.com/russross/blackfriday/v2 v2.1.0 h1:JIOH55/0cWyOuilr9/qlrm0BSXldqnqwMsf35Ld67mk= @@ -151,8 +153,6 @@ github.com/spf13/pflag v1.0.5 h1:iy+VFUOCP1a+8yFto/drg2CJ5u0yRoB7fZw3DKv/JXA= github.com/spf13/pflag v1.0.5/go.mod h1:McXfInJRrz4CZXVZOBLb0bTZqETkiAhM9Iw0y3An2Bg= github.com/spf13/viper v1.18.2 h1:LUXCnvUvSM6FXAsj6nnfc8Q2tp1dIgUfY9Kc8GsSOiQ= github.com/spf13/viper v1.18.2/go.mod h1:EKmWIqdnk5lOcmR72yw6hS+8OPYcwD0jteitLMVB+yk= -github.com/streadway/amqp v1.1.0 h1:py12iX8XSyI7aN/3dUT8DFIDJazNJsVJdxNVEpnQTZM= -github.com/streadway/amqp v1.1.0/go.mod h1:WYSrTEYHOXHd0nwFeUXAe2G2hRnQT+deZJJf88uS9Bg= github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= github.com/stretchr/objx v0.4.0/go.mod h1:YvHI0jy2hoMjB+UWwv71VJQ9isScKT/TqJzVSSt89Yw= github.com/stretchr/objx v0.5.0/go.mod h1:Yh+to48EsGEfYuaHDzXPcE3xhTkx73EhmCGUpEOglKo= @@ -173,6 +173,8 @@ github.com/vaughan0/go-ini v0.0.0-20130923145212-a98ad7ee00ec h1:DGmKwyZwEB8dI7t github.com/vaughan0/go-ini v0.0.0-20130923145212-a98ad7ee00ec/go.mod h1:owBmyHYMLkxyrugmfwE/DLJyW8Ro9mkphwuVErQ0iUw= github.com/yuin/goldmark v1.2.1/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74= github.com/yuin/goldmark v1.3.5/go.mod h1:mwnBkeHKe2W/ZEtQ+71ViKU8L12m81fl3OWwC1Zlc8k= +go.uber.org/goleak v1.3.0 h1:2K3zAYmnTNqV73imy9J1T3WC+gmCePx2hEGkimedGto= +go.uber.org/goleak v1.3.0/go.mod h1:CoHD4mav9JJNrW/WLlf7HGZPjdw8EucARQHekz1X6bE= go.uber.org/multierr v1.11.0 h1:blXXJkSxSSfBVBlC76pxqeO+LN3aDfLQo+309xJstO0= go.uber.org/multierr v1.11.0/go.mod h1:20+QtiLqy0Nd6FdQB9TLXag12DsQkrbs3htMFfDN80Y= golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w= diff --git a/test-integration/test_integration_test.go b/test-integration/test_integration_test.go index 05a4fcc..080cf72 100644 --- a/test-integration/test_integration_test.go +++ b/test-integration/test_integration_test.go @@ -27,8 +27,8 @@ import ( "github.com/jinzhu/gorm" . "github.com/onsi/ginkgo" . "github.com/onsi/gomega" + amqp "github.com/rabbitmq/amqp091-go" log "github.com/sirupsen/logrus" - "github.com/streadway/amqp" "golang.org/x/oauth2" "gopkg.in/mgo.v2" ) From c8c98af534db56bd5c8580ee089fcad1747985f6 Mon Sep 17 00:00:00 2001 From: Romain Dartigues Date: Wed, 15 May 2024 15:33:46 +0200 Subject: [PATCH 19/20] CI: add unit-tests --- .github/workflows/unit-tests.yml | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) create mode 100644 .github/workflows/unit-tests.yml diff --git a/.github/workflows/unit-tests.yml b/.github/workflows/unit-tests.yml new file mode 100644 index 0000000..d48c9a2 --- /dev/null +++ b/.github/workflows/unit-tests.yml @@ -0,0 +1,31 @@ +name: unit-tests + +on: + pull_request: ~ + push: ~ + +jobs: + build: + runs-on: ubuntu-latest + steps: + - name: checkout + uses: actions/checkout@v2 + with: + fetch-depth: 0 + + - name: set up go + uses: actions/setup-go@v2 + with: + go-version: 1.22 + + - name: cache go modules + uses: actions/cache@v1 + with: + path: ~/go/pkg/mod + key: "${{ runner.os }}-go-${{ hashFiles('**/go.sum') }}" + restore-keys: | + ${{ runner.os }}-go- + + - name: tests + run: | + go test -v ./... From 739788e9e4819e145d4b6de4f137ea8187842eb7 Mon Sep 17 00:00:00 2001 From: Romain Dartigues Date: Wed, 15 May 2024 16:54:38 +0200 Subject: [PATCH 20/20] breaking change: a default version is not returned anymore when schema does not have a Version function Related to: https://github.com/alexflint/go-arg/compare/v1.4.3...v1.5.0#diff-5150d3041d43020ac2b39e44af9b692972d5627a5777782e52a0e2094c420af9L278-R271 --- interceptor/cli/arg/arg.go | 7 ++++--- interceptor/cli/arg/arg_test.go | 5 ++--- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/interceptor/cli/arg/arg.go b/interceptor/cli/arg/arg.go index 277fd2e..f15a2c6 100644 --- a/interceptor/cli/arg/arg.go +++ b/interceptor/cli/arg/arg.go @@ -4,6 +4,7 @@ package arg import ( + "errors" "fmt" "github.com/alexflint/go-arg" "github.com/cloudfoundry-community/gautocloud/interceptor" @@ -88,18 +89,18 @@ func (i ArgInterceptor) parse(schema, found interface{}) (interface{}, error) { return nil, err } err = p.Parse(i.flags()) - if err == arg.ErrHelp { + if errors.Is(err, arg.ErrHelp) { p.WriteHelp(i.writer) if !i.exit { return schema, nil } os.Exit(0) } - version := "dev" + version := "n/a" if dest, ok := schema.(arg.Versioned); ok { version = dest.Version() } - if err == arg.ErrVersion { + if errors.Is(err, arg.ErrVersion) { fmt.Fprintln(i.writer, version) if !i.exit { return schema, nil diff --git a/interceptor/cli/arg/arg_test.go b/interceptor/cli/arg/arg_test.go index a783bb7..d1b5877 100644 --- a/interceptor/cli/arg/arg_test.go +++ b/interceptor/cli/arg/arg_test.go @@ -90,7 +90,7 @@ var _ = Describe("Arg", func() { Expect(buf.String()).Should(ContainSubstring("--foo2")) Expect(buf.String()).Should(ContainSubstring("--foo")) }) - It("should return version if flag --version is given", func() { + It("should fail when flag --version is given and schema does not provide a Version", func() { i := NewArg(Writer(buf), Exit(false), Args([]string{ "app", `--version`, @@ -100,8 +100,7 @@ var _ = Describe("Arg", func() { Foo: "orig", Foo2: "bar", }) - Expect(err).ToNot(HaveOccurred()) - Expect(strings.TrimSpace(buf.String())).Should(Equal("dev")) + Expect(err).To(HaveOccurred()) }) It("should return version given by schema if flag --version is given and schema implement Versionned", func() { i := NewArg(Writer(buf), Exit(false), Args([]string{