Skip to content
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

update tagging and log clean up #4

Merged
merged 1 commit into from
Feb 5, 2021
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
14 changes: 7 additions & 7 deletions discovery/pkg/cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,13 +28,13 @@ func init() {
// Get the root command properties and bind the config property in YAML definition
rootProps := RootCmd.GetProperties()
rootProps.AddStringProperty("wso2.basepath", "https://localhost:9443/api/am/publisher/v1", "WS02 API Manger basepath")
rootProps.AddStringProperty("wso2.tokenEndpoint", "", "")
rootProps.AddStringProperty("wso2.username", "", "")
rootProps.AddStringProperty("wso2.password", "", "")
rootProps.AddStringProperty("wso2.clientId", "", "")
rootProps.AddStringProperty("wso2.clientSecret", "", "")
rootProps.AddStringProperty("wso2.tag", "ampc", "")
rootProps.AddStringProperty("wso2.scope", "", "")
rootProps.AddStringProperty("wso2.tokenEndpoint", "https://localhost:8243/token", "OAuth token endpoint")
rootProps.AddStringProperty("wso2.username", "", "API Manager username")
rootProps.AddStringProperty("wso2.password", "", "API Manager user's password")
rootProps.AddStringProperty("wso2.clientId", "", "DCR application client ID")
rootProps.AddStringProperty("wso2.clientSecret", "", "DCR application client secret")
rootProps.AddStringProperty("wso2.tag", "*", "publish APIs that only have this tag defaults to all APIs")
rootProps.AddStringProperty("wso2.scope", "apim:api_view", "")

}

Expand Down
31 changes: 27 additions & 4 deletions discovery/pkg/wso2/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import (
log "github.com/Axway/agent-sdk/pkg/util/log"
"github.com/Axway/agents-wso2/discovery/pkg/config"
"github.com/Axway/agents-wso2/discovery/pkg/wso2/models"
"github.com/sirupsen/logrus"
)

// NewGatewayClient - builds a new Client using the AgentConfig
Expand Down Expand Up @@ -70,7 +71,7 @@ func (c *GatewayClient) DiscoverAPIs() error {
log.Error("Failed to publish api " + apiDetails.Name)
continue
}
log.Info("Published API " + serviceBody.NameToPush + " to AMPLIFY Central")
log.Infof("Published API '%s' to AMPLIFY Central", serviceBody.NameToPush)
}

return err
Expand Down Expand Up @@ -134,7 +135,7 @@ func (c *GatewayClient) callAPI(endpoint string, method string, queryParams map[
}

log.Debugf("Status (%s) : %s", endpoint, strconv.Itoa(response.Code))
log.Debugf("Body: %s", string(response.Body))
log.Debugf("Response body: %s", string(response.Body))

return response, nil
}
Expand All @@ -150,6 +151,8 @@ func (c *GatewayClient) findAmplifyAPIs() (*models.APIList, error) {
}
r := &models.APIList{}
json.Unmarshal(resp.Body, &r)

log.Infof("Found %d API to be published to AMPLIFY Central", len(*r.List))
return r, nil
}

Expand Down Expand Up @@ -182,7 +185,9 @@ func (c *GatewayClient) getAPISpec(apiID string) ([]byte, error) {

b, err := json.Marshal(jsonMap)

log.Debugf("Swagger : %s", string(b))
if log.GetLevel() == logrus.DebugLevel {
log.Debugf("Swagger JSON : \n%+v", jsonMap)
}

return b, nil
}
Expand All @@ -196,12 +201,30 @@ func buildServiceBody(api *models.API, swaggerSpec []byte) (apic.ServiceBody, er
SetDescription(getDescription(api.Description)).
SetAPISpec(swaggerSpec).
SetVersion(api.Version).
SetAuthPolicy(apic.Passthrough).
SetAuthPolicy(getAuthPolicy(api)).
SetDocumentation([]byte("\"" + getDescription(api.Description) + "\"")).
SetResourceType(apic.Oas2).
Build()
}

func getAuthPolicy(api *models.API) string {
// WS02 Cloud returns only "apiSecurity"
if api.SecurityScheme == nil {
return apic.Oauth
}

for _, scheme := range *api.SecurityScheme {
switch scheme {
case "oauth2":
return apic.Oauth
case "api_key":
return apic.Apikey
}
}

return apic.Passthrough
}

func getDescription(description *string) string {
if description == nil {
return ""
Expand Down
5 changes: 2 additions & 3 deletions discovery/sample_apic_discovery_agent.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,8 @@ wso2:
# apim:ep_certificates_update apim:publisher_settings apim:pub_alert_manage apim:shared_scope_manage
# apim:app_import_export apim:api_import_export apim:api_product_import_export"
scope: "apim:api_view apim:subscription_view"
tags:
- ampc
- pizza
# by default all API
#tag: ampc
log:
level: info
format: json
Expand Down