Skip to content

Commit

Permalink
Merge pull request #19 from Axway/APIGOV-18542-2
Browse files Browse the repository at this point in the history
APIGOV 18542 - Discovery of Assets and Policy
  • Loading branch information
Atraya21 authored Apr 30, 2021
2 parents d8b295c + a44c9f7 commit 22e2581
Show file tree
Hide file tree
Showing 7 changed files with 279 additions and 100 deletions.
79 changes: 33 additions & 46 deletions default_mulesoft_discovery_agent.yml
Original file line number Diff line number Diff line change
@@ -1,55 +1,42 @@
mulesoft_traceability_agent:
central:
organizationID: "<Amplify_ORG_ID>"
environment: <Amplify_CENTRAL_ENVIRONMENT_NAME>
url: https://apicentral.axway.com
platformURL: https://platform.axway.com
auth:
clientID: <Amplify_CENTRAL_DOSA_CLIENT_ID>
privateKey: <Amplify_CENTRAL_DOSA_PRIVATE_KEY_PATH>
publicKey: <Amplify_CENTRAL_DOSA_PUBLIC_KEY_PATH>
realm: Broker
timeout: 10s
url: https://login.axway.com/auth

mulesoft:
environment: Sandbox
cachePath: "/tmp"
pollInterval: 30s
central:
organizationID: "<Amplify_ORG_ID>"
environment: <Amplify_CENTRAL_ENVIRONMENT_NAME>
mode: publishToEnvironmentAndCatalog
url: https://apicentral.axway.com
platformURL: https://platform.axway.com
pollInterval: 10s
auth:
username: <USERNAME>
password: <PASSWORD>

output.traceability:
enabled: true
hosts:
- ${TRACEABILITY_HOST:"ingestion-lumberjack.datasearch.axway.com:453"}
protocol: ${TRACEABILITY_PROTOCOL:"tcp"}
compression_level: ${TRACEABILITY_COMPRESSIONLEVEL:3}
ssl:
enabled: true
verification_mode: none
cipher_suites:
- "ECDHE-ECDSA-AES-128-GCM-SHA256"
- "ECDHE-ECDSA-AES-256-GCM-SHA384"
- "ECDHE-ECDSA-CHACHA20-POLY1305"
- "ECDHE-RSA-AES-128-CBC-SHA256"
- "ECDHE-RSA-AES-128-GCM-SHA256"
- "ECDHE-RSA-AES-256-GCM-SHA384"
- "ECDHE-RSA-CHACHA20-POLY1205"
worker: 1
pipelining: 0
proxy_url: ${TRACEABILITY_PROXYURL:""}
clientID: <Amplify_CENTRAL_DOSA_CLIENT_ID>
privateKey: <Amplify_CENTRAL_DOSA_PRIVATE_KEY_PATH>
publicKey: <Amplify_CENTRAL_DOSA_PUBLIC_KEY_PATH>
realm: Broker
timeout: 30s
url: https://login.axway.com/auth
# Uncomment the following line if you are using a proxy to access the Amplify platform (apicentral.axway.com / login.axway.com / platform.axway.com) on port 443
# Configure the appropriate value (PROXY_USER / PROXY_PASSWORD are optional values)
#proxyurl: <PROXY_SCHEME>://<PROXY_USER>:<PROXY_USER_PASSWORD>@<PROXY_URL>:<PROXY_PORT>

log:
level: debug
format: json
output: stdout
path: logs

logging:
metrics:
enabled: false
to_stderr: true
level: ${LOG_LEVEL:debug}
mulesoft:
anypointExchangeUrl: https://anypoint.mulesoft.com
environment: Sandbox
pollInterval: 20s
auth:
username: <USERNAME>
password: <PASSWORD>
# The following property is used to filter the APIs that have a particular tag in their configuration.
# Comma-separated list of tags. Only APIs that have one or more of these tags are considered for discovery.
# Default value: empty. Meaning that no matching is performed.
#discoveryTags: tags1, tags2
#
# The following property is used to filter out APIs that have a particular tag in their configuration.
# Comma-separated list of tags. If an API has one or more of these tags, the agent ignores this API and will not publish it to Amplify Central.
# This property takes precedence over the discoveryTags property/
# Default value: empty. Meaning that no API is ignored
#discoveryIgnoreTags: tags1, tags2

