Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
46 changes: 46 additions & 0 deletions invopop/silo_meta.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,9 @@ import (
"context"
"encoding/json"
"errors"
"net/url"
"path"
"strconv"
)

const (
Expand All @@ -15,6 +17,23 @@ const (
// the special "enrolled" scope in tokens.
type SiloMetaService service

// SiloMetaCollection contains a list of Meta entries with pagination.
type SiloMetaCollection struct {
List []*SiloMeta `json:"list"`
Limit int32 `json:"limit"`
Cursor string `json:"cursor,omitempty"`
NextCursor string `json:"next_cursor,omitempty"`
}

// FindMetaBySrc is used to query meta entries by source and key.
type FindMetaBySrc struct {
Key string `query:"key" title:"Key" description:"Key used to identify the meta entries." example:"service-id"`
IncludeSecure bool `query:"include_secure" title:"Include Secure" description:"When true, secure meta entries are included in results." example:"false"`
Shared bool `query:"shared" title:"Shared" description:"When true, only shared meta entries are returned." example:"false"`
Limit int32 `query:"limit" title:"Limit" description:"Maximum number of entries to return." example:"100"`
Cursor string `query:"cursor" title:"Cursor" description:"Position provided by the previous result's next_cursor property."`
}

// SiloMeta describes a meta row embedded inside a Silo Entry.
type SiloMeta struct {
ID string `json:"id" title:"ID" description:"Compound ID of the meta row." example:"347c5b04-cde2-11ed-afa1-0242ac120002:source:key"`
Expand Down Expand Up @@ -49,6 +68,33 @@ type UpsertSiloMeta struct {
Shared bool `json:"shared,omitempty" title:"Shared" description:"When true, the meta entry can be shared with other applications." example:"true"`
}

// Find retrieves meta entries by source and key with pagination support.
// The source is determined by the authentication token's app ID.
func (s *SiloMetaService) Find(ctx context.Context, req *FindMetaBySrc) (*SiloMetaCollection, error) {
if req.Key == "" {
return nil, errors.New("missing key")
}
p := path.Join(siloBasePath, entriesPath, metaPath, req.Key)
query := make(url.Values)
if req.IncludeSecure {
query.Add("include_secure", "true")
}
if req.Shared {
query.Add("shared", "true")
}
if req.Limit != 0 {
query.Add("limit", strconv.Itoa(int(req.Limit)))
}
if req.Cursor != "" {
query.Add("cursor", req.Cursor)
}
if len(query) > 0 {
p = p + "?" + query.Encode()
}
col := new(SiloMetaCollection)
return col, s.client.get(ctx, p, col)
}

// Fetch retrieves a meta row by its key.
func (s *SiloMetaService) Fetch(ctx context.Context, entryID, key string) (*SiloMeta, error) {
if entryID == "" {
Expand Down
Loading