Files
upstream-corteza/server/pkg/envoy/resource/compose_chart.go
upstream-mirror 7e385fc126
Some checks failed
SonarQube / SonarQube (push) Failing after 5m28s
E2e test on main branch push / server and client test (map[name:admin port:8080]) (push) Failing after 3m33s
Server and lib tests / Library test (js) (push) Failing after 1m36s
Server and lib tests / Library test (vue) (push) Successful in 2m24s
Server and lib tests / Web client test (admin) (push) Successful in 2m52s
Server and lib tests / Web client test (compose) (push) Successful in 3m23s
Server and lib tests / Web client test (discovery) (push) Successful in 2m49s
Server and lib tests / Web client test (one) (push) Successful in 2m52s
Server and lib tests / Web client test (privacy) (push) Successful in 2m44s
Server and lib tests / Web client test (reporter) (push) Successful in 2m56s
Server and lib tests / Web client test (workflow) (push) Successful in 3m0s
Server and lib tests / Server tests (push) Failing after 4m55s
E2e test on main branch push / notify-failure (push) Failing after 9s
Server and lib tests / Send matrix testing notification (push) Successful in 2s
Mark stale issues and pull requests / stale (push) Successful in 40s
snapshot of https://github.com/cortezaproject/corteza.git (2024.9.x, 2026-09-18; blobs > 131072B omitted)
2026-09-18 01:22:23 +05:00

115 lines
2.5 KiB
Go

package resource
import (
"fmt"
"strconv"
"github.com/cortezaproject/corteza/server/compose/types"
)
type (
// ComposeChart represents a ComposeChart
ComposeChart struct {
*base
Res *types.Chart
// Might keep track of related namespace
RefNs *Ref
RefMods RefSet
}
)
func NewComposeChart(res *types.Chart, nsRef *Ref, mmRef RefSet) *ComposeChart {
r := &ComposeChart{
base: &base{},
RefMods: make(RefSet, len(mmRef)),
}
r.SetResourceType(types.ChartResourceType)
r.Res = res
r.AddIdentifier(identifiers(res.Handle, res.Name, res.ID)...)
r.RefNs = r.addRef(nsRef)
for i, mRef := range mmRef {
r.RefMods[i] = r.addRef(mRef).Constraint(r.RefNs)
}
// Initial timestamps
r.SetTimestamps(MakeTimestampsCUDA(&res.CreatedAt, res.UpdatedAt, res.DeletedAt, nil))
return r
}
func (r *ComposeChart) Resource() interface{} {
return r.Res
}
func (r *ComposeChart) ReRef(old RefSet, new RefSet) {
r.base.ReRef(old, new)
// Additional references
for _, n := range new {
if n.ResourceType == types.NamespaceResourceType {
r.RefNs = MakeRef(types.NamespaceResourceType, n.Identifiers)
}
}
for i, o := range old {
if o.ResourceType == types.ModuleResourceType {
r.RefMods = r.RefMods.replaceRef(o, new[i])
}
}
}
func (r *ComposeChart) SysID() uint64 {
return r.Res.ID
}
func (r *ComposeChart) resourceParts(tpl string) (resource string, ref *Ref, path []*Ref) {
ref = r.Ref().Constraint(r.RefNs)
path = []*Ref{r.RefNs}
resource = fmt.Sprintf(types.ChartRbacResourceTpl(), types.ChartResourceType, r.RefNs.Identifiers.First(), firstOkString(strconv.FormatUint(r.Res.ID, 10), r.Res.Handle))
return
}
func (r *ComposeChart) RBACParts() (resource string, ref *Ref, path []*Ref) {
return r.resourceParts(types.ChartRbacResourceTpl())
}
func (r *ComposeChart) ResourceTranslationParts() (resource string, ref *Ref, path []*Ref) {
return r.resourceParts(types.ChartResourceTranslationTpl())
}
func (r *ComposeChart) encodeTranslations() ([]*ResourceTranslation, error) {
return nil, nil
}
// FindComposeChart looks for the chart in the resources
func FindComposeChart(rr InterfaceSet, ii Identifiers) (ch *types.Chart) {
var chRes *ComposeChart
rr.Walk(func(r Interface) error {
cr, ok := r.(*ComposeChart)
if !ok {
return nil
}
if cr.Identifiers().HasAny(ii) {
chRes = cr
}
return nil
})
// Found it
if chRes != nil {
return chRes.Res
}
return nil
}
func ComposeChartErrUnresolved(ii Identifiers) error {
return fmt.Errorf("compose chart unresolved %v", ii.StringSlice())
}