sd.ApiId = &apiName
}
-func (sd *ServiceAPIDescription) RegisterKong(kongDomain string,
- kongProtocol string,
- kongIPv4 common29122.Ipv4Addr,
- kongDataPlanePort common29122.Port,
+func (sd *ServiceAPIDescription) RegisterKong(
+ kongDomain string,
+ kongProtocol string,
+ kongControlPlaneIPv4 common29122.Ipv4Addr,
kongControlPlanePort common29122.Port,
- apfId string) (int, error) {
+ kongDataPlaneIPv4 common29122.Ipv4Addr,
+ kongDataPlanePort common29122.Port,
+ apfId string) (int, error) {
log.Trace("entering RegisterKong")
+ log.Debugf("RegisterKong kongDataPlaneIPv4 %s", kongDataPlaneIPv4)
+
var (
statusCode int
err error
)
- kongControlPlaneURL := fmt.Sprintf("%s://%s:%d", kongProtocol, kongIPv4, kongControlPlanePort)
+ kongControlPlaneURL := fmt.Sprintf("%s://%s:%d", kongProtocol, kongControlPlaneIPv4, kongControlPlanePort)
statusCode, err = sd.createKongRoutes(kongControlPlaneURL, apfId)
if (err != nil) || (statusCode != http.StatusCreated) {
return statusCode, err
}
- sd.updateInterfaceDescription(kongIPv4, kongDataPlanePort, kongDomain)
+ sd.updateInterfaceDescription(kongDataPlaneIPv4, kongDataPlanePort, kongDomain)
log.Trace("exiting from RegisterKong")
return statusCode, nil
client := resty.New()
profiles := *sd.AefProfiles
- for _, profile := range profiles {
+ for i, profile := range profiles {
log.Debugf("createKongRoutes, AefId %s", profile.AefId)
- for _, version := range profile.Versions {
+ for j, version := range profile.Versions {
log.Debugf("createKongRoutes, apiVersion \"%s\"", version.ApiVersion)
- for _, resource := range *version.Resources {
- statusCode, err = sd.createKongRoute(kongControlPlaneURL, client, resource, apfId, profile.AefId, version.ApiVersion)
+ for k, resource := range *version.Resources {
+ statusCode, err = sd.createKongRoute(kongControlPlaneURL, client, &resource, apfId, profile.AefId, version.ApiVersion)
if (err != nil) || (statusCode != http.StatusCreated) {
return statusCode, err
}
+ (*profiles[i].Versions[j].Resources)[k] = resource
}
}
}
func (sd *ServiceAPIDescription) createKongRoute(
kongControlPlaneURL string,
client *resty.Client,
- resource Resource,
+ resource *Resource,
apfId string,
aefId string,
apiVersion string ) (int, error) {
log.Debugf("createKongRoute, routeName %s", routeName)
log.Debugf("createKongRoute, aefId %s", aefId)
- uri := buildUriWithVersion(apiVersion, resource.Uri)
+ uri := buildUri(apiVersion, resource.Uri)
log.Debugf("createKongRoute, uri %s", uri)
+ routeUri := buildUri(sd.ApiName, uri)
+ log.Debugf("createKongRoute, routeUri %s", routeUri)
+ resource.Uri = routeUri
+
statusCode, err := sd.createKongService(kongControlPlaneURL, serviceName, uri, tags)
if (err != nil) || (statusCode != http.StatusCreated) {
return statusCode, err
// Define the route information for Kong
kongRouteInfo := map[string]interface{}{
"name": routeName,
- "paths": []string{uri},
+ "paths": []string{routeUri},
"methods": resource.Operations,
"tags": tags,
"strip_path": true,
return resp.StatusCode(), nil
}
-func buildUriWithVersion(apiVersion string, uri string) string {
- if apiVersion != "" {
- if apiVersion[0] != '/' {
- apiVersion = "/" + apiVersion
+func buildUri(prependUri string, uri string) string {
+ if prependUri != "" {
+ if prependUri[0] != '/' {
+ prependUri = "/" + prependUri
}
- if apiVersion[len(apiVersion)-1] != '/' && uri[0] != '/' {
- apiVersion = apiVersion + "/"
+ if prependUri[len(prependUri)-1] != '/' && uri[0] != '/' {
+ prependUri = prependUri + "/"
}
- uri = apiVersion + uri
+ uri = prependUri + uri
}
return uri
}
}
// Update our exposures to point to Kong by replacing in incoming interface description with Kong interface descriptions.
-func (sd *ServiceAPIDescription) updateInterfaceDescription(kongIPv4 common29122.Ipv4Addr, kongDataPlanePort common29122.Port, kongDomain string) {
+func (sd *ServiceAPIDescription) updateInterfaceDescription(kongDataPlaneIPv4 common29122.Ipv4Addr, kongDataPlanePort common29122.Port, kongDomain string) {
log.Trace("updating InterfaceDescriptions")
+ log.Debugf("InterfaceDescriptions kongDataPlaneIPv4 %s", kongDataPlaneIPv4)
+
interfaceDesc := InterfaceDescription{
- Ipv4Addr: &kongIPv4,
+ Ipv4Addr: &kongDataPlaneIPv4,
Port: &kongDataPlanePort,
}
interfaceDescs := []InterfaceDescription{interfaceDesc}
}
}
-func (sd *ServiceAPIDescription) UnregisterKong(kongDomain string, kongProtocol string, kongIPv4 common29122.Ipv4Addr, kongDataPlanePort common29122.Port, kongControlPlanePort common29122.Port) (int, error) {
+func (sd *ServiceAPIDescription) UnregisterKong(kongDomain string, kongProtocol string, kongControlPlaneIPv4 common29122.Ipv4Addr, kongControlPlanePort common29122.Port) (int, error) {
log.Trace("entering UnregisterKong")
var (
statusCode int
err error
)
- kongControlPlaneURL := fmt.Sprintf("%s://%s:%d", kongProtocol, kongIPv4, kongControlPlanePort)
+ kongControlPlaneURL := fmt.Sprintf("%s://%s:%d", kongProtocol, kongControlPlaneIPv4, kongControlPlanePort)
statusCode, err = sd.deleteKongRoutes(kongControlPlaneURL)
if (err != nil) || (statusCode != http.StatusNoContent) {