Skip to content

APIGOV-29632 - fixes found while testing with agent #886

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 5 commits into from
Feb 5, 2025
Merged
Show file tree
Hide file tree
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
10 changes: 5 additions & 5 deletions pkg/agent/cache/applicationprofiledefinitions.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,23 +8,23 @@ import v1 "github.com/Axway/agent-sdk/pkg/apic/apiserver/models/api/v1"
func (c *cacheManager) AddApplicationProfileDefinition(resource *v1.ResourceInstance) {
defer c.setCacheUpdated(true)

c.ardMap.SetWithSecondaryKey(resource.Metadata.ID, resource.Name, resource)
c.apdMap.SetWithSecondaryKey(resource.Metadata.ID, resource.Name, resource)
}

// GetApplicationProfileDefinitionKeys - returns keys for ApplicationProfileDefinition cache
func (c *cacheManager) GetApplicationProfileDefinitionKeys() []string {
c.ApplyResourceReadLock()
defer c.ReleaseResourceReadLock()

return c.ardMap.GetKeys()
return c.apdMap.GetKeys()
}

// GetApplicationProfileDefinitionByName - returns resource from ApplicationProfileDefinition cache based on resource name
func (c *cacheManager) GetApplicationProfileDefinitionByName(name string) (*v1.ResourceInstance, error) {
c.ApplyResourceReadLock()
defer c.ReleaseResourceReadLock()

item, err := c.ardMap.GetBySecondaryKey(name)
item, err := c.apdMap.GetBySecondaryKey(name)
if item != nil {
if ard, ok := item.(*v1.ResourceInstance); ok {
ard.CreateHashes()
Expand All @@ -39,7 +39,7 @@ func (c *cacheManager) GetApplicationProfileDefinitionByID(id string) (*v1.Resou
c.ApplyResourceReadLock()
defer c.ReleaseResourceReadLock()

item, err := c.ardMap.Get(id)
item, err := c.apdMap.Get(id)
if item != nil {
if ard, ok := item.(*v1.ResourceInstance); ok {
ard.CreateHashes()
Expand All @@ -53,5 +53,5 @@ func (c *cacheManager) GetApplicationProfileDefinitionByID(id string) (*v1.Resou
func (c *cacheManager) DeleteApplicationProfileDefinition(id string) error {
defer c.setCacheUpdated(true)

return c.ardMap.Delete(id)
return c.apdMap.Delete(id)
}
4 changes: 4 additions & 0 deletions pkg/agent/cache/manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ const (
instanceCountKey = "instanceCount"
credReqDefKey = "credReqDef"
accReqDefKey = "accReqDef"
appProfDefKey = "appProfDef"
teamsKey = "teams"
managedAppKey = "managedApp"
subscriptionsKey = "subscriptions"
Expand Down Expand Up @@ -140,6 +141,7 @@ type cacheManager struct {
persistedCache cache.Cache
teams cache.Cache
ardMap cache.Cache
apdMap cache.Cache
crdMap cache.Cache
cacheFilename string
isPersistedCacheLoaded bool
Expand Down Expand Up @@ -185,6 +187,7 @@ func (c *cacheManager) initializeCache(cfg config.CentralConfig) {
instanceCountKey: func(loaded cache.Cache) { c.instanceCountMap = loaded },
credReqDefKey: func(loaded cache.Cache) { c.crdMap = loaded },
accReqDefKey: func(loaded cache.Cache) { c.ardMap = loaded },
appProfDefKey: func(loaded cache.Cache) { c.apdMap = loaded },
teamsKey: func(loaded cache.Cache) { c.teams = loaded },
managedAppKey: func(loaded cache.Cache) { c.managedApplicationMap = loaded },
subscriptionsKey: func(loaded cache.Cache) { c.subscriptionMap = loaded },
Expand Down Expand Up @@ -341,6 +344,7 @@ func (c *cacheManager) Flush() {
c.accessRequestMap.Flush()
c.apiMap.Flush()
c.ardMap.Flush()
c.apdMap.Flush()
c.crdMap.Flush()
c.instanceMap.Flush()
c.managedApplicationMap.Flush()
Expand Down
2 changes: 1 addition & 1 deletion pkg/agent/events/watchtopic.go
Original file line number Diff line number Diff line change
Expand Up @@ -244,7 +244,7 @@ func NewDiscoveryWatchTopic(name, scope string, agentResourceGroupKind v1.GroupK
{GroupKind: management.ManagedApplicationGVK().GroupKind, ScopeName: scope, ScopeKind: management.EnvironmentGVK().Kind, EventTypes: createdOrUpdated},
{GroupKind: management.CredentialRequestDefinitionGVK().GroupKind, ScopeName: scope, ScopeKind: management.EnvironmentGVK().Kind, EventTypes: all},
{GroupKind: management.AccessRequestDefinitionGVK().GroupKind, ScopeName: scope, ScopeKind: management.EnvironmentGVK().Kind, EventTypes: all},
{GroupKind: management.ManagedApplicationProfileGVK().GroupKind, Name: scope, EventTypes: createdOrUpdated},
{GroupKind: management.ManagedApplicationProfileGVK().GroupKind, ScopeName: scope, ScopeKind: management.EnvironmentGVK().Kind, EventTypes: createdOrUpdated},
{GroupKind: management.ApplicationProfileDefinitionGVK().GroupKind, ScopeName: scope, ScopeKind: management.EnvironmentGVK().Kind, EventTypes: all},
{GroupKind: management.EnvironmentGVK().GroupKind, Name: scope, EventTypes: updated},
}
Expand Down
12 changes: 11 additions & 1 deletion pkg/agent/provisioning.go
Original file line number Diff line number Diff line change
Expand Up @@ -509,7 +509,17 @@ func createOrUpdateAccessRequestDefinition(data *management.AccessRequestDefinit
if ri == nil || err != nil {
return nil, err
}
err = data.FromInstance(ri)

if data.FromInstance(ri) == nil && agent.applicationProfileDefinition != "" {
err = agent.apicClient.CreateSubResource(ri.ResourceMeta,
map[string]interface{}{
management.AccessRequestDefinitionApplicationprofileSubResourceName: data.Applicationprofile,
})
if err != nil {
return data, err
}
}

return data, err
}

Expand Down
4 changes: 4 additions & 0 deletions pkg/apic/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -783,6 +783,8 @@ func (c *ServiceClient) getCachedResource(data *apiv1.ResourceInstance) (*apiv1.
return c.caches.GetAccessRequestDefinitionByName(data.Name)
case management.CredentialRequestDefinitionGVK().Kind:
return c.caches.GetCredentialRequestDefinitionByName(data.Name)
case management.ApplicationProfileDefinitionGVK().Kind:
return c.caches.GetApplicationProfileDefinitionByName(data.Name)
case management.APIServiceInstanceGVK().Kind:
return c.caches.GetAPIServiceInstanceByName(data.Name)
}
Expand All @@ -795,6 +797,8 @@ func (c *ServiceClient) addResourceToCache(data *apiv1.ResourceInstance) {
c.caches.AddAccessRequestDefinition(data)
case management.CredentialRequestDefinitionGVK().Kind:
c.caches.AddCredentialRequestDefinition(data)
case management.ApplicationProfileDefinitionGVK().Kind:
c.caches.AddApplicationProfileDefinition(data)
case management.APIServiceInstanceGVK().Kind:
c.caches.AddAPIServiceInstance(data)
}
Expand Down
4 changes: 3 additions & 1 deletion pkg/apic/provisioning/accessrequestdefinitionbuilder.go
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,9 @@ func (a *accessRequestDef) Register() (*management.AccessRequestDefinition, erro
ard.Spec = spec

if a.appProfDef != "" {
ard.Applicationprofile.Name = a.appProfDef
ard.Applicationprofile = management.AccessRequestDefinitionApplicationprofile{
Name: a.appProfDef,
}
}

util.SetAgentDetailsKey(ard, definitions.AttrSpecHash, fmt.Sprintf("%v", hashInt))
Expand Down
53 changes: 53 additions & 0 deletions pkg/apic/provisioning/propertybuilder.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ const (
DataTypeInteger = "integer"
DataTypeArray = "array"
DataTypeObject = "object"
DataTypeBoolean = "boolean"
)

// oneOfPropertyDefinitions - used for items of propertyDefinition
Expand Down Expand Up @@ -95,6 +96,8 @@ type TypePropertyBuilder interface {
SetReadOnly() TypePropertyBuilder
// SetHidden - set the property as a hidden property
SetHidden() TypePropertyBuilder
// IsBoolean - Set the property to be of type string
IsBoolean() BooleanPropertyBuilder
// IsString - Set the property to be of type string
IsString() StringPropertyBuilder
// IsInteger - Set the property to be of type integer
Expand All @@ -108,6 +111,13 @@ type TypePropertyBuilder interface {
PropertyBuilder
}

// BooleanPropertyBuilder - specific methods related to the Boolean property builders
type BooleanPropertyBuilder interface {
// SetDefaultValue - Define the initial value for the property
SetDefaultValue(value bool) BooleanPropertyBuilder
PropertyBuilder
}

// StringPropertyBuilder - specific methods related to the String property builders
type StringPropertyBuilder interface {
// SetEnumValues - Set a list of valid values for the property
Expand Down Expand Up @@ -233,6 +243,14 @@ func (p *schemaProperty) IsString() StringPropertyBuilder {
}
}

// IsString - Set the property to be of type string
func (p *schemaProperty) IsBoolean() BooleanPropertyBuilder {
p.dataType = DataTypeBoolean
return &booleanSchemaProperty{
schemaProperty: p,
}
}

// IsNumber - Set the property to be of type number
func (p *schemaProperty) IsNumber() NumberPropertyBuilder {
p.dataType = DataTypeNumber
Expand Down Expand Up @@ -503,6 +521,41 @@ func (p *stringSchemaProperty) buildDependenciesDef(val string, props []Property
return depDef, nil
}

/**
boolean property datatype
*/
// booleanSchemaProperty - adds specific info needed for a boolean schema property
type booleanSchemaProperty struct {
schemaProperty *schemaProperty
defaultValue *bool
BooleanPropertyBuilder
}

// SetDefaultValue - Define the initial value for the property
func (p *booleanSchemaProperty) SetDefaultValue(value bool) BooleanPropertyBuilder {
p.defaultValue = &value
return p
}

// Build - create the propertyDefinition for use in the subscription schema builder
func (p *booleanSchemaProperty) Build() (def *propertyDefinition, err error) {
def, err = p.schemaProperty.Build()
if err != nil {
return
}

if p.defaultValue != nil {
def.DefaultValue = p.defaultValue
}

return def, err
}

// BuildDependencies - builds the dependencies for the property, this is called automatically by the schema builder
func (p *booleanSchemaProperty) BuildDependencies() (*oneOfPropertyDefinitions, error) {
return nil, nil
}

/**
number property datatype builder
*/
Expand Down
29 changes: 15 additions & 14 deletions pkg/apic/provisioning/schemabuilder.go
Original file line number Diff line number Diff line change
Expand Up @@ -91,24 +91,25 @@ func (s *schemaBuilder) SetPropertyOrder(propertyOrder []string) SchemaBuilder {
// AddProperty - adds a new subscription schema property to the schema
func (s *schemaBuilder) AddProperty(property PropertyBuilder) SchemaBuilder {
prop, err := property.Build()
if err == nil {
s.properties[prop.Name] = *prop
if err != nil {
s.err = err
return s
}

// If property order wasn't set, add property as they come in
if !s.propertyOrderSet {
s.propertyOrder = append(s.propertyOrder, prop.Name)
}
s.properties[prop.Name] = *prop

dep, err := property.BuildDependencies()
if err != nil {
s.err = err
}
if dep != nil {
s.dependencies[prop.Name] = dep
}
} else {
// If property order wasn't set, add property as they come in
if !s.propertyOrderSet {
s.propertyOrder = append(s.propertyOrder, prop.Name)
}

dep, err := property.BuildDependencies()
if err != nil {
s.err = err
}
if dep != nil {
s.dependencies[prop.Name] = dep
}

return s
}
Expand Down