Skip to content

Commit

Permalink
Merge branch 'master' into api-enhancements
Browse files Browse the repository at this point in the history
Signed-off-by: VihasMakwana <[email protected]>
Signed-off-by: Vihas Makwana <[email protected]>
  • Loading branch information
VihasMakwana committed Dec 5, 2023
2 parents 20a205a + 955b388 commit d762f1d
Show file tree
Hide file tree
Showing 10 changed files with 39 additions and 18 deletions.
8 changes: 4 additions & 4 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ require (
gorm.io/driver/postgres v1.5.3
gorm.io/driver/sqlite v1.5.4
gorm.io/gorm v1.25.5
helm.sh/helm/v3 v3.13.0
helm.sh/helm/v3 v3.13.2
k8s.io/api v0.28.3
k8s.io/apimachinery v0.28.3
k8s.io/cli-runtime v0.28.3
Expand Down Expand Up @@ -67,7 +67,7 @@ require (
github.com/deckarep/golang-set v1.8.0 // indirect
github.com/docker/cli v24.0.6+incompatible // indirect
github.com/docker/distribution v2.8.2+incompatible // indirect
github.com/docker/docker v24.0.6+incompatible // indirect
github.com/docker/docker v24.0.7+incompatible // indirect
github.com/docker/docker-credential-helpers v0.7.0 // indirect
github.com/docker/go-connections v0.4.0 // indirect
github.com/docker/go-metrics v0.0.1 // indirect
Expand Down Expand Up @@ -148,7 +148,7 @@ require (
github.com/morikuni/aec v1.0.0 // indirect
github.com/mpvl/unique v0.0.0-20150818121801-cbe035fff7de // indirect
github.com/munnerz/goautoneg v0.0.0-20191010083416-a7dc8b61c822 // indirect
github.com/nats-io/nkeys v0.4.5 // indirect
github.com/nats-io/nkeys v0.4.6 // indirect
github.com/nats-io/nuid v1.0.1 // indirect
github.com/novln/docker-parser v1.0.0 // indirect
github.com/opencontainers/go-digest v1.0.0 // indirect
Expand Down Expand Up @@ -211,7 +211,7 @@ require (
k8s.io/klog/v2 v2.100.1 // indirect
k8s.io/kube-openapi v0.0.0-20230717233707-2695361300d9 // indirect
k8s.io/utils v0.0.0-20230406110748-d93618cff8a2 // indirect
oras.land/oras-go v1.2.3 // indirect
oras.land/oras-go v1.2.4 // indirect
sigs.k8s.io/controller-runtime v0.13.0 // indirect
sigs.k8s.io/json v0.0.0-20221116044647-bc3834ca7abd // indirect
sigs.k8s.io/kustomize/api v0.13.5-0.20230601165947-6ce0bf390ce3 // indirect
Expand Down
12 changes: 6 additions & 6 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -658,8 +658,8 @@ github.com/mwitkow/go-conntrack v0.0.0-20161129095857-cc309e4a2223/go.mod h1:qRW
github.com/mxk/go-flowrate v0.0.0-20140419014527-cca7078d478f/go.mod h1:ZdcZmHo+o7JKHSa8/e818NopupXU1YMK5fe1lsApnBw=
github.com/nats-io/nats.go v1.31.0 h1:/WFBHEc/dOKBF6qf1TZhrdEfTmOZ5JzdJ+Y3m6Y/p7E=
github.com/nats-io/nats.go v1.31.0/go.mod h1:di3Bm5MLsoB4Bx61CBTsxuarI36WbhAwOm8QrW39+i8=
github.com/nats-io/nkeys v0.4.5 h1:Zdz2BUlFm4fJlierwvGK+yl20IAKUm7eV6AAZXEhkPk=
github.com/nats-io/nkeys v0.4.5/go.mod h1:XUkxdLPTufzlihbamfzQ7mw/VGx6ObUs+0bN5sNvt64=
github.com/nats-io/nkeys v0.4.6 h1:IzVe95ru2CT6ta874rt9saQRkWfe2nFj1NtvYSLqMzY=
github.com/nats-io/nkeys v0.4.6/go.mod h1:4DxZNzenSVd1cYQoAa8948QY3QDjrHfcfVADymtkpts=
github.com/nats-io/nuid v1.0.1 h1:5iA8DT8V7q8WK2EScv2padNa/rTESc1KdnPw4TC2paw=
github.com/nats-io/nuid v1.0.1/go.mod h1:19wcPz3Ph3q0Jbyiqsd0kePYG7A95tJPxeL+1OSON2c=
github.com/niemeyer/pretty v0.0.0-20200227124842-a10e7caefd8e/go.mod h1:zD1mROLANZcx1PVRCS0qkT7pwLkGfwJo4zjcN/Tysno=
Expand Down Expand Up @@ -1360,8 +1360,8 @@ gotest.tools v2.2.0+incompatible h1:VsBPFP1AI068pPrMxtb/S8Zkgf9xEmTLJjfM+P5UIEo=
gotest.tools v2.2.0+incompatible/go.mod h1:DsYFclhRJ6vuDpmuTbkuFWG+y2sxOXAzmJt81HFBacw=
gotest.tools/v3 v3.4.0 h1:ZazjZUfuVeZGLAmlKKuyv3IKP5orXcwtOwDQH6YVr6o=
gotest.tools/v3 v3.4.0/go.mod h1:CtbdzLSsqVhDgMtKsx03ird5YTGB3ar27v0u/yKBW5g=
helm.sh/helm/v3 v3.13.0 h1:XPJKIU30K4JTQ6VX/6e0hFAmEIonYa8E7wx5aqv4xOc=
helm.sh/helm/v3 v3.13.0/go.mod h1:2PBEKsMWKLVZTojUOqMS3Eadv5mP43FBWrRgLNkNm9Y=
helm.sh/helm/v3 v3.13.2 h1:IcO9NgmmpetJODLZhR3f3q+6zzyXVKlRizKFwbi7K8w=
helm.sh/helm/v3 v3.13.2/go.mod h1:GIHDwZggaTGbedevTlrQ6DB++LBN6yuQdeGj0HNaDx0=
honnef.co/go/tools v0.0.0-20190102054323-c2f93a96b099/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4=
honnef.co/go/tools v0.0.0-20190106161140-3f1c8253044a/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4=
honnef.co/go/tools v0.0.0-20190418001031-e561f6794a2a/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4=
Expand Down Expand Up @@ -1408,8 +1408,8 @@ k8s.io/utils v0.0.0-20210802155522-efc7438f0176/go.mod h1:jPW/WVKK9YHAvNhRxK0md/
k8s.io/utils v0.0.0-20211116205334-6203023598ed/go.mod h1:jPW/WVKK9YHAvNhRxK0md/EJ228hCsBRufyofKtW8HA=
k8s.io/utils v0.0.0-20230406110748-d93618cff8a2 h1:qY1Ad8PODbnymg2pRbkyMT/ylpTrCM8P2RJ0yroCyIk=
k8s.io/utils v0.0.0-20230406110748-d93618cff8a2/go.mod h1:OLgZIPagt7ERELqWJFomSt595RzquPNLL48iOWgYOg0=
oras.land/oras-go v1.2.3 h1:v8PJl+gEAntI1pJ/LCrDgsuk+1PKVavVEPsYIHFE5uY=
oras.land/oras-go v1.2.3/go.mod h1:M/uaPdYklze0Vf3AakfarnpoEckvw0ESbRdN8Z1vdJg=
oras.land/oras-go v1.2.4 h1:djpBY2/2Cs1PV87GSJlxv4voajVOMZxqqtq9AB8YNvY=
oras.land/oras-go v1.2.4/go.mod h1:DYcGfb3YF1nKjcezfX2SNlDAeQFKSXmf+qrFmrh4324=
rsc.io/binaryregexp v0.2.0/go.mod h1:qTv7/COck+e2FymRvadv62gMdZztPaShugOCi3I+8D8=
rsc.io/quote/v3 v3.1.0/go.mod h1:yEA65RcK8LyAZtP9Kv3t0HmxON59tX3rD+tICJqUlj0=
rsc.io/sampler v1.3.0/go.mod h1:T1hPZKmBbMNahiBKFy5HrXp6adAjACjK9JXDnKaTXpA=
Expand Down
11 changes: 9 additions & 2 deletions models/meshmodel/core/policies/rego_policy_relationship.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package policies
import (
"context"
"encoding/json"
"fmt"
"io/fs"
"os"
"path/filepath"
Expand Down Expand Up @@ -69,7 +70,7 @@ func mapRelationshipsWithSubType(relationships *[]v1alpha1.RelationshipDefinitio
}

// RegoPolicyHandler takes the required inputs and run the query against all the policy files provided
func (r *Rego) RegoPolicyHandler(regoQueryString string, designFile []byte) (map[string]interface{}, error) {
func (r *Rego) RegoPolicyHandler(regoQueryString string, designFile []byte) (interface{}, error) {
regoEngine, err := rego.New(
rego.Query(regoQueryString),
rego.Load([]string{r.policyDir}, nil),
Expand All @@ -93,7 +94,13 @@ func (r *Rego) RegoPolicyHandler(regoQueryString string, designFile []byte) (map
}

if !eval_result.Allowed() {
return eval_result[0].Expressions[0].Value.(map[string]interface{}), nil
if len(eval_result) > 0 {
if len(eval_result[0].Expressions) > 0 {
return eval_result[0].Expressions[0].Value, nil
}
return nil, ErrEval(fmt.Errorf("evaluation results are empty"))
}
return nil, ErrEval(fmt.Errorf("evaluation results are empty"))
}

return nil, ErrEval(err)
Expand Down
2 changes: 1 addition & 1 deletion models/meshmodel/core/v1alpha1/component.go
Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,7 @@ type ComponentFilter struct {
OrderOn string
Limit int //If 0 or unspecified then all records are returned and limit is not used
Offset int
Annotations string
Annotations string //When this query parameter is "true", only components with the "isAnnotation" property set to true are returned. When this query parameter is "false", all components except those considered to be annotation components are returned. Any other value of the query parameter results in both annotations as well as non-annotation models being returned.
}

// Create the filter from map[string]interface{}
Expand Down
4 changes: 3 additions & 1 deletion models/meshmodel/core/v1alpha1/models.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,11 @@ type ModelFilter struct {
Category string
OrderOn string
Sort string //asc or desc. Default behavior is asc
Limit int //If 0 or unspecified then all records are returned and limit is not used
Limit int //If 0 or unspecified then all records are returned and limit is not used
Offset int
Annotations string //When this query parameter is "true", only models with the "isAnnotation" property set to true are returned. When this query parameter is "false", all models except those considered to be annotation models are returned. Any other value of the query parameter results in both annoations as well as non-annotation models being returned.

// When these are set to true, we also retrieve components/relationships associated with the model.
Components bool
Relationships bool
}
Expand Down
4 changes: 4 additions & 0 deletions models/meshmodel/core/v1alpha1/relationship.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ type RelationshipDefinition struct {
DisplayHostName string `json:"displayhostname"`
Metadata map[string]interface{} `json:"metadata" yaml:"metadata"`
SubType string `json:"subType" yaml:"subType" gorm:"subType"`
RegoQuery string `json:"rego_query" yaml:"rego_query" gorm:"rego_query"`
Selectors map[string]interface{} `json:"selectors" yaml:"selectors"`
CreatedAt time.Time `json:"-"`
UpdatedAt time.Time `json:"-"`
Expand All @@ -35,6 +36,7 @@ type RelationshipDefinitionDB struct {
TypeMeta
Metadata []byte `json:"metadata" yaml:"metadata"`
SubType string `json:"subType" yaml:"subType"`
RegoQuery string `json:"rego_query" yaml:"rego_query" gorm:"rego_query"`
Selectors []byte `json:"selectors" yaml:"selectors"`
CreatedAt time.Time `json:"-"`
UpdatedAt time.Time `json:"-"`
Expand Down Expand Up @@ -127,6 +129,7 @@ func (rdb *RelationshipDefinitionDB) GetRelationshipDefinition(m Model) (r Relat
r.SubType = rdb.SubType
r.Kind = rdb.Kind
r.Model = m
r.RegoQuery = rdb.RegoQuery
return
}

Expand Down Expand Up @@ -160,5 +163,6 @@ func (r *RelationshipDefinition) GetRelationshipDefinitionDB() (rdb Relationship
rdb.Kind = r.Kind
rdb.SubType = r.SubType
rdb.ModelID = r.Model.ID
rdb.RegoQuery = r.RegoQuery
return
}
10 changes: 10 additions & 0 deletions models/meshmodel/registry/registry.go
Original file line number Diff line number Diff line change
Expand Up @@ -337,6 +337,11 @@ func (rm *RegistryManager) GetModels(db *database.Handler, f types.Filter) ([]v1
finder = finder.Where("model_dbs.display_name = ?", mf.DisplayName)
}
}
if mf.Annotations == "true" {
finder = finder.Where("model_dbs.metadata->>'isAnnotation' = true")
} else if mf.Annotations == "false" {
finder = finder.Where("model_dbs.metadata->>'isAnnotation' = false")
}
if mf.Version != "" {
finder = finder.Where("model_dbs.version = ?", mf.Version)
}
Expand All @@ -346,6 +351,11 @@ func (rm *RegistryManager) GetModels(db *database.Handler, f types.Filter) ([]v1
if mf.Registrant != "" {
finder = finder.Where("hosts.hostname = ?", mf.Registrant)
}
if mf.Annotations == "true" {
finder = finder.Where("model_dbs.metadata->>'isAnnotation' = true")
} else if mf.Annotations == "false" {
finder = finder.Where("model_dbs.metadata->>'isAnnotation' = false")
}
if mf.OrderOn != "" {
if mf.Sort == "desc" {
finder = finder.Order(clause.OrderByColumn{Column: clause.Column{Name: mf.OrderOn}, Desc: true})
Expand Down
2 changes: 1 addition & 1 deletion models/oam/core/v1alpha1/application_configuration.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,4 +44,4 @@ type ConfigurationSpecComponentScope struct {
type ConfigurationSpecComponentScopeRef struct {
metav1.TypeMeta `json:",inline"`
Name string
}
}
1 change: 0 additions & 1 deletion utils/manifests/getComponents.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ import (
k8s "github.com/layer5io/meshkit/utils/kubernetes"
)


func GetFromManifest(ctx context.Context, url string, resource int, cfg Config) (*Component, error) {
manifest, err := utils.ReadFileSource(url)
if err != nil {
Expand Down
3 changes: 1 addition & 2 deletions utils/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -247,7 +247,6 @@ func Contains[G []K, K comparable](slice G, ele K) bool {
return false
}


func Cast[K any](val interface{}) (K, error) {
assertedValue, ok := val.(K)
if !ok {
Expand All @@ -256,7 +255,7 @@ func Cast[K any](val interface{}) (K, error) {
return assertedValue, nil
}

func MarshalAndUnmarshal[fromType any, toType any](val fromType) (unmarshalledvalue toType, err error){
func MarshalAndUnmarshal[fromType any, toType any](val fromType) (unmarshalledvalue toType, err error) {
data, err := Marshal(val)
if err != nil {
return
Expand Down

0 comments on commit d762f1d

Please sign in to comment.