@@ -20,15 +20,17 @@ import (
|
|||||||
"maps"
|
"maps"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
|
"github.com/getprobo/probo/pkg/probo/coredata/gid"
|
||||||
"github.com/getprobo/probo/pkg/probo/coredata/page"
|
"github.com/getprobo/probo/pkg/probo/coredata/page"
|
||||||
"github.com/jackc/pgx/v5"
|
"github.com/jackc/pgx/v5"
|
||||||
|
|
||||||
"go.gearno.de/crypto/uuid"
|
"go.gearno.de/crypto/uuid"
|
||||||
"go.gearno.de/kit/pg"
|
"go.gearno.de/kit/pg"
|
||||||
)
|
)
|
||||||
|
|
||||||
type (
|
type (
|
||||||
Control struct {
|
Control struct {
|
||||||
ID uuid.UUID
|
ID gid.GID
|
||||||
FrameworkID string
|
FrameworkID string
|
||||||
Name string
|
Name string
|
||||||
Description string
|
Description string
|
||||||
@@ -41,7 +43,7 @@ type (
|
|||||||
)
|
)
|
||||||
|
|
||||||
func (c Control) CursorKey() page.CursorKey {
|
func (c Control) CursorKey() page.CursorKey {
|
||||||
return page.NewCursorKey(c.ID, c.CreatedAt)
|
return page.NewCursorKey(uuid.UUID(c.ID), c.CreatedAt)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *Control) scan(r pgx.Row) error {
|
func (c *Control) scan(r pgx.Row) error {
|
||||||
|
|||||||
23
pkg/probo/coredata/entity_type_reg.go
Normal file
23
pkg/probo/coredata/entity_type_reg.go
Normal file
@@ -0,0 +1,23 @@
|
|||||||
|
// Copyright (c) 2025 Probo Inc <hello@getprobo.com>.
|
||||||
|
//
|
||||||
|
// Permission to use, copy, modify, and/or distribute this software for any
|
||||||
|
// purpose with or without fee is hereby granted, provided that the above
|
||||||
|
// copyright notice and this permission notice appear in all copies.
|
||||||
|
//
|
||||||
|
// THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
|
||||||
|
// REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
|
||||||
|
// AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
|
||||||
|
// INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
|
||||||
|
// LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
|
||||||
|
// OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
|
||||||
|
// PERFORMANCE OF THIS SOFTWARE.
|
||||||
|
|
||||||
|
package coredata
|
||||||
|
|
||||||
|
const (
|
||||||
|
OrganizationEntityType uint32 = iota
|
||||||
|
FrameworkEntityType
|
||||||
|
ControlEntityType
|
||||||
|
TaskEntityType
|
||||||
|
EvidenceEntityType
|
||||||
|
)
|
||||||
@@ -14,11 +14,15 @@
|
|||||||
|
|
||||||
package coredata
|
package coredata
|
||||||
|
|
||||||
import "time"
|
import (
|
||||||
|
"time"
|
||||||
|
|
||||||
|
"github.com/getprobo/probo/pkg/probo/coredata/gid"
|
||||||
|
)
|
||||||
|
|
||||||
type (
|
type (
|
||||||
Evidence struct {
|
Evidence struct {
|
||||||
ID string
|
ID gid.GID
|
||||||
TaskID string
|
TaskID string
|
||||||
ContentID string
|
ContentID string
|
||||||
CreatedAt time.Time
|
CreatedAt time.Time
|
||||||
|
|||||||
@@ -20,15 +20,16 @@ import (
|
|||||||
"maps"
|
"maps"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
|
"github.com/getprobo/probo/pkg/probo/coredata/gid"
|
||||||
"github.com/getprobo/probo/pkg/probo/coredata/page"
|
"github.com/getprobo/probo/pkg/probo/coredata/page"
|
||||||
"github.com/jackc/pgx/v5"
|
"github.com/jackc/pgx/v5"
|
||||||
"go.gearno.de/crypto/uuid"
|
|
||||||
"go.gearno.de/kit/pg"
|
"go.gearno.de/kit/pg"
|
||||||
|
"go.gearno.de/crypto/uuid"
|
||||||
)
|
)
|
||||||
|
|
||||||
type (
|
type (
|
||||||
Framework struct {
|
Framework struct {
|
||||||
ID uuid.UUID
|
ID gid.GID
|
||||||
OrganizationID string
|
OrganizationID string
|
||||||
Name string
|
Name string
|
||||||
Description string
|
Description string
|
||||||
@@ -41,7 +42,7 @@ type (
|
|||||||
)
|
)
|
||||||
|
|
||||||
func (f Framework) CursorKey() page.CursorKey {
|
func (f Framework) CursorKey() page.CursorKey {
|
||||||
return page.NewCursorKey(f.ID, f.CreatedAt)
|
return page.NewCursorKey(uuid.UUID(f.ID), f.CreatedAt)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (f *Framework) scan(r pgx.Row) error {
|
func (f *Framework) scan(r pgx.Row) error {
|
||||||
|
|||||||
91
pkg/probo/coredata/gid/gid.go
Normal file
91
pkg/probo/coredata/gid/gid.go
Normal file
@@ -0,0 +1,91 @@
|
|||||||
|
// Copyright (c) 2025 Probo Inc <hello@getprobo.com>.
|
||||||
|
//
|
||||||
|
// Permission to use, copy, modify, and/or distribute this software for any
|
||||||
|
// purpose with or without fee is hereby granted, provided that the above
|
||||||
|
// copyright notice and this permission notice appear in all copies.
|
||||||
|
//
|
||||||
|
// THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
|
||||||
|
// REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
|
||||||
|
// AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
|
||||||
|
// INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
|
||||||
|
// LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
|
||||||
|
// OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
|
||||||
|
// PERFORMANCE OF THIS SOFTWARE.
|
||||||
|
|
||||||
|
package gid
|
||||||
|
|
||||||
|
import (
|
||||||
|
"database/sql/driver"
|
||||||
|
"encoding/base64"
|
||||||
|
"encoding/binary"
|
||||||
|
"fmt"
|
||||||
|
|
||||||
|
"go.gearno.de/crypto/uuid"
|
||||||
|
)
|
||||||
|
|
||||||
|
type (
|
||||||
|
GID uuid.UUID
|
||||||
|
)
|
||||||
|
|
||||||
|
func NewGID(et uint32) (GID, error) {
|
||||||
|
id, err := uuid.NewV7()
|
||||||
|
if err != nil {
|
||||||
|
return GID(uuid.Nil), err
|
||||||
|
}
|
||||||
|
|
||||||
|
binary.BigEndian.PutUint32(id[10:14], et)
|
||||||
|
|
||||||
|
return GID(id), nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (gid GID) Value() (driver.Value, error) {
|
||||||
|
return gid[:], nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (gid GID) EntityType() uint32 {
|
||||||
|
return binary.BigEndian.Uint32(gid[10:14])
|
||||||
|
}
|
||||||
|
|
||||||
|
func (gid *GID) Scan(value interface{}) error {
|
||||||
|
switch v := value.(type) {
|
||||||
|
case string:
|
||||||
|
id, err := uuid.Parse(v)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
*gid = GID(id)
|
||||||
|
case []byte:
|
||||||
|
id, err := uuid.ParseBytes(v)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
*gid = GID(id)
|
||||||
|
default:
|
||||||
|
return fmt.Errorf("invalid type for GID: expected string or []byte, got %T", value)
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (gid GID) String() string {
|
||||||
|
return base64.RawURLEncoding.EncodeToString(gid[:])
|
||||||
|
}
|
||||||
|
|
||||||
|
func (gid GID) MarshalText() ([]byte, error) {
|
||||||
|
enc := base64.RawURLEncoding
|
||||||
|
|
||||||
|
buf := make([]byte, enc.EncodedLen(len(gid)))
|
||||||
|
enc.Encode(buf, gid[:])
|
||||||
|
|
||||||
|
return buf, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (gid *GID) UnmarshalText(encoded []byte) error {
|
||||||
|
enc := base64.RawURLEncoding
|
||||||
|
|
||||||
|
_, err := enc.Decode(gid[:], encoded)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
return nil
|
||||||
|
}
|
||||||
@@ -20,13 +20,14 @@ import (
|
|||||||
"maps"
|
"maps"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
|
"github.com/getprobo/probo/pkg/probo/coredata/gid"
|
||||||
"github.com/jackc/pgx/v5"
|
"github.com/jackc/pgx/v5"
|
||||||
"go.gearno.de/kit/pg"
|
"go.gearno.de/kit/pg"
|
||||||
)
|
)
|
||||||
|
|
||||||
type (
|
type (
|
||||||
Organization struct {
|
Organization struct {
|
||||||
ID string
|
ID gid.GID
|
||||||
Name string
|
Name string
|
||||||
CreatedAt time.Time
|
CreatedAt time.Time
|
||||||
UpdatedAt time.Time
|
UpdatedAt time.Time
|
||||||
|
|||||||
@@ -20,15 +20,17 @@ import (
|
|||||||
"maps"
|
"maps"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
|
"github.com/getprobo/probo/pkg/probo/coredata/gid"
|
||||||
"github.com/getprobo/probo/pkg/probo/coredata/page"
|
"github.com/getprobo/probo/pkg/probo/coredata/page"
|
||||||
"github.com/jackc/pgx/v5"
|
"github.com/jackc/pgx/v5"
|
||||||
|
|
||||||
"go.gearno.de/crypto/uuid"
|
"go.gearno.de/crypto/uuid"
|
||||||
"go.gearno.de/kit/pg"
|
"go.gearno.de/kit/pg"
|
||||||
)
|
)
|
||||||
|
|
||||||
type (
|
type (
|
||||||
Task struct {
|
Task struct {
|
||||||
ID uuid.UUID
|
ID gid.GID
|
||||||
ControlID string
|
ControlID string
|
||||||
ContentRef string
|
ContentRef string
|
||||||
CreatedAt time.Time
|
CreatedAt time.Time
|
||||||
@@ -39,7 +41,7 @@ type (
|
|||||||
)
|
)
|
||||||
|
|
||||||
func (t Task) CursorKey() page.CursorKey {
|
func (t Task) CursorKey() page.CursorKey {
|
||||||
return page.NewCursorKey(t.ID, t.CreatedAt)
|
return page.NewCursorKey(uuid.UUID(t.ID), t.CreatedAt)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (t *Task) scan(r pgx.Row) error {
|
func (t *Task) scan(r pgx.Row) error {
|
||||||
|
|||||||
Reference in New Issue
Block a user