79 changes: 46 additions & 33 deletions default_mulesoft_traceability_agent.yml
Original file line number Diff line number Diff line change
@@ -1,42 +1,55 @@
central:
organizationID: "<Amplify_ORG_ID>"
environment: <Amplify_CENTRAL_ENVIRONMENT_NAME>
mode: publishToEnvironmentAndCatalog
url: https://apicentral.axway.com
platformURL: https://platform.axway.com
pollInterval: 10s
mulesoft_traceability_agent:
central:
organizationID: "<Amplify_ORG_ID>"
environment: <Amplify_CENTRAL_ENVIRONMENT_NAME>
url: https://apicentral.axway.com
platformURL: https://platform.axway.com
auth:
clientID: <Amplify_CENTRAL_DOSA_CLIENT_ID>
privateKey: <Amplify_CENTRAL_DOSA_PRIVATE_KEY_PATH>
publicKey: <Amplify_CENTRAL_DOSA_PUBLIC_KEY_PATH>
realm: Broker
timeout: 10s
url: https://login.axway.com/auth

mulesoft:
environment: Sandbox
cachePath: "/tmp"
pollInterval: 30s
auth:
clientID: <Amplify_CENTRAL_DOSA_CLIENT_ID>
privateKey: <Amplify_CENTRAL_DOSA_PRIVATE_KEY_PATH>
publicKey: <Amplify_CENTRAL_DOSA_PUBLIC_KEY_PATH>
realm: Broker
timeout: 30s
url: https://login.axway.com/auth
# Uncomment the following line if you are using a proxy to access the Amplify platform (apicentral.axway.com / login.axway.com / platform.axway.com) on port 443
# Configure the appropriate value (PROXY_USER / PROXY_PASSWORD are optional values)
#proxyurl: <PROXY_SCHEME>://<PROXY_USER>:<PROXY_USER_PASSWORD>@<PROXY_URL>:<PROXY_PORT>
username: <USERNAME>
password: <PASSWORD>

output.traceability:
enabled: true
hosts:
- ${TRACEABILITY_HOST:"ingestion-lumberjack.datasearch.axway.com:453"}
protocol: ${TRACEABILITY_PROTOCOL:"tcp"}
compression_level: ${TRACEABILITY_COMPRESSIONLEVEL:3}
ssl:
enabled: true
verification_mode: none
cipher_suites:
- "ECDHE-ECDSA-AES-128-GCM-SHA256"
- "ECDHE-ECDSA-AES-256-GCM-SHA384"
- "ECDHE-ECDSA-CHACHA20-POLY1305"
- "ECDHE-RSA-AES-128-CBC-SHA256"
- "ECDHE-RSA-AES-128-GCM-SHA256"
- "ECDHE-RSA-AES-256-GCM-SHA384"
- "ECDHE-RSA-CHACHA20-POLY1205"
worker: 1
pipelining: 0
proxy_url: ${TRACEABILITY_PROXYURL:""}

log:
level: debug
format: json
output: stdout
path: logs

mulesoft:
anypointExchangeUrl: https://anypoint.mulesoft.com
environment: Sandbox
pollInterval: 20s
auth:
username: <USERNAME>
password: <PASSWORD>
# The following property is used to filter the APIs that have a particular tag in their configuration.
# Comma-separated list of tags. Only APIs that have one or more of these tags are considered for discovery.
# Default value: empty. Meaning that no matching is performed.
#discoveryTags: tags1, tags2
#
# The following property is used to filter out APIs that have a particular tag in their configuration.
# Comma-separated list of tags. If an API has one or more of these tags, the agent ignores this API and will not publish it to Amplify Central.
# This property takes precedence over the discoveryTags property/
# Default value: empty. Meaning that no API is ignored
#discoveryIgnoreTags: tags1, tags2
logging:
metrics:
enabled: false
to_stderr: true
level: ${LOG_LEVEL:debug}

4 changes: 3 additions & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,14 @@ go 1.13

