Skip to content

Infisical is the open-source platform for securing secrets, certificates, access, and AI Agents.

feat: updated server package

=45587d58e2a4
diff --git a/backend-go/pkg/api/README.md b/backend-go/pkg/chita/README.md
similarity index 100%
rename from backend-go/pkg/api/README.md
rename to backend-go/pkg/chita/README.md
diff --git a/backend-go/pkg/api/auth.go b/backend-go/pkg/chita/auth.go
similarity index 99%
rename from backend-go/pkg/api/auth.go
rename to backend-go/pkg/chita/auth.go
index 99768c5a83..6d8ca96bff 100644
--- a/backend-go/pkg/api/auth.go
+++ b/backend-go/pkg/chita/auth.go
@@ -1,4 +1,4 @@
-package api
+package chita
import (
"context"
diff --git a/backend-go/pkg/api/auth_test.go b/backend-go/pkg/chita/auth_test.go
similarity index 99%
rename from backend-go/pkg/api/auth_test.go
rename to backend-go/pkg/chita/auth_test.go
index ce97ed0445..86e8c3643d 100644
--- a/backend-go/pkg/api/auth_test.go
+++ b/backend-go/pkg/chita/auth_test.go
@@ -1,4 +1,4 @@
-package api
+package chita
import (
"context"
diff --git a/backend-go/pkg/api/endpoint.go b/backend-go/pkg/chita/endpoint.go
similarity index 99%
rename from backend-go/pkg/api/endpoint.go
rename to backend-go/pkg/chita/endpoint.go
index 0a6d65c60b..c868d89e24 100644
--- a/backend-go/pkg/api/endpoint.go
+++ b/backend-go/pkg/chita/endpoint.go
@@ -1,4 +1,4 @@
-package api
+package chita
import (
"net/http"
diff --git a/backend-go/pkg/api/errors.go b/backend-go/pkg/chita/errors.go
similarity index 99%
rename from backend-go/pkg/api/errors.go
rename to backend-go/pkg/chita/errors.go
index c0b672ff52..eb929e6280 100644
--- a/backend-go/pkg/api/errors.go
+++ b/backend-go/pkg/chita/errors.go
@@ -1,4 +1,4 @@
-package api
+package chita
import (
"errors"
diff --git a/backend-go/pkg/api/handler.go b/backend-go/pkg/chita/handler.go
similarity index 99%
rename from backend-go/pkg/api/handler.go
rename to backend-go/pkg/chita/handler.go
index 983f4d56fa..c0799491b0 100644
--- a/backend-go/pkg/api/handler.go
+++ b/backend-go/pkg/chita/handler.go
@@ -1,4 +1,4 @@
-package api
+package chita
import (
"context"
diff --git a/backend-go/pkg/api/http_test.go b/backend-go/pkg/chita/http_test.go
similarity index 99%
rename from backend-go/pkg/api/http_test.go
rename to backend-go/pkg/chita/http_test.go
index 1e0c8c8348..b3a52c0101 100644
--- a/backend-go/pkg/api/http_test.go
+++ b/backend-go/pkg/chita/http_test.go
@@ -1,4 +1,4 @@
-package api
+package chita
import (
"bytes"
diff --git a/backend-go/pkg/api/integration_test.go b/backend-go/pkg/chita/integration_test.go
similarity index 99%
rename from backend-go/pkg/api/integration_test.go
rename to backend-go/pkg/chita/integration_test.go
index e7d4a10e2e..2f4bbd86fb 100644
--- a/backend-go/pkg/api/integration_test.go
+++ b/backend-go/pkg/chita/integration_test.go
@@ -1,4 +1,4 @@
-package api
+package chita
import (
"encoding/json"
diff --git a/backend-go/pkg/api/ispresent_test.go b/backend-go/pkg/chita/ispresent_test.go
similarity index 99%
rename from backend-go/pkg/api/ispresent_test.go
rename to backend-go/pkg/chita/ispresent_test.go
index 68cd819476..2f7e136b3a 100644
--- a/backend-go/pkg/api/ispresent_test.go
+++ b/backend-go/pkg/chita/ispresent_test.go
@@ -1,4 +1,4 @@
-package api
+package chita
import (
"encoding/json"
diff --git a/backend-go/pkg/api/nullable.go b/backend-go/pkg/chita/nullable.go
similarity index 99%
rename from backend-go/pkg/api/nullable.go
rename to backend-go/pkg/chita/nullable.go
index b3c16dde3c..18d5f27f56 100644
--- a/backend-go/pkg/api/nullable.go
+++ b/backend-go/pkg/chita/nullable.go
@@ -1,4 +1,4 @@
-package api
+package chita
import (
"bytes"
diff --git a/backend-go/pkg/api/nullable_test.go b/backend-go/pkg/chita/nullable_test.go
similarity index 99%
rename from backend-go/pkg/api/nullable_test.go
rename to backend-go/pkg/chita/nullable_test.go
index 6464133f1f..17b1e96d94 100644
--- a/backend-go/pkg/api/nullable_test.go
+++ b/backend-go/pkg/chita/nullable_test.go
@@ -1,4 +1,4 @@
-package api
+package chita
import (
"encoding/json"
diff --git a/backend-go/pkg/api/oneof_anyof_test.go b/backend-go/pkg/chita/oneof_anyof_test.go
similarity index 99%
rename from backend-go/pkg/api/oneof_anyof_test.go
rename to backend-go/pkg/chita/oneof_anyof_test.go
index 113afc385b..e8542654b8 100644
--- a/backend-go/pkg/api/oneof_anyof_test.go
+++ b/backend-go/pkg/chita/oneof_anyof_test.go
@@ -1,4 +1,4 @@
-package api
+package chita
import (
"testing"
diff --git a/backend-go/pkg/api/openapi.go b/backend-go/pkg/chita/openapi.go
similarity index 99%
rename from backend-go/pkg/api/openapi.go
rename to backend-go/pkg/chita/openapi.go
index 1c62789040..4972d2917c 100644
--- a/backend-go/pkg/api/openapi.go
+++ b/backend-go/pkg/chita/openapi.go
@@ -1,4 +1,4 @@
-package api
+package chita
import (
"encoding/json"
diff --git a/backend-go/pkg/api/openapi_test.go b/backend-go/pkg/chita/openapi_test.go
similarity index 99%
rename from backend-go/pkg/api/openapi_test.go
rename to backend-go/pkg/chita/openapi_test.go
index 8e606b272d..2ef0738d1b 100644
--- a/backend-go/pkg/api/openapi_test.go
+++ b/backend-go/pkg/chita/openapi_test.go
@@ -1,4 +1,4 @@
-package api
+package chita
import (
"encoding/json"
diff --git a/backend-go/pkg/api/registry.go b/backend-go/pkg/chita/registry.go
similarity index 99%
rename from backend-go/pkg/api/registry.go
rename to backend-go/pkg/chita/registry.go
index 804cb44c4f..6c558b28b0 100644
--- a/backend-go/pkg/api/registry.go
+++ b/backend-go/pkg/chita/registry.go
@@ -1,4 +1,4 @@
-package api
+package chita
import (
"maps"
diff --git a/backend-go/pkg/api/request.go b/backend-go/pkg/chita/request.go
similarity index 99%
rename from backend-go/pkg/api/request.go
rename to backend-go/pkg/chita/request.go
index c92d6fa64d..3e70fdf1b2 100644
--- a/backend-go/pkg/api/request.go
+++ b/backend-go/pkg/chita/request.go
@@ -1,4 +1,4 @@
-package api
+package chita
import (
"encoding/json"
diff --git a/backend-go/pkg/api/request_test.go b/backend-go/pkg/chita/request_test.go
similarity index 99%
rename from backend-go/pkg/api/request_test.go
rename to backend-go/pkg/chita/request_test.go
index 790587387b..9a5f16ac30 100644
--- a/backend-go/pkg/api/request_test.go
+++ b/backend-go/pkg/chita/request_test.go
@@ -1,4 +1,4 @@
-package api
+package chita
import (
"bytes"
diff --git a/backend-go/pkg/api/router.go b/backend-go/pkg/chita/router.go
similarity index 99%
rename from backend-go/pkg/api/router.go
rename to backend-go/pkg/chita/router.go
index b6549364b1..7b2c85adbe 100644
--- a/backend-go/pkg/api/router.go
+++ b/backend-go/pkg/chita/router.go
@@ -1,4 +1,4 @@
-package api
+package chita
import (
"encoding/json"
diff --git a/backend-go/pkg/api/router_test.go b/backend-go/pkg/chita/router_test.go
similarity index 99%
rename from backend-go/pkg/api/router_test.go
rename to backend-go/pkg/chita/router_test.go
index 65771983a4..9a0ce9e00b 100644
--- a/backend-go/pkg/api/router_test.go
+++ b/backend-go/pkg/chita/router_test.go
@@ -1,4 +1,4 @@
-package api
+package chita
import (
"context"
diff --git a/backend-go/pkg/api/schema.go b/backend-go/pkg/chita/schema.go
similarity index 99%
rename from backend-go/pkg/api/schema.go
rename to backend-go/pkg/chita/schema.go
index 651f97c92c..69c22a9c73 100644
--- a/backend-go/pkg/api/schema.go
+++ b/backend-go/pkg/chita/schema.go
@@ -1,4 +1,4 @@
-package api
+package chita
import (
"encoding/json"
diff --git a/backend-go/pkg/api/schema_composite.go b/backend-go/pkg/chita/schema_composite.go
similarity index 99%
rename from backend-go/pkg/api/schema_composite.go
rename to backend-go/pkg/chita/schema_composite.go
index 63b4ada267..f05a84e649 100644
--- a/backend-go/pkg/api/schema_composite.go
+++ b/backend-go/pkg/chita/schema_composite.go
@@ -1,4 +1,4 @@
-package api
+package chita
import (
"encoding/json"
diff --git a/backend-go/pkg/api/schema_composite_test.go b/backend-go/pkg/chita/schema_composite_test.go
similarity index 99%
rename from backend-go/pkg/api/schema_composite_test.go
rename to backend-go/pkg/chita/schema_composite_test.go
index 8ef123b558..a4e34f77e0 100644
--- a/backend-go/pkg/api/schema_composite_test.go
+++ b/backend-go/pkg/chita/schema_composite_test.go
@@ -1,4 +1,4 @@
-package api
+package chita
import (
"testing"
diff --git a/backend-go/pkg/chita/schema_request.go b/backend-go/pkg/chita/schema_request.go
new file mode 100644
index 0000000000..624b48766f
--- /dev/null
+++ b/backend-go/pkg/chita/schema_request.go
@@ -0,0 +1,178 @@
+package chita
+
+import (
+ "fmt"
+ "net/url"
+ "strings"
+)
+
+// ValueGetter is implemented by schema types that can return their bound value.
+type ValueGetter interface {
+ GetValue() any
+ IsZero() bool
+}
+
+// GetValue returns the bound string value.
+func (s *StringSchema) GetValue() any {
+ if s.ptr == nil {
+ return nil
+ }
+ return *s.ptr
+}
+
+// IsZero returns true if the value is zero/empty.
+func (s *StringSchema) IsZero() bool {
+ return s.ptr == nil || *s.ptr == ""
+}
+
+// GetValue returns the bound int value.
+func (s *IntSchema) GetValue() any {
+ if s.ptr != nil {
+ return *s.ptr
+ }
+ if s.ptr64 != nil {
+ return *s.ptr64
+ }
+ return nil
+}
+
+// IsZero returns true if the value is zero/empty.
+func (s *IntSchema) IsZero() bool {
+ if s.ptr != nil {
+ return *s.ptr == 0
+ }
+ if s.ptr64 != nil {
+ return *s.ptr64 == 0
+ }
+ return true
+}
+
+// GetValue returns the bound float value.
+func (s *FloatSchema) GetValue() any {
+ if s.ptr == nil {
+ return nil
+ }
+ return *s.ptr
+}
+
+// IsZero returns true if the value is zero/empty.
+func (s *FloatSchema) IsZero() bool {
+ return s.ptr == nil || *s.ptr == 0
+}
+
+// GetValue returns the bound bool value.
+func (s *BoolSchema) GetValue() any {
+ if s.ptr == nil {
+ return nil
+ }
+ return *s.ptr
+}
+
+// IsZero returns true if the value is zero/empty.
+func (s *BoolSchema) IsZero() bool {
+ return s.ptr == nil
+}
+
+// GetValue returns the bound UUID value.
+func (s *UUIDSchema) GetValue() any {
+ if s.ptr == nil {
+ return nil
+ }
+ return s.ptr.String()
+}
+
+// IsZero returns true if the value is zero/empty.
+func (s *UUIDSchema) IsZero() bool {
+ return s.ptr == nil || *s.ptr == [16]byte{}
+}
+
+// GetValue returns the bound time value.
+func (s *TimeSchema) GetValue() any {
+ if s.ptr == nil {
+ return nil
+ }
+ return s.ptr.Format("2006-01-02T15:04:05Z07:00")
+}
+
+// IsZero returns true if the value is zero/empty.
+func (s *TimeSchema) IsZero() bool {
+ return s.ptr == nil || s.ptr.IsZero()
+}
+
+// GetValue returns the bound bytes value.
+func (s *BytesSchema) GetValue() any {
+ if s.ptr == nil {
+ return nil
+ }
+ return *s.ptr
+}
+
+// IsZero returns true if the value is zero/empty.
+func (s *BytesSchema) IsZero() bool {
+ return s.ptr == nil || len(*s.ptr) == 0
+}
+
+// GetValue returns the bound any value.
+func (s *AnySchema) GetValue() any {
+ if s.ptr == nil {
+ return nil
+ }
+ return *s.ptr
+}
+
+// IsZero returns true if the value is zero/empty.
+func (s *AnySchema) IsZero() bool {
+ return s.ptr == nil || *s.ptr == nil
+}
+
+// GetValue returns the bound raw JSON value.
+func (s *RawSchema) GetValue() any {
+ if s.ptr == nil {
+ return nil
+ }
+ return *s.ptr
+}
+
+// IsZero returns true if the value is zero/empty.
+func (s *RawSchema) IsZero() bool {
+ return s.ptr == nil || len(*s.ptr) == 0
+}
+
+// BuildRequest builds the URL path and body from the schema's bound values.
+// It uses the Source of each field to determine if it goes in path, query, or body.
+// Returns the path (with query string) and a map of body fields.
+func (s *ObjectSchema) BuildRequest(basePath string) (path string, body map[string]any) {
+ path = basePath
+ query := url.Values{}
+ body = make(map[string]any)
+
+ for name, field := range s.properties {
+ source := field.GetSource()
+
+ valueGetter, ok := field.(ValueGetter)
+ if !ok {
+ continue
+ }
+
+ if valueGetter.IsZero() {
+ continue
+ }
+
+ value := valueGetter.GetValue()
+
+ switch source {
+ case SourcePath:
+ path = strings.Replace(path, "{"+name+"}", fmt.Sprint(value), 1)
+ case SourceQuery:
+ query.Set(name, fmt.Sprint(value))
+ default:
+ body[name] = value
+ }
+ }
+
+ if len(query) > 0 {
+ path += "?" + query.Encode()
+ }
+
+ return
+}
diff --git a/backend-go/pkg/api/schema_test.go b/backend-go/pkg/chita/schema_test.go
similarity index 99%
rename from backend-go/pkg/api/schema_test.go
rename to backend-go/pkg/chita/schema_test.go
index 42f5495ab9..da05fa3649 100644
--- a/backend-go/pkg/api/schema_test.go
+++ b/backend-go/pkg/chita/schema_test.go
@@ -1,4 +1,4 @@
-package api
+package chita
import (
"encoding/json"
diff --git a/backend-go/pkg/chita/testing.go b/backend-go/pkg/chita/testing.go
new file mode 100644
index 0000000000..b4149a18fa
--- /dev/null
+++ b/backend-go/pkg/chita/testing.go
@@ -0,0 +1,44 @@
+package chita
+
+import (
+ "bytes"
+ "context"
+ "encoding/json"
+ "io"
+ "net/http"
+ "net/http/httptest"
+ "testing"
+
+ "github.com/stretchr/testify/require"
+)
+
+// HTTPTest makes an HTTP request using the schema's BuildRequest to construct the URL and body.
+// It returns the decoded response and status code.
+func HTTPTest[Req SchemaProvider, Resp any](t *testing.T, srv *httptest.Server, method, basePath string, req Req) (result Resp, statusCode int) {
+ t.Helper()
+
+ path, bodyFields := req.Schema().BuildRequest(basePath)
+
+ var reqBody io.Reader = http.NoBody
+ if len(bodyFields) > 0 {
+ b, err := json.Marshal(bodyFields)
+ require.NoError(t, err)
+ reqBody = bytes.NewReader(b)
+ }
+
+ httpReq, err := http.NewRequestWithContext(context.Background(), method, srv.URL+path, reqBody)
+ require.NoError(t, err)
+
+ if len(bodyFields) > 0 {
+ httpReq.Header.Set("Content-Type", "application/json")
+ }
+
+ resp, err := http.DefaultClient.Do(httpReq)
+ require.NoError(t, err)
+ defer func() { _ = resp.Body.Close() }()
+
+ _ = json.NewDecoder(resp.Body).Decode(&result)
+ statusCode = resp.StatusCode
+
+ return
+}
diff --git a/backend-go/pkg/api/union.go b/backend-go/pkg/chita/union.go
similarity index 99%
rename from backend-go/pkg/api/union.go
rename to backend-go/pkg/chita/union.go
index 359c0da788..5b6a73129b 100644
--- a/backend-go/pkg/api/union.go
+++ b/backend-go/pkg/chita/union.go
@@ -1,4 +1,4 @@
-package api
+package chita
import (
"encoding/json"
diff --git a/backend-go/pkg/api/union_helpers_test.go b/backend-go/pkg/chita/union_helpers_test.go
similarity index 99%
rename from backend-go/pkg/api/union_helpers_test.go
rename to backend-go/pkg/chita/union_helpers_test.go
index e6df20e501..b226f07931 100644
--- a/backend-go/pkg/api/union_helpers_test.go
+++ b/backend-go/pkg/chita/union_helpers_test.go
@@ -1,4 +1,4 @@
-package api
+package chita
import (
"encoding/json"
diff --git a/backend-go/pkg/api/union_test.go b/backend-go/pkg/chita/union_test.go
similarity index 99%
rename from backend-go/pkg/api/union_test.go
rename to backend-go/pkg/chita/union_test.go
index 3a27fd07ff..9d24ee7be3 100644
--- a/backend-go/pkg/api/union_test.go
+++ b/backend-go/pkg/chita/union_test.go
@@ -1,4 +1,4 @@
-package api
+package chita
import (
"encoding/json"