Skip to content

Commit

Permalink
feat: introducing eventarc apihub reference
Browse files Browse the repository at this point in the history
  • Loading branch information
mat-613 committed May 23, 2023
1 parent 5325d3b commit 1705882
Show file tree
Hide file tree
Showing 10 changed files with 372 additions and 1 deletion.
1 change: 1 addition & 0 deletions CODEOWNERS
Validating CODEOWNERS rules …
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
/labs/bdd-proxy-development @markjkelly
/labs/best-practices-hackathon @sauliuz @seymen
/labs/idp-okta-integration @teodlh
/labs/eventarc-apihub @mat-613
/references/cicd-pipeline @danistrebel
/references/cicd-sharedflow-pipeline @ssvaidyanathan
/references/cloud-logging-shared-flow @danistrebel
Expand Down
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,8 @@ technical or non-technical topic.
deploying and testing a mock API, generated from an Open API Specification.
- [Identity facade with Okta](labs/idp-okta-integration) [(web)](https://apigee.github.io/devrel/labs/idp-okta-integration)
A 300 level lab that shows how to configure the Apigee Identity Facade with Okta IDP.

- [Eventarc + ApiHub integration](labs/eventarc-apihub) - A lab for
a workflow-based automation for Apigee X using API Hub and EventArc
## Contributing

See the [contributing instructions](./CONTRIBUTING.md) to get started.
Expand Down
1 change: 1 addition & 0 deletions labs/eventarc-apihub/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
eventarc-apihub
11 changes: 11 additions & 0 deletions labs/eventarc-apihub/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
# Eventarc Api Hub Lab

Use [claat](https://github.com/googlecodelabs/tools) to
generate static HTML site from the Markdown document.

go get github.com/googlecodelabs/tools/claat

claat export ./lab.md

This will create directory with static files. Serve it from any static file
webserver.
Binary file added labs/eventarc-apihub/assets/diagram.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
21 changes: 21 additions & 0 deletions labs/eventarc-apihub/cloud-builder/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# Copyright 2023 Google LLC
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
# http://www.apache.org/licenses/LICENSE-2.0
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

FROM debian:11

RUN apt update
RUN apt install nodejs npm -y
RUN npm install -g openapi2apigee
RUN apt install default-jre -y

COPY wsdl2apigee-1.0.0-jar-with-dependencies.jar .
ENTRYPOINT ["bash"]

194 changes: 194 additions & 0 deletions labs/eventarc-apihub/lab.md

Large diffs are not rendered by default.

17 changes: 17 additions & 0 deletions labs/eventarc-apihub/pipeline.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
#!/bin/sh
# Copyright 2023 Google LLC
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

# build labs
claat export ./lab.md
41 changes: 41 additions & 0 deletions labs/eventarc-apihub/workflows/apigee-notifydeployment-apihub.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
# Copyright 2023 Google LLC
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
# http://www.apache.org/licenses/LICENSE-2.0
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
main:
params: [input]
steps:
- init:
assign:
- project_id: ${sys.get_env("GOOGLE_CLOUD_PROJECT_ID")}
- getRevisionList:
call: http.get
args:
url: ${"https://apigeeregistry.googleapis.com/v1/projects/" + project_id + "/locations/global/apis/"+text.to_lower(input.data.protoPayload.response.apiProxy)+"/versions/"+"1"+"/specs"}
auth:
type: OAuth2
scopes: https://www.googleapis.com/auth/cloud-platform
result: revisionList
- callApiRegistry:
call: http.post
args:
url: ${"https://apigeeregistry.googleapis.com/v1/projects/" + project_id + "/locations/global/apis/" + text.to_lower(input.data.protoPayload.response.apiProxy) + "/deployments"}
auth:
type: OAuth2
scopes: https://www.googleapis.com/auth/cloud-platform
query:
apiDeploymentId: ${text.to_lower(input.data.protoPayload.response.apiProxy)+"-"+ input.data.protoPayload.response.revision +"-"+ text.substring(time.format(sys.now()), 0, 10)}
body:
labels:
apihub-gateway: apihub-google-cloud-apigee
displayName: ${input.data.protoPayload.response.environment}
apiSpecRevision: ${revisionList.body.apiSpecs[0].name+"@"+revisionList.body.apiSpecs[0].revisionId}
result: callApiRegistry
- returnOutput:
return: ${revisionList.body}
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
# Copyright 2023 Google LLC
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
# http://www.apache.org/licenses/LICENSE-2.0
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
main:
params: [input]
steps:
- init:
assign:
- project_id: ${sys.get_env("GOOGLE_CLOUD_PROJECT_ID")}
- location_id: "global"
- checkServiceTipe:
switch:
- condition: ${input.data.payload.mimeType == "application/x.openapi"}
steps:
- stepa:
assign:
- service_type: "rest"
- createBuildRest:
call: googleapis.cloudbuild.v1.projects.builds.create
args:
projectId: ${project_id}
parent: ${"projects/" + project_id + "/locations/" + location_id}
body:
steps:
- name: 'gcr.io/cloud-builders/gcloud'
script: '${"curl -H \"Authorization: Bearer "+ "\"$(gcloud auth print-access-token)\"\"" +" https://apigeeregistry.googleapis.com/v1/" + input.data.payload.name + ":getContents --output "+input.data.payload.filename}'
- name: ${"europe-docker.pkg.dev/"+project_id+"/builder/apigee-automation-builder"}
script: '${"openapi2apigee generateApi "+input.api+" -s "+ input.data.payload.filename +" -d . -O true -B /"+input.api+"/"+input.version}'#TODO add targetEndpoint??
- name: 'gcr.io/cloud-builders/gcloud'
script: '${"curl -X POST -H \"Authorization: Bearer "+ "\"$(gcloud auth print-access-token)\"\"" +" -F file=@" +input.api+"/"+ "apiproxy.zip \"https://apigee.googleapis.com/v1/organizations/" + project_id + "/apis?action=import&name="+input.api +"\"" }'
- condition: ${input.data.payload.mimeType == "application/wsdl+xml"}
steps:
- stepb:
assign:
- service_type: "soap"
- createBuildSoap:
switch:
- condition: ${text.split(input.data.payload.filename, ".")[1] != "zip"}
steps:
- createSoapPackageFromWsdl:
call: googleapis.cloudbuild.v1.projects.builds.create
args:
projectId: ${project_id}
parent: ${"projects/" + project_id + "/locations/" + location_id}
body:
steps:
- name: 'gcr.io/cloud-builders/gcloud'
script: '${"curl -H \"Authorization: Bearer "+ "\"$(gcloud auth print-access-token)\"\"" +" https://apigeeregistry.googleapis.com/v1/" + input.data.payload.name + ":getContents --output "+input.data.payload.filename}'
- name: ${"europe-docker.pkg.dev/"+project_id+"/builder/apigee-automation-builder"}
script: '${"java -jar wsdl2apigee-1.0.0-jar-with-dependencies.jar -wsdl="+ input.data.payload.filename + " -passthru=true -oauth=true -basepath=/"+input.api+"/"+input.version}'#TODO add targetEndpoint??
- name: 'bash'
script: 'mv *.zip package.zip'
- name: 'gcr.io/cloud-builders/gcloud'
script: '${"curl -X POST -H \"Authorization: Bearer "+ "\"$(gcloud auth print-access-token)\"\"" +" -F file=@package.zip \"https://apigee.googleapis.com/v1/organizations/" + project_id + "/apis?action=import&name="+input.api +"\"" }'
- condition: ${text.split(input.data.payload.filename, ".")[1] == "zip"}
steps:
- createSoapPackageFromZip:
call: googleapis.cloudbuild.v1.projects.builds.create
args:
projectId: ${project_id}
parent: ${"projects/" + project_id + "/locations/" + location_id}
body:
steps:
- name: 'gcr.io/cloud-builders/gcloud'
script: '${"curl -H \"Authorization: Bearer "+ "\"$(gcloud auth print-access-token)\"\"" +" https://apigeeregistry.googleapis.com/v1/" + input.data.payload.name + ":getContents --output "+input.data.payload.filename}'
- name: 'bash'
script: '${"unzip "+input.data.payload.filename +" -d ./"+ text.split(input.data.payload.filename, ".")[0]}'
- name: ${"europe-docker.pkg.dev/"+project_id+"/builder/apigee-automation-builder"}
script: '${"java -jar ../wsdl2apigee-1.0.0-jar-with-dependencies.jar -wsdl=./"+ text.split(input.data.payload.filename, ".")[0]+"/service.wsdl" + " -passthru=true -oauth=true -basepath=/"+input.api+"/"+input.version}' #TODO add targetEndpoint??
- name: 'bash'
script: '${"rm " + input.data.payload.filename}'
- name: 'bash'
script: 'mv *.zip package.zip'
- name: 'gcr.io/cloud-builders/gcloud'
script: '${"curl -X POST -H \"Authorization: Bearer "+ "\"$(gcloud auth print-access-token)\"\"" +" -F file=@package.zip \"https://apigee.googleapis.com/v1/organizations/" + project_id + "/apis?action=import&name="+input.api +"\"" }'
- returnOutput:
return: ${service_type}

0 comments on commit 1705882

Please sign in to comment.