require (
github.com/Axway/agent-sdk v1.0.20210421
github.com/Axway/agents-mulesoft/mulesoft_discovery_agent v0.0.0-20210423202411-12425c6347de
github.com/Shopify/sarama v1.26.4 // indirect
github.com/docker/docker v1.13.1 // indirect
github.com/dustin/go-humanize v1.0.0 // indirect
github.com/eapache/go-resiliency v1.2.0 // indirect
github.com/elastic/beats/v7 v7.7.1
github.com/garyburd/redigo v1.6.0 // indirect
github.com/getkin/kin-openapi v0.53.0
github.com/go-openapi/spec v0.0.0-20160808142527-6aced65f8501
github.com/googleapis/gnostic v0.3.1 // indirect
github.com/hashicorp/golang-lru v0.5.4 // indirect
github.com/imdario/mergo v0.3.9 // indirect
Expand All @@ -25,6 +26,7 @@ require (
github.com/spf13/afero v1.3.0 // indirect
github.com/spf13/cast v1.3.1 // indirect
github.com/stretchr/testify v1.6.1
golang.org/x/sys v0.0.0-20210119212857-b64e53b001e4 // indirect
gopkg.in/ini.v1 v1.57.0 // indirect
gopkg.in/jcmturner/gokrb5.v7 v7.5.0 // indirect
gopkg.in/yaml.v2 v2.4.0
Expand Down
11 changes: 9 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,6 @@ code.cloudfoundry.org/rfc5424 v0.0.0-20180905210152-236a6d29298a/go.mod h1:tkZo8
dmitri.shuralyov.com/gpu/mtl v0.0.0-20190408044501-666a987793e9/go.mod h1:H6x//7gZCb22OMCxBHrMx7a5I7Hp++hsVxbQ4BYO7hU=
github.com/Axway/agent-sdk v1.0.20210421 h1:sZBM0OPMlpRwkf1y6jRSEsEC3cFT5eds6hoE6usKvfE=
github.com/Axway/agent-sdk v1.0.20210421/go.mod h1:ESIGxeiVC5Cza+MYgj5yGePQNjkT8diz4HxkQBCHwFk=
github.com/Axway/agents-mulesoft/mulesoft_discovery_agent v0.0.0-20210423202411-12425c6347de h1:UNihpBehBrAy/fKuAxuADJvXj9kE1wlxI7st9MbtmiY=
github.com/Axway/agents-mulesoft/mulesoft_discovery_agent v0.0.0-20210423202411-12425c6347de/go.mod h1:J+6SAOGqDXv21b01Eo9BboUCs/lpzWEworrLf6tCrk4=
github.com/Azure/azure-amqp-common-go/v3 v3.0.0/go.mod h1:SY08giD/XbhTz07tJdpw1SoxQXHPN30+DI3Z04SYqyg=
github.com/Azure/azure-event-hubs-go/v3 v3.1.2/go.mod h1:hR40byNJjKkS74+3RhloPQ8sJ8zFQeJ920Uk3oYY0+k=
github.com/Azure/azure-pipeline-go v0.1.8/go.mod h1:XA1kFWRVhSK+KNFiOhfv83Fv8L9achrP7OxIzeTn1Yg=
Expand Down Expand Up @@ -231,6 +229,8 @@ github.com/garyburd/redigo v1.6.0 h1:0VruCpn7yAIIu7pWVClQC8wxCJEcG3nyzpMSHKi1PQc
github.com/garyburd/redigo v1.6.0/go.mod h1:NR3MbYisc3/PwhQ00EMzDiPmrwpPxAn5GI05/YaO1SY=
github.com/getkin/kin-openapi v0.9.0 h1:/vaUQkiOR+vfFO3oilZentZTfAhz7OzXPhLdNas4q4w=
github.com/getkin/kin-openapi v0.9.0/go.mod h1:zZQMFkVgRHCdhgb6ihCTIo9dyDZFvX0k/xAKqw1FhPw=
github.com/getkin/kin-openapi v0.53.0 h1:7WzP+MZRRe7YQz2Kc74Ley3dukJmXDvifVbElGmQfoA=
github.com/getkin/kin-openapi v0.53.0/go.mod h1:7Yn5whZr5kJi6t+kShccXS8ae1APpYTW6yheSwk8Yi4=
github.com/ghodss/yaml v0.0.0-20150909031657-73d445a93680/go.mod h1:4dBDuWmgqj2HViK6kFavaiC9ZROes6MMH2rRYeMEF04=
github.com/ghodss/yaml v1.0.0 h1:wQHKEahhL6wmXdzwWG11gIVCkOv05bNOh+Rxn0yngAk=
github.com/ghodss/yaml v1.0.0/go.mod h1:4dBDuWmgqj2HViK6kFavaiC9ZROes6MMH2rRYeMEF04=
Expand All @@ -245,12 +245,16 @@ github.com/go-martini/martini v0.0.0-20170121215854-22fa46961aab/go.mod h1:/P9AE
github.com/go-ole/go-ole v1.2.5-0.20190920104607-14974a1cf647/go.mod h1:pprOEPIfldk/42T2oK7lQ4v4JSDwmV0As9GaiUsvbm0=
github.com/go-openapi/jsonpointer v0.0.0-20160704185906-46af16f9f7b1 h1:wSt/4CYxs70xbATrGXhokKF1i0tZjENLOo1ioIO13zk=
github.com/go-openapi/jsonpointer v0.0.0-20160704185906-46af16f9f7b1/go.mod h1:+35s3my2LFTysnkMfxsJBAMHj/DoqoB9knIWoYG/Vk0=
github.com/go-openapi/jsonpointer v0.19.5 h1:gZr+CIYByUqjcgeLXnQu2gHYQC9o73G2XUeOFYEICuY=
github.com/go-openapi/jsonpointer v0.19.5/go.mod h1:Pl9vOtqEWErmShwVjC8pYs9cog34VGT37dQOVbmoatg=
github.com/go-openapi/jsonreference v0.0.0-20160704190145-13c6e3589ad9 h1:tF+augKRWlWx0J0B7ZyyKSiTyV6E1zZe+7b3qQlcEf8=
github.com/go-openapi/jsonreference v0.0.0-20160704190145-13c6e3589ad9/go.mod h1:W3Z9FmVs9qj+KR4zFKmDPGiLdk1D9Rlm7cyMvf57TTg=
github.com/go-openapi/spec v0.0.0-20160808142527-6aced65f8501 h1:C1JKChikHGpXwT5UQDFaryIpDtyyGL/CR6C2kB7F1oc=
github.com/go-openapi/spec v0.0.0-20160808142527-6aced65f8501/go.mod h1:J8+jY1nAiCcj+friV/PDoE1/3eeccG9LYBs0tYvLOWc=
github.com/go-openapi/swag v0.0.0-20160704191624-1d0bd113de87 h1:zP3nY8Tk2E6RTkqGYrarZXuzh+ffyLDljLxCy1iJw80=
github.com/go-openapi/swag v0.0.0-20160704191624-1d0bd113de87/go.mod h1:DXUve3Dpr1UfpPtxFw+EFuQ41HhCWZfha5jSVRG7C7I=
github.com/go-openapi/swag v0.19.5 h1:lTz6Ys4CmqqCQmZPBlbQENR1/GucA2bzYTE12Pw4tFY=
github.com/go-openapi/swag v0.19.5/go.mod h1:POnQmlKehdgb5mhVOsnJFsivZCEZ/vjK9gh66Z9tfKk=
github.com/go-sourcemap/sourcemap v2.1.2+incompatible h1:0b/xya7BKGhXuqFESKM4oIiRo9WOt2ebz7KxfreD6ug=
github.com/go-sourcemap/sourcemap v2.1.2+incompatible/go.mod h1:F8jJfvm2KbVjc5NqelyYJmf/v5J0dwNLS2mL4sNA1Jg=
github.com/go-sql-driver/mysql v1.4.0/go.mod h1:zAC/RDZ24gD3HViQzih4MyKcchzm+sOG5ZlKdlhCg5w=
Expand Down Expand Up @@ -326,6 +330,7 @@ github.com/gorhill/cronexpr v0.0.0-20180427100037-88b0669f7d75 h1:f0n1xnMSmBLzVf
github.com/gorhill/cronexpr v0.0.0-20180427100037-88b0669f7d75/go.mod h1:g2644b03hfBX9Ov0ZBDgXXens4rxSxmqFBbhvKv2yVA=
github.com/gorilla/mux v1.7.2 h1:zoNxOV7WjqXptQOVngLmcSQgXmgk4NMz1HibBchjl/I=
github.com/gorilla/mux v1.7.2/go.mod h1:1lud6UwP+6orDFRuTfBEV8e9/aOM/c4fVVCaMa2zaAs=
github.com/gorilla/mux v1.8.0/go.mod h1:DVbg23sWSpFRCP0SfiEN6jmj59UnW/n46BH5rLB71So=
github.com/gorilla/websocket v1.4.0/go.mod h1:E7qHFY5m1UJ88s3WnNqhKjPHQ0heANvMoAMk2YaljkQ=
github.com/gorilla/websocket v1.4.1/go.mod h1:YR8l580nyteQvAITg2hZ9XVh4b55+EU/adAjf1fMHhE=
github.com/gorilla/websocket v1.4.2/go.mod h1:YR8l580nyteQvAITg2hZ9XVh4b55+EU/adAjf1fMHhE=
Expand Down Expand Up @@ -427,6 +432,8 @@ github.com/magiconair/properties v1.8.0/go.mod h1:PppfXfuXeibc/6YijjN8zIbojt8czP
github.com/magiconair/properties v1.8.1 h1:ZC2Vc7/ZFkGmsVC9KvOjumD+G5lXy2RtTKyzRKO2BQ4=
github.com/magiconair/properties v1.8.1/go.mod h1:PppfXfuXeibc/6YijjN8zIbojt8czPbwD3XqdrwzmxQ=
github.com/mailru/easyjson v0.0.0-20160728113105-d5b7844b561a/go.mod h1:C1wdFJiN94OJF2b5HbByQZoLdCWB1Yqtg26g4irojpc=
github.com/mailru/easyjson v0.0.0-20190614124828-94de47d64c63/go.mod h1:C1wdFJiN94OJF2b5HbByQZoLdCWB1Yqtg26g4irojpc=
github.com/mailru/easyjson v0.0.0-20190626092158-b2ccc519800e/go.mod h1:C1wdFJiN94OJF2b5HbByQZoLdCWB1Yqtg26g4irojpc=
github.com/mailru/easyjson v0.7.1 h1:mdxE1MF9o53iCb2Ghj1VfWvh7ZOwHpnVG/xwXrV90U8=
github.com/mailru/easyjson v0.7.1/go.mod h1:KAzv3t3aY1NaHWoQz1+4F1ccyAH66Jk7yos7ldAVICs=
github.com/martini-contrib/render v0.0.0-20150707142108-ec18f8345a11/go.mod h1:Ah2dBMoxZEqk118as2T4u4fjfXarE0pPnMJaArZQZsI=
Expand Down
13 changes: 9 additions & 4 deletions pkg/anypoint/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ type Client interface {
GetAccessToken() (string, *User, time.Duration, error)
GetEnvironmentByName(name string) (*Environment, error)
ListAssets(page *Page) ([]Asset, error)
GetPolicies(api *API) ([]Policy, error)
GetPolicies(api *API) (Policies, error)
GetExchangeAsset(api *API) (*ExchangeAsset, error)
GetExchangeAssetIcon(asset *ExchangeAsset) (icon string, contentType string, err error)
GetExchangeFileContent(file *ExchangeFile) (fileContent []byte, err error)
Expand Down Expand Up @@ -249,13 +249,13 @@ func (c *AnypointClient) ListAssets(page *Page) ([]Asset, error) {
}

// GetPolicies lists the API policies.
func (c *AnypointClient) GetPolicies(api *API) ([]Policy, error) {
var policies []Policy
func (c *AnypointClient) GetPolicies(api *API) (Policies, error) {
var policies Policies
url := fmt.Sprintf("%s/apimanager/api/v1/organizations/%s/environments/%s/apis/%d/policies", c.baseURL, c.auth.GetOrgID(), c.environment.ID, api.ID)
err := c.invokeJSONGet(url, nil, &policies)

if err != nil {
return nil, err
return Policies{}, err
}

return policies, err
Expand Down Expand Up @@ -388,6 +388,11 @@ func (c *AnypointClient) invokeJSON(request coreapi.Request, resp interface{}) e
return agenterrors.Wrap(ErrCommunicatingWithGateway, err.Error())
}

//TODO this is to prevent Mule 3 APIs with no policies crashing the discovery agent -> need to verify if still required
if string(body) == "[]" {
return nil
}

err = json.Unmarshal(body, resp)
if err != nil {
return agenterrors.Wrap(ErrMarshallingBody, err.Error())
Expand Down
25 changes: 19 additions & 6 deletions pkg/anypoint/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -92,16 +92,29 @@ type API struct {

// Policy -
type Policy struct {
APIID int64 `json:"apiId"`
AssetID string `json:"assetId"`
AssetVersion string `json:"assetVersion"`
Audit Audit `json:"audit"`
ConfigurationData map[string]interface{} `json:"configurationData"`
GroupID string `json:"groupId"`
ID int64 `json:"id"`
Type string `json:"type"`
Order int `json:"order"`
PointCutData interface{} `json:"pointCutData"`
PolicyID int `json:"policyId"`
Version int64 `json:"version"`
MasterOrganizationID string `json:"masterOrganizationId"`
OrganizationID string `json:"organizationId"`
ID int64 `json:"id"`
Template Template `json:"template"`
APIID int64 `json:"apiId"`
PolicyTemplateID string `json:"policyTemplateId"`
Configuration map[string]interface{} `json:"configuration"`
}

type Template struct {
GroupId string `json:"groupId"`
AssetId string `json:"assetId"`
Assetversion string `json:"assetVersion"`
}

type Policies struct {
Policies []Policy `json:"policies"`
}

// Audit -
Expand Down
Loading

0 comments on commit 22e2581

Please sign in to comment.