diff --git a/cmd/serve.go b/cmd/serve.go index 647ee1c5..21d9f30e 100644 --- a/cmd/serve.go +++ b/cmd/serve.go @@ -10,13 +10,14 @@ import ( dbx "github.com/theopenlane/dbx/pkg/dbxclient" "github.com/theopenlane/iam/fgax" + "github.com/theopenlane/utils/cache" + ent "github.com/theopenlane/core/internal/ent/generated" "github.com/theopenlane/core/internal/entdb" "github.com/theopenlane/core/internal/httpserve/authmanager" "github.com/theopenlane/core/internal/httpserve/config" "github.com/theopenlane/core/internal/httpserve/server" "github.com/theopenlane/core/internal/httpserve/serveropts" - "github.com/theopenlane/core/pkg/cache" ) var serveCmd = &cobra.Command{ diff --git a/config/config.go b/config/config.go index 0f05c28e..51527cc2 100644 --- a/config/config.go +++ b/config/config.go @@ -21,10 +21,11 @@ import ( "github.com/theopenlane/iam/sessions" "github.com/theopenlane/iam/tokens" + "github.com/theopenlane/utils/cache" + "github.com/theopenlane/core/internal/ent/entconfig" "github.com/theopenlane/core/internal/httpserve/handlers" "github.com/theopenlane/core/pkg/analytics/posthog" - "github.com/theopenlane/core/pkg/cache" "github.com/theopenlane/core/pkg/events/kafka/kafkaconfig" "github.com/theopenlane/core/pkg/middleware/cachecontrol" "github.com/theopenlane/core/pkg/middleware/cors" diff --git a/go.mod b/go.mod index cfe1992e..aa2024a2 100644 --- a/go.mod +++ b/go.mod @@ -61,7 +61,7 @@ require ( github.com/theopenlane/gqlgen-plugins v0.1.0 github.com/theopenlane/httpsling v0.1.0 github.com/theopenlane/iam v0.1.6 - github.com/theopenlane/utils v0.1.4 + github.com/theopenlane/utils v0.1.5 github.com/tursodatabase/libsql-client-go v0.0.0-20240812094001-348a4e45b535 github.com/vektah/gqlparser/v2 v2.5.16 github.com/wundergraph/graphql-go-tools v1.67.4 diff --git a/go.sum b/go.sum index 4686a4b3..f36b8932 100644 --- a/go.sum +++ b/go.sum @@ -550,8 +550,8 @@ github.com/theopenlane/httpsling v0.1.0 h1:IHWUSo213stJTmHOHjNIg5b3npgpchzMdPMY7 github.com/theopenlane/httpsling v0.1.0/go.mod h1:wOyNfO4moIbmP4stQc9Kasgp+Q4sODo3LOLwvjUe/PA= github.com/theopenlane/iam v0.1.6 h1:ps6xLXHpnGy687uLPRZiD7034DRVqaWEfJLCJVMx95o= github.com/theopenlane/iam v0.1.6/go.mod h1:mOtYjuqUD7SX4EkwXFAYwf8+mwPDsRvTsLhAngqVIxM= -github.com/theopenlane/utils v0.1.4 h1:G2hrRBOugS2VvdqumBMrp2uSjulwbJMt8QO0EpwKm7g= -github.com/theopenlane/utils v0.1.4/go.mod h1:aFHkhJKNMGcaqNSfWV+hClZeejjuz4+oerrM7orq0Jw= +github.com/theopenlane/utils v0.1.5 h1:4DRieQmsBF87n4lPjEkTt6s4iVRQaCGYlk2+C05lt3o= +github.com/theopenlane/utils v0.1.5/go.mod h1:LWJzG9FfklsLlqWx/VdmfBMuNk700cWqHAwQL0299FM= github.com/tursodatabase/libsql-client-go v0.0.0-20240812094001-348a4e45b535 h1:iLjJLq2A5J6L9zrhyNn+fpmxFvtEpYB4XLMr0rX3epI= github.com/tursodatabase/libsql-client-go v0.0.0-20240812094001-348a4e45b535/go.mod h1:l8xTsYB90uaVdMHXMCxKKLSgw5wLYBwBKKefNIUnm9s= github.com/twitchyliquid64/golang-asm v0.15.1 h1:SU5vSMR7hnwNxj24w34ZyCi/FmDZTkS4MhqMhdFk5YI= diff --git a/internal/ent/hooks/user.go b/internal/ent/hooks/user.go index 200af93b..feebb329 100644 --- a/internal/ent/hooks/user.go +++ b/internal/ent/hooks/user.go @@ -13,12 +13,13 @@ import ( "github.com/theopenlane/iam/auth" + "github.com/theopenlane/utils/passwd" + "github.com/theopenlane/core/internal/ent/generated" "github.com/theopenlane/core/internal/ent/generated/hook" "github.com/theopenlane/core/internal/ent/generated/organization" "github.com/theopenlane/core/internal/ent/generated/privacy" "github.com/theopenlane/core/pkg/enums" - "github.com/theopenlane/utils/passwd" ) const ( diff --git a/internal/httpserve/handlers/login.go b/internal/httpserve/handlers/login.go index 85bf03bf..f7ce0bf4 100644 --- a/internal/httpserve/handlers/login.go +++ b/internal/httpserve/handlers/login.go @@ -11,9 +11,10 @@ import ( "github.com/theopenlane/iam/auth" + "github.com/theopenlane/utils/passwd" + "github.com/theopenlane/core/pkg/enums" "github.com/theopenlane/core/pkg/models" - "github.com/theopenlane/utils/passwd" ) // LoginHandler validates the user credentials and returns a valid cookie diff --git a/internal/httpserve/handlers/resetpassword.go b/internal/httpserve/handlers/resetpassword.go index 51c9a09a..ba34f59b 100644 --- a/internal/httpserve/handlers/resetpassword.go +++ b/internal/httpserve/handlers/resetpassword.go @@ -19,10 +19,11 @@ import ( "github.com/theopenlane/iam/auth" "github.com/theopenlane/iam/tokens" + "github.com/theopenlane/utils/passwd" + "github.com/theopenlane/core/internal/ent/generated" "github.com/theopenlane/core/internal/ent/privacy/token" "github.com/theopenlane/core/pkg/models" - "github.com/theopenlane/utils/passwd" ) // ResetPassword allows the user (after requesting a password reset) to diff --git a/internal/httpserve/serveropts/option.go b/internal/httpserve/serveropts/option.go index ef5d30b0..c6fe4785 100644 --- a/internal/httpserve/serveropts/option.go +++ b/internal/httpserve/serveropts/option.go @@ -27,12 +27,13 @@ import ( "github.com/theopenlane/iam/sessions" "github.com/theopenlane/iam/tokens" + "github.com/theopenlane/utils/cache" + "github.com/theopenlane/core/internal/ent/generated" "github.com/theopenlane/core/internal/graphapi" "github.com/theopenlane/core/internal/httpserve/config" "github.com/theopenlane/core/internal/httpserve/server" "github.com/theopenlane/core/pkg/analytics" - "github.com/theopenlane/core/pkg/cache" "github.com/theopenlane/core/pkg/events/kafka/publisher" authmw "github.com/theopenlane/core/pkg/middleware/auth" "github.com/theopenlane/core/pkg/middleware/cachecontrol" diff --git a/jsonschema/api-docs.md b/jsonschema/api-docs.md index be464c75..e4c5d07d 100644 --- a/jsonschema/api-docs.md +++ b/jsonschema/api-docs.md @@ -14,7 +14,7 @@ Config contains the configuration for the core server |[**authz**](#authz)|`object`||yes| |[**db**](#db)|`object`||yes| |[**dbx**](#dbx)|`object`||| -|[**redis**](#redis)|`object`|Config for the redis client used to store key-value pairs
|| +|[**redis**](#redis)|`object`||| |[**tracer**](#tracer)|`object`||| |[**email**](#email)|`object`||| |[**sessions**](#sessions)|`object`||| @@ -429,26 +429,23 @@ OauthProviderConfig represents the configuration for OAuth providers such as Git ## redis: object -Config for the redis client used to store key-value pairs - - **Properties** |Name|Type|Description|Required| |----|----|-----------|--------| -|**enabled**|`boolean`|Enabled to enable redis client in the server
|| -|**address**|`string`|Address is the host:port to connect to redis
|| -|**name**|`string`|Name of the connecting client
|| -|**username**|`string`|Username to connect to redis
|| -|**password**|`string`|Password, must match the password specified in the server configuration
|| -|**db**|`integer`|DB to be selected after connecting to the server, 0 uses the default
|| -|**dialTimeout**|`integer`|Dial timeout for establishing new connections, defaults to 5s
|| -|**readTimeout**|`integer`|Timeout for socket reads. If reached, commands will fail
with a timeout instead of blocking. Supported values:
- `0` - default timeout (3 seconds).
- `-1` - no timeout (block indefinitely).
- `-2` - disables SetReadDeadline calls completely.
|| -|**writeTimeout**|`integer`|Timeout for socket writes. If reached, commands will fail
with a timeout instead of blocking. Supported values:
- `0` - default timeout (3 seconds).
- `-1` - no timeout (block indefinitely).
- `-2` - disables SetWriteDeadline calls completely.
|| -|**maxRetries**|`integer`|MaxRetries before giving up.
Default is 3 retries; -1 (not 0) disables retries.
|| -|**minIdleConns**|`integer`|MinIdleConns is useful when establishing new connection is slow.
Default is 0. the idle connections are not closed by default.
|| -|**maxIdleConns**|`integer`|Maximum number of idle connections.
Default is 0. the idle connections are not closed by default.
|| -|**maxActiveConns**|`integer`|Maximum number of connections allocated by the pool at a given time.
When zero, there is no limit on the number of connections in the pool.
|| +|**enabled**|`boolean`||| +|**address**|`string`||| +|**name**|`string`||| +|**username**|`string`||| +|**password**|`string`||| +|**db**|`integer`||| +|**dialTimeout**|`integer`||| +|**readTimeout**|`integer`||| +|**writeTimeout**|`integer`||| +|**maxRetries**|`integer`||| +|**minIdleConns**|`integer`||| +|**maxIdleConns**|`integer`||| +|**maxActiveConns**|`integer`||| **Additional Properties:** not allowed diff --git a/jsonschema/core.config.json b/jsonschema/core.config.json index eca6f8fb..6d235e36 100644 --- a/jsonschema/core.config.json +++ b/jsonschema/core.config.json @@ -11,61 +11,47 @@ "cache.Config": { "properties": { "enabled": { - "type": "boolean", - "description": "Enabled to enable redis client in the server" + "type": "boolean" }, "address": { - "type": "string", - "description": "Address is the host:port to connect to redis" + "type": "string" }, "name": { - "type": "string", - "description": "Name of the connecting client" + "type": "string" }, "username": { - "type": "string", - "description": "Username to connect to redis" + "type": "string" }, "password": { - "type": "string", - "description": "Password, must match the password specified in the server configuration" + "type": "string" }, "db": { - "type": "integer", - "description": "DB to be selected after connecting to the server, 0 uses the default" + "type": "integer" }, "dialTimeout": { - "type": "integer", - "description": "Dial timeout for establishing new connections, defaults to 5s" + "type": "integer" }, "readTimeout": { - "type": "integer", - "description": "Timeout for socket reads. If reached, commands will fail\nwith a timeout instead of blocking. Supported values:\n - `0` - default timeout (3 seconds).\n - `-1` - no timeout (block indefinitely).\n - `-2` - disables SetReadDeadline calls completely." + "type": "integer" }, "writeTimeout": { - "type": "integer", - "description": "Timeout for socket writes. If reached, commands will fail\nwith a timeout instead of blocking. Supported values:\n - `0` - default timeout (3 seconds).\n - `-1` - no timeout (block indefinitely).\n - `-2` - disables SetWriteDeadline calls completely." + "type": "integer" }, "maxRetries": { - "type": "integer", - "description": "MaxRetries before giving up.\nDefault is 3 retries; -1 (not 0) disables retries." + "type": "integer" }, "minIdleConns": { - "type": "integer", - "description": "MinIdleConns is useful when establishing new connection is slow.\nDefault is 0. the idle connections are not closed by default." + "type": "integer" }, "maxIdleConns": { - "type": "integer", - "description": "Maximum number of idle connections.\nDefault is 0. the idle connections are not closed by default." + "type": "integer" }, "maxActiveConns": { - "type": "integer", - "description": "Maximum number of connections allocated by the pool at a given time.\nWhen zero, there is no limit on the number of connections in the pool." + "type": "integer" } }, "additionalProperties": false, - "type": "object", - "description": "Config for the redis client used to store key-value pairs" + "type": "object" }, "cachecontrol.Config": { "properties": { diff --git a/jsonschema/schema_generator.go b/jsonschema/schema_generator.go index dd9285c2..ed8638b4 100644 --- a/jsonschema/schema_generator.go +++ b/jsonschema/schema_generator.go @@ -33,7 +33,6 @@ const ( // any external packages must use the jsonschema description tags to add comments var includedPackages = []string{ "./config", - "./pkg/cache", "./internal/ent", "./internal/entdb", "./internal/httpserve/handlers", diff --git a/pkg/cache/client.go b/pkg/cache/client.go deleted file mode 100644 index a9775f35..00000000 --- a/pkg/cache/client.go +++ /dev/null @@ -1,89 +0,0 @@ -package cache - -import ( - "context" - "time" - - "github.com/redis/go-redis/v9" -) - -// Config for the redis client used to store key-value pairs -type Config struct { - // Enabled to enable redis client in the server - Enabled bool `json:"enabled" koanf:"enabled" default:"true"` - // Address is the host:port to connect to redis - Address string `json:"address" koanf:"address" default:"localhost:6379"` - // Name of the connecting client - Name string `json:"name" koanf:"name" default:"openlane"` - // Username to connect to redis - Username string `json:"username" koanf:"username"` - // Password, must match the password specified in the server configuration - Password string `json:"password" koanf:"password"` - // DB to be selected after connecting to the server, 0 uses the default - DB int `json:"db" koanf:"db" default:"0"` - // Dial timeout for establishing new connections, defaults to 5s - DialTimeout time.Duration `json:"dialTimeout" koanf:"dialTimeout" default:"5s"` - // Timeout for socket reads. If reached, commands will fail - // with a timeout instead of blocking. Supported values: - // - `0` - default timeout (3 seconds). - // - `-1` - no timeout (block indefinitely). - // - `-2` - disables SetReadDeadline calls completely. - ReadTimeout time.Duration `json:"readTimeout" koanf:"readTimeout" default:"0"` - // Timeout for socket writes. If reached, commands will fail - // with a timeout instead of blocking. Supported values: - // - `0` - default timeout (3 seconds). - // - `-1` - no timeout (block indefinitely). - // - `-2` - disables SetWriteDeadline calls completely. - WriteTimeout time.Duration `json:"writeTimeout" koanf:"writeTimeout" default:"0"` - // MaxRetries before giving up. - // Default is 3 retries; -1 (not 0) disables retries. - MaxRetries int `json:"maxRetries" koanf:"maxRetries" default:"3"` - // MinIdleConns is useful when establishing new connection is slow. - // Default is 0. the idle connections are not closed by default. - MinIdleConns int `json:"minIdleConns" koanf:"minIdleConns" default:"0"` - // Maximum number of idle connections. - // Default is 0. the idle connections are not closed by default. - MaxIdleConns int `json:"maxIdleConns" koanf:"maxIdleConns" default:"0"` - // Maximum number of connections allocated by the pool at a given time. - // When zero, there is no limit on the number of connections in the pool. - MaxActiveConns int `json:"maxActiveConns" koanf:"maxActiveConns" default:"0"` -} - -// New returns a new redis client based on the configuration settings -func New(c Config) *redis.Client { - opts := &redis.Options{ - Addr: c.Address, - ClientName: c.Name, - DB: c.DB, - DialTimeout: c.DialTimeout, - ReadTimeout: c.ReadTimeout, - WriteTimeout: c.WriteTimeout, - MaxRetries: c.MaxRetries, - MinIdleConns: c.MinIdleConns, - MaxIdleConns: c.MaxIdleConns, - MaxActiveConns: c.MaxActiveConns, - DisableIndentity: true, // # spellcheck: off - } - - if c.Username != "" { - opts.Username = c.Username - } - - if c.Password != "" { - opts.Password = c.Password - } - - return redis.NewClient(opts) -} - -// Healthcheck pings the client to check if the connection is working -func Healthcheck(c *redis.Client) func(ctx context.Context) error { - return func(ctx context.Context) error { - // check if its alive - if err := c.Ping(ctx).Err(); err != nil { - return err - } - - return nil - } -} diff --git a/pkg/cache/doc.go b/pkg/cache/doc.go deleted file mode 100644 index 5b4b989f..00000000 --- a/pkg/cache/doc.go +++ /dev/null @@ -1,2 +0,0 @@ -// Package cache holds the library for interacting with redis -package cache