Skip to content

Commit

Permalink
MR issues
Browse files Browse the repository at this point in the history
  • Loading branch information
dgghinea committed Nov 27, 2023
1 parent aa43fe3 commit 4b2285c
Show file tree
Hide file tree
Showing 6 changed files with 31 additions and 24 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ In order to publish a specification file that properly represents the gateway se

##### Local specification path

The local specification discovery method is configured by providing a value for the `KONG_SPEC_LOCALPATH` variable. When set the Kong agent will look for a tag, on the gateway service, that is prefixed by `spec_local_`. When that tag is set the value, after stripping the prefix, is used to find the specification file in directory configured by `KONG_SPEC_LOCALPATH`. When this configuration value is set no other specification discovery methods will be used.
The local specification discovery method is configured by providing a value for the `KONG_SPEC_LOCALPATH` variable. When set the Kong agent will look for a tag on each of the available routes from the gateway service that are prefixed by `spec_local_`. When that tag is set the value, after stripping the prefix, is used to find the specification file in directory configured by `KONG_SPEC_LOCALPATH`. When this configuration value is set no other specification discovery methods will be used.

Ex.

Expand Down
12 changes: 7 additions & 5 deletions pkg/common/common.go
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
package common

const (
AttrServiceId = "serviceId"
AttrRouteId = "routeId"
AttrChecksum = "checksum"
AttrAppID = "kongApplicationId"
AttrServiceID = "serviceID"
AttrRouteID = "routeID"
AttrChecksum = "checksum"
AttrAppID = "kongApplicationID"
AttrServiceName = "serviceName"
AttrRouteName = "routeName"

AttrCredentialID = "kongCredentialId"
AttrCredentialID = "kongCredentialID"
AttrCredUpdater = "kongCredentialUpdate"

AclGroup = "amplify.group"
Expand Down
18 changes: 10 additions & 8 deletions pkg/gateway/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ func (gc *Client) processKongServicesList(ctx context.Context, services []*klib.
}

func (gc *Client) processSingleKongService(ctx context.Context, service *klib.Service) error {
log := gc.logger.WithField("service-name", *service.Name)
log := gc.logger.WithField(common.AttrServiceName, *service.Name)
log.Info("processing service")

routes, err := gc.kongClient.ListRoutesForService(ctx, *service.ID)
Expand All @@ -121,14 +121,15 @@ func (gc *Client) processSingleKongService(ctx context.Context, service *klib.Se
}

func (gc *Client) specPreparation(ctx context.Context, route *klib.Route, service *klib.Service) {
log := gc.logger.WithField("route-id", *route.ID)
log := gc.logger.WithField(common.AttrRouteID, *route.ID).
WithField(common.AttrServiceID, *service.ID)
proxyHost := gc.kongGatewayCfg.Proxy.Host
httpPort := gc.kongGatewayCfg.Proxy.Port.HTTP
httpsPort := gc.kongGatewayCfg.Proxy.Port.HTTPS

apiPlugins, err := gc.plugins.GetEffectivePlugins(*route.ID, *service.ID)
if err != nil {
log.Infof("Could not list plugins for serviceID: %s, with routeID: %s", *service.ID, *route.ID)
log.Warn("could not list plugins")
return
}

Expand All @@ -138,7 +139,7 @@ func (gc *Client) specPreparation(ctx context.Context, route *klib.Route, servic
}
// don't publish an empty spec
if kongServiceSpec == nil {
log.Info("no spec found")
log.Warn("no spec found")
return
}
oasSpec := Openapi{
Expand All @@ -148,20 +149,21 @@ func (gc *Client) specPreparation(ctx context.Context, route *klib.Route, servic
endpoints := gc.processKongRoute(proxyHost, oasSpec.BasePath(), route, httpPort, httpsPort)
serviceBody, err := gc.processKongAPI(ctx, *route.ID, service, oasSpec, endpoints, apiPlugins)
if err != nil {
log.WithError(err).Error("Failed to process kong API")
log.WithError(err).Error("failed to process kong API")
return
}
if serviceBody == nil {
log.Info("not processing since no changes were detected")
return
}
log = log.WithField("apiName", serviceBody.APIName)
err = agent.PublishAPI(*serviceBody)
if err != nil {
log.WithError(err).Error("failed to publish api")
return
}

log.Infof("Published API '%s' to central", serviceBody.APIName)
log.Info("Successfully published to central")
}

func (gc *Client) processKongRoute(defaultHost string, basePath string, route *klib.Route, httpPort, httpsPort int) []apic.EndpointDefinition {
Expand Down Expand Up @@ -228,8 +230,8 @@ func (gc *Client) processKongAPI(
}

agentDetails := map[string]string{
common.AttrServiceId: *service.ID,
common.AttrRouteId: routeID,
common.AttrServiceID: *service.ID,
common.AttrRouteID: routeID,
common.AttrChecksum: checksum,
}
kongAPI.agentDetails = agentDetails
Expand Down
9 changes: 6 additions & 3 deletions pkg/kong/kongclient.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import (
"github.com/Axway/agent-sdk/pkg/util/log"

"github.com/Axway/agent-sdk/pkg/apic"
"github.com/Axway/agents-kong/pkg/common"
config "github.com/Axway/agents-kong/pkg/config/discovery"

klib "github.com/kong/go-kong/kong"
Expand Down Expand Up @@ -106,7 +107,8 @@ func (k KongClient) ListRoutesForService(ctx context.Context, serviceId string)
}

func (k KongClient) GetSpecForService(ctx context.Context, service *klib.Service, route *klib.Route) ([]byte, error) {
log := k.logger.WithField("serviceName", *service.Name).WithField("routeName", *route.Name)
log := k.logger.WithField(common.AttrServiceName, *service.Name).
WithField(common.AttrRouteName, *route.Name)

if k.specLocalPath != "" {
return k.getSpecFromLocal(ctx, service, route)
Expand All @@ -131,7 +133,8 @@ func (k KongClient) GetSpecForService(ctx context.Context, service *klib.Service
}

func (k KongClient) getSpecFromLocal(ctx context.Context, service *klib.Service, route *klib.Route) ([]byte, error) {
log := k.logger.WithField("serviceName", *service.Name).WithField("routeName", *route.Name)
log := k.logger.WithField(common.AttrServiceName, *service.Name).
WithField(common.AttrRouteName, *route.Name)

specTag := ""
for _, tag := range route.Tags {
Expand Down Expand Up @@ -174,7 +177,7 @@ func (k KongClient) loadSpecFile(specFilePath string) ([]byte, error) {
}

func (k KongClient) getSpecFromDevPortal(ctx context.Context, serviceID string) ([]byte, error) {
log := k.logger.WithField("serviceID", serviceID)
log := k.logger.WithField(common.AttrServiceID, serviceID)
log.Info("getting spec file from dev portal")

endpoint := fmt.Sprintf("%s/services/%s/document_objects", k.kongAdminEndpoint, serviceID)
Expand Down
2 changes: 1 addition & 1 deletion pkg/subscription/access/access.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ type AccessProvisioner struct {

func NewAccessProvisioner(ctx context.Context, client accessClient, request accessRequest) AccessProvisioner {
instDetails := request.GetInstanceDetails()
routeID := sdkUtil.ToString(instDetails[common.AttrRouteId])
routeID := sdkUtil.ToString(instDetails[common.AttrRouteID])

a := AccessProvisioner{
ctx: context.Background(),
Expand Down
12 changes: 6 additions & 6 deletions pkg/subscription/access/access_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ func TestProvision(t *testing.T) {
common.AttrAppID: "appID",
},
details: map[string]interface{}{
common.AttrRouteId: "routeID",
common.AttrRouteID: "routeID",
},
quota: &mockQuota{
interval: provisioning.Weekly,
Expand All @@ -133,7 +133,7 @@ func TestProvision(t *testing.T) {
common.AttrAppID: "appID",
},
details: map[string]interface{}{
common.AttrRouteId: "routeID",
common.AttrRouteID: "routeID",
},
quota: &mockQuota{
interval: provisioning.Daily,
Expand All @@ -152,7 +152,7 @@ func TestProvision(t *testing.T) {
common.AttrAppID: "appID",
},
details: map[string]interface{}{
common.AttrRouteId: "routeID",
common.AttrRouteID: "routeID",
},
quota: &mockQuota{
interval: provisioning.Daily,
Expand All @@ -169,7 +169,7 @@ func TestProvision(t *testing.T) {
common.AttrAppID: "appID",
},
details: map[string]interface{}{
common.AttrRouteId: "routeID",
common.AttrRouteID: "routeID",
},
quota: &mockQuota{
interval: provisioning.Daily,
Expand Down Expand Up @@ -216,7 +216,7 @@ func TestDeprovision(t *testing.T) {
common.AttrAppID: "appID",
},
details: map[string]interface{}{
common.AttrRouteId: "routeID",
common.AttrRouteID: "routeID",
},
quota: &mockQuota{
interval: provisioning.Daily,
Expand All @@ -233,7 +233,7 @@ func TestDeprovision(t *testing.T) {
common.AttrAppID: "appID",
},
details: map[string]interface{}{
common.AttrRouteId: "routeID",
common.AttrRouteID: "routeID",
},
quota: &mockQuota{
interval: provisioning.Daily,
Expand Down

0 comments on commit 4b2285c

Please sign in to comment.