Skip to content

Commit

Permalink
APIGOV-21721 - prepend the title incase its the same as the name (#324)
Browse files Browse the repository at this point in the history
  • Loading branch information
jcollins-axway authored Feb 15, 2022
1 parent d74f8f4 commit 83a24a6
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 19 deletions.
7 changes: 5 additions & 2 deletions pkg/agent/cache/manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package cache

import (
"encoding/json"
"fmt"
"sync"

"github.com/Axway/agent-sdk/pkg/apic/definitions"
Expand Down Expand Up @@ -344,9 +345,11 @@ func (c *cacheManager) DeleteAllAPIServiceInstance() {

// AddCategory - add/update Category resource in cache
func (c *cacheManager) AddCategory(resource *v1.ResourceInstance) {
c.ApplyResourceReadLock()
defer c.ReleaseResourceReadLock()
defer c.setCacheUpdated(true)

c.categoryMap.SetWithSecondaryKey(resource.Name, resource.Title, resource)
c.categoryMap.SetWithSecondaryKey(resource.Name, fmt.Sprintf("title-%s", resource.Title), resource)
}

// GetCategoryCache - returns the Category cache
Expand Down Expand Up @@ -382,7 +385,7 @@ func (c *cacheManager) GetCategoryWithTitle(title string) *v1.ResourceInstance {
c.ApplyResourceReadLock()
defer c.ReleaseResourceReadLock()

category, _ := c.categoryMap.GetBySecondaryKey(title)
category, _ := c.categoryMap.GetBySecondaryKey(fmt.Sprintf("title-%s", title))
if category != nil {
ri, ok := category.(*v1.ResourceInstance)
if ok {
Expand Down
24 changes: 7 additions & 17 deletions pkg/apic/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -120,14 +120,8 @@ func (c *ServiceClient) getTeamFromCache(teamName string) (string, bool) {

// GetOrCreateCategory - Returns the value on published proxy
func (c *ServiceClient) GetOrCreateCategory(category string) string {
categoryCache := c.caches.GetCategoryCache()
if categoryCache == nil {
log.Errorf("category cache has not been initialized")
return ""
}

categoryInterface, _ := categoryCache.GetBySecondaryKey(category)
if categoryInterface == nil {
categoryResource := c.caches.GetCategoryWithTitle(category)
if categoryResource == nil {
if !corecfg.IsCategoryAutocreationEnabled() {
log.Warnf("Category auto creation is disabled: agent is not allowed to create %s category", category)
return ""
Expand All @@ -139,17 +133,13 @@ func (c *ServiceClient) GetOrCreateCategory(category string) string {
log.Errorf(errors.Wrap(ErrCategoryCreate, err.Error()).FormatError(category).Error())
return ""
}
categoryInterface, _ = newCategory.AsInstance()
log.Infof("Created new category %s (%s)", newCategory.Title, newCategory.Name)
categoryCache.SetWithSecondaryKey(newCategory.Name, newCategory.Title, categoryInterface)
}

cat, ok := categoryInterface.(*apiv1.ResourceInstance)
if !ok {
return ""
categoryResource, err = newCategory.AsInstance()
if err == nil {
c.caches.AddCategory(categoryResource)
}
}

return cat.Name
return categoryResource.Name
}

// initClient - config change handler
Expand Down

0 comments on commit 83a24a6

Please sign in to comment.