├── .DS_Store ├── .github ├── ISSUE_TEMPLATE │ ├── bug_report.md │ ├── documentation.md │ ├── feature_request.md │ └── question.md ├── PULL_REQUEST_TEMPLATE.md ├── config.yml ├── label-commenter-config.yml ├── release-drafter.yml ├── stale.yml ├── welcome │ └── Layer5-celebration.png └── workflows │ ├── ci.yml │ ├── label-commenter.yml │ ├── release-drafter.yml │ └── slack.yml ├── .gitignore ├── LICENSE ├── Makefile ├── README.md ├── api ├── Dockerfile ├── go.mod └── main.go ├── config ├── consul-values.yaml └── image-hub.yaml ├── deployment.yaml ├── docker-compose.yaml ├── docs └── assets │ └── img │ └── readme │ └── docker-con-2020.png ├── envoy.Dockerfile ├── envoy.yaml ├── gateway.yaml ├── img └── readme │ ├── community.svg │ ├── image-hub-on-consul-with-wasm-and-meshery.png │ ├── layer5-image-hub.svg │ ├── service-mesh-architecture-consul.png │ ├── slack-128.png │ └── slack-dark-128.png ├── rate-limit-filter ├── .dockerignore ├── Cargo.toml ├── Dockerfile ├── README.md ├── envoy ├── pkg │ └── rate_limit_filter_bg.wasm └── src │ ├── json_parse │ ├── mod.rs │ └── rules.rs │ ├── lib.rs │ └── rate_limiter │ ├── mod.rs │ └── rate_limiter.rs └── web ├── .gitignore ├── Dockerfile ├── README.md ├── babel.config.js ├── package.json ├── public ├── favicon.ico └── index.html ├── src ├── App.vue ├── assets │ ├── layer5-image-hub-white.ai │ ├── layer5-image-hub-white.svg │ ├── layer5-image-hub.ai │ └── layer5-image-hub.svg ├── main.js ├── plugins │ └── vuetify.js ├── router │ └── index.js └── views │ ├── Auth.vue │ ├── Hello.vue │ ├── Signup.vue │ └── Upgrade.vue ├── vue.config.js └── yarn.lock /.DS_Store: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/layer5io/image-hub/626ca0c1782cdb9cd5c07ba2cfe7af33da668812/.DS_Store -------------------------------------------------------------------------------- /.github/ISSUE_TEMPLATE/bug_report.md: -------------------------------------------------------------------------------- 1 | --- 2 | name: Bug/issue report 3 | about: Report an issue to help improve the project. 4 | title: '' 5 | labels: 'bug' 6 | assignees: '' 7 | --- 8 | **Description** 9 | 10 | 11 | **Expected Behavior** 12 | 13 | 14 | **Screenshots** 15 | 16 | 17 | **Environment:** 18 | - OS: [e.g. Ubuntu] 19 | - Browser: [e.g. Chrome, Safari] 20 | - Version: [e.g. 22] 21 | - Device: [e.g. laptop, iPhone 8] 22 | 23 | --- 24 | [Optional] **To Reproduce** 25 | Steps to reproduce the behavior: 26 | 1. Go to '...' 27 | 2. Click on '....' 28 | 3. Scroll down to '....' 29 | 4. See error 30 | 31 | [Optional] **Additional Context** 32 | 33 | - 🎨 Wireframes and [designs for Layer5 site](https://www.figma.com/file/5ZwEkSJwUPitURD59YHMEN/Layer5-Designs) in Figma [(open invite)](https://www.figma.com/team_invite/redeem/qJy1c95qirjgWQODApilR9) 34 | -------------------------------------------------------------------------------- /.github/ISSUE_TEMPLATE/documentation.md: -------------------------------------------------------------------------------- 1 | --- 2 | name: Documentation issue 3 | about: Issues related to documentation. 4 | title: '[Docs]' 5 | labels: 'docs' 6 | assignees: '' 7 | --- 8 | **Current State:** 9 | 10 | 11 | **Desired State:** 12 | 13 | 14 | --- 15 | **Contributor Resources** 16 | - [Meshery documentation site](https://meshery.layer5.io/docs/) 17 | - [Meshery documentation source](https://github.com/layer5io/meshery/tree/master/docs) 18 | - [Instructions for contributing to documentation](https://github.com/layer5io/meshery/blob/master/CONTRIBUTING.md#documentation-contribution-flow) 19 | - 🎨 Wireframes and [designs for Layer5 site](https://www.figma.com/file/5ZwEkSJwUPitURD59YHMEN/Layer5-Designs) in Figma [(open invite)](https://www.figma.com/team_invite/redeem/qJy1c95qirjgWQODApilR9) 20 | -------------------------------------------------------------------------------- /.github/ISSUE_TEMPLATE/feature_request.md: -------------------------------------------------------------------------------- 1 | --- 2 | name: Feature Request 3 | about: Suggest an enhancement to this project. 4 | title: '' 5 | labels: 'enhancement' 6 | assignees: '' 7 | --- 8 | 9 | **Current Behavior** 10 | 11 | 12 | 13 | **Desired Behavior** 14 | 15 | 16 | 17 | --- 18 | **Resources** 19 | 20 | - 🎨 Wireframes and [designs for Layer5 site](https://www.figma.com/file/5ZwEkSJwUPitURD59YHMEN/Layer5-Designs) in Figma [(open invite)](https://www.figma.com/team_invite/redeem/qJy1c95qirjgWQODApilR9) 21 | 22 | **Alternatives / Additional Context** 23 | 24 | -------------------------------------------------------------------------------- /.github/ISSUE_TEMPLATE/question.md: -------------------------------------------------------------------------------- 1 | --- 2 | name: General question 3 | about: Request information about the project; clarify behavior of the software 4 | title: '[Question]' 5 | labels: 'question' 6 | assignees: '' 7 | --- 8 | 9 | **How can we help?** 10 | 11 | **Resources** 12 | - 🎨 Wireframes and [designs for Layer5 site](https://www.figma.com/file/5ZwEkSJwUPitURD59YHMEN/Layer5-Designs) in Figma [(open invite)](https://www.figma.com/team_invite/redeem/qJy1c95qirjgWQODApilR9) 13 | -------------------------------------------------------------------------------- /.github/PULL_REQUEST_TEMPLATE.md: -------------------------------------------------------------------------------- 1 | 30 | **Description** 31 | 32 | 33 | This PR fixes # 34 | 35 | **Notes to reviewers** 36 | 37 | #### Checklist 38 | 39 | - [] [Signed commits](https://github.com/layer5io/meshery/blob/master/CONTRIBUTING.md#signing-off-on-commits-developer-certificate-of-origin). 40 | - [] PR title includes `[]:` 41 | -------------------------------------------------------------------------------- /.github/config.yml: -------------------------------------------------------------------------------- 1 | --- 2 | #------------------------------------------------------------------------------- 3 | # Configuration for new-issue-welcome - https://github.com/behaviorbot/new-issue-welcome 4 | # Comment to be posted to on first time issues 5 | newIssueWelcomeComment: > 6 | Thanks for opening this issue. A contributor will be by to give feedback soon. In the meantime, please review the [Layer5 Contributors' Welcome Guide](https://docs.google.com/document/d/17OPtDE_rdnPQxmk2Kauhm3GwXF1R5dZ3Cj8qZLKdo5E/edit?usp=sharing) and sure to join the [community Slack](http://slack.layer5.io/). 7 | # Configuration for new-pr-welcome - https://github.com/behaviorbot/new-pr-welcome 8 | # Comment to be posted to on PRs from first time contributors in your repository 9 | newPRWelcomeComment: > 10 | Yay, your first pull request! :thumbsup: A contributor will be by to give feedback soon. In the meantime, please review the [Layer5 Contributors' Welcome Guide](https://docs.google.com/document/d/17OPtDE_rdnPQxmk2Kauhm3GwXF1R5dZ3Cj8qZLKdo5E/edit?usp=sharing) and sure to join the [community Slack](http://slack.layer5.io/). 11 | 12 | Be sure to double-check that you have signed your commits. Here are instructions for [making signing an implicit activity while peforming a commit](https://github.com/layer5io/meshery/blob/master/CONTRIBUTING.md#signing-off-on-commits-developer-certificate-of-origin). 13 | 14 | #------------------------------------------------------------------------------- 15 | # Configuration for first-pr-merge - https://github.com/behaviorbot/first-pr-merge 16 | # Comment to be posted to on pull requests merged by a first time user 17 | firstPRMergeComment: > 18 | Thanks for your contribution to the Layer5 community! :tada: 19 | 20 | ![Congrats!](https://raw.githubusercontent.com/layer5io/meshery/master/.github/welcome/Layer5-celebration.png) 21 | 22 |         :star: Please [star the project](../stargazers) if you are yet to do so. 23 | #------------------------------------------------------------------------------- 24 | # Configuration for request-info - https://github.com/behaviorbot/request-info 25 | # Comment to reply with 26 | requestInfoReplyComment: > 27 | Thanks for opening this issue. We welcome all input! If you could provide a little more information, this will greatly aide in its resolution. :thumbsup: 28 | # *OPTIONAL* Add a list of people whose Issues/PRs will not be commented on 29 | # keys must be GitHub usernames 30 | #requestInfoUserstoExclude: 31 | # - layer5io/maintainers 32 | 33 | #------------------------------------------------------------------------------- 34 | # Configuration for sentiment-bot - https://github.com/behaviorbot/sentiment-bot 35 | # *Required* toxicity threshold between 0 and .99 with the higher numbers being the most toxic 36 | # Anything higher than this threshold will be marked as toxic and commented on 37 | sentimentBotToxicityThreshold: .9 38 | 39 | # *Required* Comment to reply with 40 | sentimentBotReplyComment: > 41 | Please be sure to review the code of conduct and be respectful of other users. // @layer5io/maintainers 42 | 43 | #------------------------------------------------------------------------------------ 44 | # *Required* Star the project 45 | # Staring the project is as important as contributing to it. 46 | 47 | -------------------------------------------------------------------------------- /.github/label-commenter-config.yml: -------------------------------------------------------------------------------- 1 | comment: 2 | footer: "\ 3 | ---\n\n 4 | >         Be sure to [join the community](http://slack.layer5.io), if you haven't yet and please leave a :star: [star on the project](../stargazers) :smile: on the project. 5 | " 6 | 7 | labels: 8 | - name: issue/design required 9 | labeled: 10 | issue: 11 | body: This issue has been labeled with 'design-required'. Note that prior to commencing on implementation, a design specification needs to be created and reviewed for approval. See [Creating a Functional Specification](https://docs.google.com/document/d/1RP3IWLc-MiQS-QYasqCoVuCH7--G87p5ezE5f_nOzB8/edit?usp=sharing) to create a design spec. 12 | action: open 13 | - name: issue/remind 14 | labeled: 15 | issue: 16 | body: Checking in... it has been awhile since we've heard from you on this issue. Are you still working on it? Please let us know and please don't hesitate to contact a [MeshMate](https://layer5.io/community/meshmates/) or any other [community member](https://layer5.io/community/members) for assistance. 17 | action: open 18 | pr: 19 | body: Checking in... it has been awhile since we've heard from you on this issue. Are you still working on it? Please let us know and please don't hesitate to contact a [MeshMate](https://layer5.io/community/meshmates/) or any other [community member](https://layer5.io/community/members) for assistance. 20 | action: open 21 | - name: issue/dco 22 | labeled: 23 | pr: 24 | body: "🚨 Alert! Git Police! We couldn’t help but notice that one or more of your commits is missing a sign-off. _A what?_ A commit sign-off (your email address).\n\n 25 | To amend the commits in this PR with your signoff using the instructions provided in the DCO check above. \n\n 26 | To configure your dev environment to automatically signoff on your commits in the future, see [these instructions](https://github.com/meshery/meshery/blob/master/CONTRIBUTING.md#signing-off-on-commits-developer-certificate-of-origin)." 27 | action: open -------------------------------------------------------------------------------- /.github/release-drafter.yml: -------------------------------------------------------------------------------- 1 | name-template: 'v$NEXT_PATCH_VERSION' 2 | tag-template: 'v$NEXT_PATCH_VERSION' 3 | categories: 4 | - title: '🚀 Features' 5 | labels: 6 | - 'kind/feature' 7 | - 'kind/enhancement' 8 | - title: '🐛 Bug Fixes' 9 | labels: 10 | - 'kind/fix' 11 | - 'kind/bugfix' 12 | - 'kind/bug' 13 | - title: '🧰 Maintenance' 14 | labels: 15 | - 'kind/chore' 16 | - 'area/ci' 17 | - 'area/tests' 18 | - title: 📖 Documentation 19 | label: area/docs 20 | change-template: '- $TITLE @$AUTHOR (#$NUMBER)' 21 | template: | 22 | ## What's new ? 23 | $CHANGES 24 | 25 | ## Contributors 26 | 27 | Thanks a lot to our contributors for making this release possible: 28 | $CONTRIBUTORS 29 | -------------------------------------------------------------------------------- /.github/stale.yml: -------------------------------------------------------------------------------- 1 | # Number of days of inactivity before an issue becomes stale 2 | daysUntilStale: 30 3 | # Number of days of inactivity before a stale issue is closed 4 | daysUntilClose: 14 5 | # Issues with these labels will never be considered stale 6 | exemptLabels: 7 | - lifecycle/frozen 8 | # Label to use when marking an issue as stale 9 | staleLabel: lifecycle/stale 10 | # Comment to post when marking an issue as stale. Set to `false` to disable 11 | markComment: > 12 | This issue has been automatically marked as stale because it has not had 13 | recent activity. It will be closed if no further activity occurs. Thank you 14 | for your contributions. 15 | # Comment to post when closing a stale issue. Set to `false` to disable 16 | closeComment: > 17 | This issue is being automatically closed due to inactivity. -------------------------------------------------------------------------------- /.github/welcome/Layer5-celebration.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/layer5io/image-hub/626ca0c1782cdb9cd5c07ba2cfe7af33da668812/.github/welcome/Layer5-celebration.png -------------------------------------------------------------------------------- /.github/workflows/ci.yml: -------------------------------------------------------------------------------- 1 | name: Image Hub 2 | on: 3 | push: 4 | branches: 5 | - '*' 6 | tags: 7 | - 'v*' 8 | pull_request: 9 | branches: 10 | - master 11 | 12 | jobs: 13 | docker: 14 | name: Docker build and push 15 | runs-on: ubuntu-latest 16 | steps: 17 | - name: Check out code 18 | if: github.event_name != 'pull_request' && (startsWith(github.ref, 'refs/tags/') || github.ref == 'refs/heads/master') && success() 19 | uses: actions/checkout@master 20 | with: 21 | fetch-depth: 1 22 | - name: Docker login 23 | if: github.event_name != 'pull_request' && (startsWith(github.ref, 'refs/tags/') || github.ref == 'refs/heads/master') && success() 24 | uses: azure/docker-login@v1 25 | with: 26 | username: ${{ secrets.DOCKER_USERNAME }} 27 | password: ${{ secrets.DOCKER_PASSWORD }} 28 | - name: Docker build & push - envoy 29 | if: github.event_name != 'pull_request' && (startsWith(github.ref, 'refs/tags/') || github.ref == 'refs/heads/master') && success() 30 | run: | 31 | cd rate-limit-filter && DOCKER_BUILDKIT=1 docker build --no-cache -t layer5/image-hub-envoy . 32 | docker tag layer5/image-hub-envoy:latest layer5/image-hub-envoy:${GITHUB_SHA::8} 33 | docker push layer5/image-hub-envoy:${GITHUB_SHA::8} 34 | docker push layer5/image-hub-envoy:latest 35 | - name: Docker build & push - api 36 | if: github.event_name != 'pull_request' && (startsWith(github.ref, 'refs/tags/') || github.ref == 'refs/heads/master') && success() 37 | run: | 38 | cd api && DOCKER_BUILDKIT=1 docker build --no-cache -t layer5/image-hub-api . 39 | docker tag layer5/image-hub-api:latest layer5/image-hub-api:${GITHUB_SHA::8} 40 | docker push layer5/image-hub-api:${GITHUB_SHA::8} 41 | docker push layer5/image-hub-api:latest 42 | - name: Docker build & push - web 43 | if: github.event_name != 'pull_request' && (startsWith(github.ref, 'refs/tags/') || github.ref == 'refs/heads/master') && success() 44 | run: | 45 | cd web && DOCKER_BUILDKIT=1 docker build --no-cache -t layer5/image-hub-web . 46 | docker tag layer5/image-hub-web:latest layer5/image-hub-web:${GITHUB_SHA::8} 47 | docker push layer5/image-hub-web:${GITHUB_SHA::8} 48 | docker push layer5/image-hub-web:latest -------------------------------------------------------------------------------- /.github/workflows/label-commenter.yml: -------------------------------------------------------------------------------- 1 | name: Label Commenter 2 | 3 | on: 4 | issues: 5 | types: 6 | - labeled 7 | 8 | pull_request_target: 9 | types: 10 | - labeled 11 | 12 | permissions: 13 | contents: read 14 | issues: write 15 | pull-requests: write 16 | 17 | jobs: 18 | comment: 19 | runs-on: ubuntu-18.04 20 | steps: 21 | - uses: actions/checkout@v2 22 | with: 23 | ref: main # Set your default branch 24 | 25 | - name: Label Commenter 26 | uses: peaceiris/actions-label-commenter@v1.10.0 -------------------------------------------------------------------------------- /.github/workflows/release-drafter.yml: -------------------------------------------------------------------------------- 1 | name: Release Drafter 2 | 3 | on: 4 | push: 5 | # our release branch 6 | branches: 7 | - master 8 | 9 | jobs: 10 | update_release_draft: 11 | runs-on: ubuntu-latest 12 | steps: 13 | # Drafts your next Release notes as Pull Requests are merged into "master" 14 | - uses: release-drafter/release-drafter@v5 15 | with: 16 | config-name: release-drafter.yml 17 | env: 18 | GITHUB_TOKEN: ${{ secrets.RELEASEDRAFTER_PAT }} 19 | -------------------------------------------------------------------------------- /.github/workflows/slack.yml: -------------------------------------------------------------------------------- 1 | name: Slack Notify on Star 2 | on: watch 3 | jobs: 4 | star-notify: 5 | name: Notify Slack on star 6 | runs-on: ubuntu-latest 7 | steps: 8 | - name: Get current star count 9 | run: | 10 | echo "STARS=$(curl --silent 'https://api.github.com/repos/layer5io/image-hub' -H 'Accept: application/vnd.github.preview' | jq '.stargazers_count')" >> $GITHUB_ENV 11 | - name: Notify slack 12 | env: 13 | SLACK_BOT_TOKEN: ${{ secrets.SLACK_BOT_TOKEN }} 14 | uses: pullreminders/slack-action@master 15 | with: 16 | args: '{\"channel\":\"CSK7N9TGX\",\"text\":\"${{ github.actor }} just starred Image Hub! (https://github.com/layer5io/image-hub/stargazers) Total ⭐️: ${{env.STARS}}\"}' 17 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | target 2 | Cargo.lock -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | Apache License 2 | Version 2.0, January 2004 3 | http://www.apache.org/licenses/ 4 | 5 | TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION 6 | 7 | 1. Definitions. 8 | 9 | "License" shall mean the terms and conditions for use, reproduction, 10 | and distribution as defined by Sections 1 through 9 of this document. 11 | 12 | "Licensor" shall mean the copyright owner or entity authorized by 13 | the copyright owner that is granting the License. 14 | 15 | "Legal Entity" shall mean the union of the acting entity and all 16 | other entities that control, are controlled by, or are under common 17 | control with that entity. For the purposes of this definition, 18 | "control" means (i) the power, direct or indirect, to cause the 19 | direction or management of such entity, whether by contract or 20 | otherwise, or (ii) ownership of fifty percent (50%) or more of the 21 | outstanding shares, or (iii) beneficial ownership of such entity. 22 | 23 | "You" (or "Your") shall mean an individual or Legal Entity 24 | exercising permissions granted by this License. 25 | 26 | "Source" form shall mean the preferred form for making modifications, 27 | including but not limited to software source code, documentation 28 | source, and configuration files. 29 | 30 | "Object" form shall mean any form resulting from mechanical 31 | transformation or translation of a Source form, including but 32 | not limited to compiled object code, generated documentation, 33 | and conversions to other media types. 34 | 35 | "Work" shall mean the work of authorship, whether in Source or 36 | Object form, made available under the License, as indicated by a 37 | copyright notice that is included in or attached to the work 38 | (an example is provided in the Appendix below). 39 | 40 | "Derivative Works" shall mean any work, whether in Source or Object 41 | form, that is based on (or derived from) the Work and for which the 42 | editorial revisions, annotations, elaborations, or other modifications 43 | represent, as a whole, an original work of authorship. For the purposes 44 | of this License, Derivative Works shall not include works that remain 45 | separable from, or merely link (or bind by name) to the interfaces of, 46 | the Work and Derivative Works thereof. 47 | 48 | "Contribution" shall mean any work of authorship, including 49 | the original version of the Work and any modifications or additions 50 | to that Work or Derivative Works thereof, that is intentionally 51 | submitted to Licensor for inclusion in the Work by the copyright owner 52 | or by an individual or Legal Entity authorized to submit on behalf of 53 | the copyright owner. For the purposes of this definition, "submitted" 54 | means any form of electronic, verbal, or written communication sent 55 | to the Licensor or its representatives, including but not limited to 56 | communication on electronic mailing lists, source code control systems, 57 | and issue tracking systems that are managed by, or on behalf of, the 58 | Licensor for the purpose of discussing and improving the Work, but 59 | excluding communication that is conspicuously marked or otherwise 60 | designated in writing by the copyright owner as "Not a Contribution." 61 | 62 | "Contributor" shall mean Licensor and any individual or Legal Entity 63 | on behalf of whom a Contribution has been received by Licensor and 64 | subsequently incorporated within the Work. 65 | 66 | 2. Grant of Copyright License. Subject to the terms and conditions of 67 | this License, each Contributor hereby grants to You a perpetual, 68 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 69 | copyright license to reproduce, prepare Derivative Works of, 70 | publicly display, publicly perform, sublicense, and distribute the 71 | Work and such Derivative Works in Source or Object form. 72 | 73 | 3. Grant of Patent License. Subject to the terms and conditions of 74 | this License, each Contributor hereby grants to You a perpetual, 75 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 76 | (except as stated in this section) patent license to make, have made, 77 | use, offer to sell, sell, import, and otherwise transfer the Work, 78 | where such license applies only to those patent claims licensable 79 | by such Contributor that are necessarily infringed by their 80 | Contribution(s) alone or by combination of their Contribution(s) 81 | with the Work to which such Contribution(s) was submitted. If You 82 | institute patent litigation against any entity (including a 83 | cross-claim or counterclaim in a lawsuit) alleging that the Work 84 | or a Contribution incorporated within the Work constitutes direct 85 | or contributory patent infringement, then any patent licenses 86 | granted to You under this License for that Work shall terminate 87 | as of the date such litigation is filed. 88 | 89 | 4. Redistribution. You may reproduce and distribute copies of the 90 | Work or Derivative Works thereof in any medium, with or without 91 | modifications, and in Source or Object form, provided that You 92 | meet the following conditions: 93 | 94 | (a) You must give any other recipients of the Work or 95 | Derivative Works a copy of this License; and 96 | 97 | (b) You must cause any modified files to carry prominent notices 98 | stating that You changed the files; and 99 | 100 | (c) You must retain, in the Source form of any Derivative Works 101 | that You distribute, all copyright, patent, trademark, and 102 | attribution notices from the Source form of the Work, 103 | excluding those notices that do not pertain to any part of 104 | the Derivative Works; and 105 | 106 | (d) If the Work includes a "NOTICE" text file as part of its 107 | distribution, then any Derivative Works that You distribute must 108 | include a readable copy of the attribution notices contained 109 | within such NOTICE file, excluding those notices that do not 110 | pertain to any part of the Derivative Works, in at least one 111 | of the following places: within a NOTICE text file distributed 112 | as part of the Derivative Works; within the Source form or 113 | documentation, if provided along with the Derivative Works; or, 114 | within a display generated by the Derivative Works, if and 115 | wherever such third-party notices normally appear. The contents 116 | of the NOTICE file are for informational purposes only and 117 | do not modify the License. You may add Your own attribution 118 | notices within Derivative Works that You distribute, alongside 119 | or as an addendum to the NOTICE text from the Work, provided 120 | that such additional attribution notices cannot be construed 121 | as modifying the License. 122 | 123 | You may add Your own copyright statement to Your modifications and 124 | may provide additional or different license terms and conditions 125 | for use, reproduction, or distribution of Your modifications, or 126 | for any such Derivative Works as a whole, provided Your use, 127 | reproduction, and distribution of the Work otherwise complies with 128 | the conditions stated in this License. 129 | 130 | 5. Submission of Contributions. Unless You explicitly state otherwise, 131 | any Contribution intentionally submitted for inclusion in the Work 132 | by You to the Licensor shall be under the terms and conditions of 133 | this License, without any additional terms or conditions. 134 | Notwithstanding the above, nothing herein shall supersede or modify 135 | the terms of any separate license agreement you may have executed 136 | with Licensor regarding such Contributions. 137 | 138 | 6. Trademarks. This License does not grant permission to use the trade 139 | names, trademarks, service marks, or product names of the Licensor, 140 | except as required for reasonable and customary use in describing the 141 | origin of the Work and reproducing the content of the NOTICE file. 142 | 143 | 7. Disclaimer of Warranty. Unless required by applicable law or 144 | agreed to in writing, Licensor provides the Work (and each 145 | Contributor provides its Contributions) on an "AS IS" BASIS, 146 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 147 | implied, including, without limitation, any warranties or conditions 148 | of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A 149 | PARTICULAR PURPOSE. You are solely responsible for determining the 150 | appropriateness of using or redistributing the Work and assume any 151 | risks associated with Your exercise of permissions under this License. 152 | 153 | 8. Limitation of Liability. In no event and under no legal theory, 154 | whether in tort (including negligence), contract, or otherwise, 155 | unless required by applicable law (such as deliberate and grossly 156 | negligent acts) or agreed to in writing, shall any Contributor be 157 | liable to You for damages, including any direct, indirect, special, 158 | incidental, or consequential damages of any character arising as a 159 | result of this License or out of the use or inability to use the 160 | Work (including but not limited to damages for loss of goodwill, 161 | work stoppage, computer failure or malfunction, or any and all 162 | other commercial damages or losses), even if such Contributor 163 | has been advised of the possibility of such damages. 164 | 165 | 9. Accepting Warranty or Additional Liability. While redistributing 166 | the Work or Derivative Works thereof, You may choose to offer, 167 | and charge a fee for, acceptance of support, warranty, indemnity, 168 | or other liability obligations and/or rights consistent with this 169 | License. However, in accepting such obligations, You may act only 170 | on Your own behalf and on Your sole responsibility, not on behalf 171 | of any other Contributor, and only if You agree to indemnify, 172 | defend, and hold each Contributor harmless for any liability 173 | incurred by, or claims asserted against, such Contributor by reason 174 | of your accepting any such warranty or additional liability. 175 | 176 | END OF TERMS AND CONDITIONS 177 | 178 | APPENDIX: How to apply the Apache License to your work. 179 | 180 | To apply the Apache License to your work, attach the following 181 | boilerplate notice, with the fields enclosed by brackets "[]" 182 | replaced with your own identifying information. (Don't include 183 | the brackets!) The text should be enclosed in the appropriate 184 | comment syntax for the file format. We also recommend that a 185 | file or class name and description of purpose be included on the 186 | same "printed page" as the copyright notice for easier 187 | identification within third-party archives. 188 | 189 | Copyright 2020 Layer5, Inc. 190 | 191 | Licensed under the Apache License, Version 2.0 (the "License"); 192 | you may not use this file except in compliance with the License. 193 | You may obtain a copy of the License at 194 | 195 | http://www.apache.org/licenses/LICENSE-2.0 196 | 197 | Unless required by applicable law or agreed to in writing, software 198 | distributed under the License is distributed on an "AS IS" BASIS, 199 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 200 | See the License for the specific language governing permissions and 201 | limitations under the License. 202 | -------------------------------------------------------------------------------- /Makefile: -------------------------------------------------------------------------------- 1 | VER=$(shell git rev-parse --short HEAD) 2 | 3 | build: 4 | cd rate-limit-filter && cargo +nightly build --target=wasm32-unknown-unknown --release 5 | 6 | deploy: 7 | docker-compose up --build --remove-orphans 8 | 9 | # shows only the logs related to WASM filter/singleton 10 | deploy-filtered: 11 | docker-compose up --build --remove-orphans | grep "\[wasm\]\|Starting" 12 | 13 | run: build deploy 14 | 15 | run-filtered: build deploy-filtered 16 | 17 | clean: 18 | cargo clean 19 | 20 | build-web: 21 | cd web && docker build -t layer5/image-hub-web:latest -t layer5/image-hub-web:$(VER) . 22 | 23 | build-api: 24 | cd api && docker build -t layer5/image-hub-api:latest -t layer5/image-hub-api:$(VER) . 25 | 26 | build-envoy: 27 | cd rate-limit-filter && docker build -t layer5/image-hub-envoy:latest -t layer5/image-hub-envoy:$(VER) . 28 | 29 | dev-run-api: build-api deploy 30 | 31 | dev-run-web: 32 | cd web && yarn serve 33 | 34 | image-push-latest: 35 | docker push layer5/image-hub-web:latest 36 | docker push layer5/image-hub-api:latest 37 | docker push layer5/image-hub-envoy:latest 38 | 39 | image-push-version: 40 | docker push layer5/image-hub-web:$(VER) 41 | docker push layer5/image-hub-api:$(VER) 42 | docker push layer5/image-hub-envoy:$(VER) 43 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 |

Layer5 Image Hub

2 | 3 | [![Go Report Card](https://goreportcard.com/badge/github.com/layer5io/image-hub)](https://goreportcard.com/report/github.com/layer5io/image-hub) 4 | [![GitHub](https://img.shields.io/github/license/layer5io/image-hub.svg)](LICENSE) 5 | [![GitHub issues by-label](https://img.shields.io/github/issues/layer5io/meshery/help%20wanted.svg)](https://github.com/issues?utf8=✓&q=is%3Aopen+is%3Aissue+archived%3Afalse+org%3Alayer5io+label%3A%22help+wanted%22+") 6 | [![Website](https://img.shields.io/website/https/layer5.io/meshery.svg)](https://layer5.io/) 7 | [![Twitter Follow](https://img.shields.io/twitter/follow/layer5.svg?label=Follow&style=social)](https://twitter.com/intent/follow?screen_name=layer5) 8 | [![Slack](https://img.shields.io/badge/Slack-@layer5.svg?logo=slack)](http://slack.layer5.io) 9 | [![CII Best Practices](https://bestpractices.coreinfrastructure.org/projects/3564/badge)](https://bestpractices.coreinfrastructure.org/projects/3564) 10 | 11 |

If you’re using the Image Hub or if you like other Layer5 projects, please star this repository to show your support! 🤩

12 | 13 | ## Image Hub 14 | Image Hub is a sample application written to run on [Consul](https://meshery.layer5.io/docs/service-meshes/adapters/consul) for exploring WebAssembly modules used as Envoy filters. This demo application has been enabled by experimental works of [Nic Jackson](https://twitter.com/sheriffjackson) of HashiCorp, and [Kanishkar J](https://twitter.com/_kanishkarj_), [Lee Calcote](https://twitter.com/lcalcote), and other contributors of Layer5. 15 | 16 | 17 | ## Deployment Instructions 18 | 19 | Image Hub supports Envoy-based data planes. Deployment instructions for each supported service mesh are below. 20 | 21 | ### Using Istio (pending [PR #196](https://github.com/layer5io/meshery-istio/pull/196)+release; clone and do make run for now): 22 | 1) Use [Meshery](https://github.com/layer5io/meshery) to deploy [istio](https://github.com/layer5io/advanced-istio-service-mesh-workshop/blob/master/lab-1/README.md) and the Image Hub sample application (Management > Istio > Manage Sample Application Lifecycle > Image-Hub ) onto the Istio service mesh. 23 | 2) To map `imagehub.meshery.io` to the appropriate IP, run the following command to add the appropriate entry in the `"\etc\hosts"` file: 24 | 25 | ``` 26 | echo $(kubectl get nodes --selector=kubernetes.io/role!=master -o jsonpath={.items[0].status.addresses[?\(@.type==\"InternalIP\"\)].address})' 'imagehub.meshery.io | sudo tee -a /etc/hosts 27 | ``` 28 | 3) To get the environment port, run the following command: 29 | ``` 30 | echo $(kubectl get svc istio-ingressgateway -n istio-system -o jsonpath='{.spec.ports[1].nodePort}') 31 | ``` 32 | 4) Access the web UI using: 33 | ``` 34 | http://imagehub.meshery.io: 35 | ``` 36 | 37 | 38 | ### Using Consul: 39 | 40 | 1) Deploy the latest Consul: 41 | 42 | ```bash 43 | helm repo add hashicorp https://helm.releases.hashicorp.com # Adds helm hashicorp repo 44 | helm install consul hashicorp/consul -f config/consul-values.yaml # Setup custom Consul with support for WASM 45 | ``` 46 | 47 | 2) Use [Meshery](https://github.com/layer5io/meshery) to deploy the Image Hub sample application onto the Consul service mesh. 48 | 49 | 3) Find the port assigned to the `ingess` service: 50 | 51 | ``` 52 | kubectl get svc ingess 53 | NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE 54 | ingess NodePort 10.97.34.25 80:31118/TCP 27m 55 | ``` 56 | 57 | 4) Open http://localhost:31118 (where 31118 is your environment's port number). 58 | 59 | ## Use Image Hub 60 | 61 | 1. Upon visiting the image-hub homepage, we would need to signup for an account! Go ahead and click the "Sign Up" button in the top right. 62 | 1. Enter the login details, and select a plan; Personal gives you 10 pulls per minute, Team gives you 100 pulls per minute, and Enterprise will give you 1000 pulls per minute. 63 | 1. After signing up, you should be redirected to the login page, where you can log in and start using the sample app. 64 | 1. On the main page, open up the network tab, and reload the page. This will allow you to see the request-response of the app. 65 | 1. Go ahead and click the download button a couple of times. You'll notice that there is nothing actually limiting you from crossing the number of pulls according to the plan you chose! 66 | 1. Alternatively, you could test the above by navigating to http://imagehub.meshery.io:/pull and then looking at the request-responses. 67 | 68 | ## Deploying the Rate Limiter WASM Filter for Envoy 69 | 70 | 1. Go back to Management > Istio and under "Apply Service Mesh Configuration" make sure to apply "Automatic Sidecar Injection" 71 | 1. Open up a terminal, and run `kubectl get pods` to get a list of running pods. You should be able to see 2 pods, `web` and `api`. Now run 72 | the command `kubectl delete pods `. This will cause kubernetes to respawn them with the updated configuration. 73 | 1. Go back to Management > Istio and under "Apply Service Mesh Configuration", select the `Envoy Filter for Image Hub` option, and wait for a few seconds. 74 | 75 | ## Use Image hub with a WASM filter 76 | 77 | 1. Test your ability to "pull" an image (images are not in fact pulled, but an HTTP request is sent to the backend `api`). You would not be able to pull an image, and the response would say "unauthorized". 78 | 1. Sign up a new user and select a subscription plan. 79 | 1. Log in as that user. 80 | 1. Test your ability to "pull" an image. You should be able to pull an image. 81 | 1. Open Meshery's performance management page (http://localhost:9081/performance) 82 | 1. Configure a performance test against http://x.x.x.x:31118/api/pull (where x.x.x.x is your machine's host IP address, not "localhost") 83 | 1. Enter `{ "authorization" : "" }` 84 | 1. Run the performance test. See that your subscription plan limit is enforced accordingly. 85 | 1. Change your subscription plan and retest. 86 | 87 | ## Architecture 88 | 89 | ### Consul Service Mesh Architecture w/WebAssembly 90 | ![Service Mesh Architecture - Consul](img/readme/service-mesh-architecture-consul.png) 91 | 92 | ### Image Hub deployed on Consul 93 | ![Meshery and WASM](img/readme/image-hub-on-consul-with-wasm-and-meshery.png) 94 | 95 | ## Presentations 96 | 97 | DockerCon'2020 98 | 99 | - [DockerCon 2020](https://docker.events.cube365.net/docker/dockercon/content/Videos/63TCCNpzDC7Xxnm8b) | [deck](https://calcotestudios.com/talks/decks/slides-dockercon-2020-service-meshing-with-docker-desktop-and-webassembly.html) | ([video](https://www.youtube.com/watch?v=5BrbbKZOctw&list=PL3A-A6hPO2IN_HSU0pSfijBboiHggs5mC&index=4&t=0s) 100 | 101 |
 
102 | 103 | ## Join the Community! 104 | 105 | 106 | Our projects are community-built and welcome collaboration. 👍 Be sure to see the Layer5 Community Welcome Guide for a tour of resources available to you and jump into our Slack! 107 | 108 | Layer5 Cloud Native Community 109 | 110 | 111 | 112 | 113 | 114 | 115 | Shows an illustrated light mode meshery logo in light color mode and a dark mode meshery logo dark color mode. 116 | 117 | 118 | 119 | 120 |

121 | ✔️ Join any or all of the weekly meetings on the community calendar.
122 | ✔️ Watch community meeting recordings.
123 | ✔️ Fill-in a community member form to gain access to community resources. 124 |
125 | ✔️ Discuss in the Community Forum.
126 |

127 |

128 | Not sure where to start? Grab an open issue with the help-wanted label. 129 |

130 | 131 |
 
132 | 133 | ### About Layer5 134 | 135 | [Layer5](https://layer5.io)'s cloud native application and infrastructure management software enables organizations to expect more from their infrastructure. We embrace developer-defined infrastructure. We empower engineer to change how they write applications, support operators in rethinking how they run modern infrastructure and enable product owners to regain full control over their product portfolio. 136 | 137 | **License** 138 | 139 | This repository and site are available as open source under the terms of the [Apache 2.0 License](https://opensource.org/licenses/Apache-2.0). 140 | -------------------------------------------------------------------------------- /api/Dockerfile: -------------------------------------------------------------------------------- 1 | FROM golang:1.13.5 as bd 2 | WORKDIR /github.com/layer5io/dockercon-2020-api 3 | ADD . . 4 | RUN GOPROXY=direct GOSUMDB=off go build -a -o /api . 5 | CMD ["/api"] -------------------------------------------------------------------------------- /api/go.mod: -------------------------------------------------------------------------------- 1 | module github.com/layer5io/dockercon-2020/api 2 | 3 | go 1.14 4 | -------------------------------------------------------------------------------- /api/main.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "encoding/base64" 5 | "encoding/json" 6 | "fmt" 7 | "io/ioutil" 8 | "net/http" 9 | ) 10 | 11 | type User struct { 12 | Username string 13 | Password string 14 | Plan string 15 | } 16 | 17 | var DB = map[string]User{} 18 | 19 | func CORSMiddleware(next http.Handler) http.Handler { 20 | return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { 21 | if r.Method == http.MethodOptions { 22 | w.Header().Set("Access-Control-Allow-Origin", "*") 23 | w.Header().Set("Access-Control-Allow-Methods", "*") 24 | w.Header().Set("Access-Control-Allow-Headers", "*") 25 | w.Header().Set("Access-Control-Max-Age", "3600") 26 | w.WriteHeader(http.StatusNoContent) 27 | return 28 | } 29 | w.Header().Set("Access-Control-Allow-Origin", "*") 30 | next.ServeHTTP(w, r) 31 | }) 32 | } 33 | 34 | func hello(w http.ResponseWriter, req *http.Request) { 35 | token := req.Header.Get("Authorization") 36 | w.Write([]byte("Hello, " + token + ", welcome to Istiocon 2021!")) 37 | } 38 | 39 | func auth(w http.ResponseWriter, req *http.Request) { 40 | defer req.Body.Close() 41 | data, err := ioutil.ReadAll(req.Body) 42 | if err != nil { 43 | w.WriteHeader(http.StatusBadRequest) 44 | return 45 | } 46 | var mp map[string]string 47 | err = json.Unmarshal(data, &mp) 48 | fmt.Printf("1 %v", mp) 49 | if err != nil { 50 | w.WriteHeader(http.StatusInternalServerError) 51 | return 52 | } 53 | username := mp["username"] 54 | password := mp["password"] 55 | matchedUser, ok := DB[username] 56 | 57 | if !ok || matchedUser.Password != password { 58 | w.WriteHeader(http.StatusBadRequest) 59 | return 60 | } 61 | 62 | token, err := json.Marshal(&map[string]string{ 63 | "username": matchedUser.Username, 64 | "plan": matchedUser.Plan, 65 | }) 66 | 67 | fmt.Printf("3 %v", string(token)) 68 | if err != nil { 69 | w.WriteHeader(http.StatusInternalServerError) 70 | return 71 | } 72 | 73 | json.NewEncoder(w).Encode(map[string]string{ 74 | "token": base64.RawStdEncoding.EncodeToString(token), 75 | }) 76 | } 77 | 78 | func upgrade(w http.ResponseWriter, req *http.Request) { 79 | defer req.Body.Close() 80 | data, err := ioutil.ReadAll(req.Body) 81 | if err != nil { 82 | w.WriteHeader(http.StatusBadRequest) 83 | return 84 | } 85 | var mp map[string]string 86 | err = json.Unmarshal(data, &mp) 87 | fmt.Printf("1 %v", mp) 88 | if err != nil { 89 | w.WriteHeader(http.StatusInternalServerError) 90 | return 91 | } 92 | username := mp["username"] 93 | matchedUser, ok := DB[username] 94 | 95 | fmt.Printf("3 %v %v", matchedUser, ok) 96 | if !ok { 97 | w.WriteHeader(http.StatusBadRequest) 98 | return 99 | } 100 | 101 | matchedUser.Plan = mp["plan"] 102 | 103 | token, err := json.Marshal(&map[string]string{ 104 | "username": matchedUser.Username, 105 | "plan": matchedUser.Plan, 106 | }) 107 | 108 | fmt.Printf("3 %v", string(token)) 109 | if err != nil { 110 | w.WriteHeader(http.StatusInternalServerError) 111 | return 112 | } 113 | 114 | json.NewEncoder(w).Encode(map[string]string{ 115 | "token": base64.RawStdEncoding.EncodeToString(token), 116 | }) 117 | } 118 | 119 | func signup(w http.ResponseWriter, req *http.Request) { 120 | defer req.Body.Close() 121 | data, err := ioutil.ReadAll(req.Body) 122 | if err != nil { 123 | w.WriteHeader(http.StatusBadRequest) 124 | return 125 | } 126 | var mp map[string]string 127 | err = json.Unmarshal(data, &mp) 128 | fmt.Printf("1 %v", mp) 129 | if err != nil { 130 | w.WriteHeader(http.StatusInternalServerError) 131 | return 132 | } 133 | newUser := User{ 134 | Username: mp["username"], 135 | Password: mp["password"], 136 | Plan: mp["plan"], 137 | } 138 | DB[mp["username"]] = newUser 139 | } 140 | 141 | func main() { 142 | mux := http.NewServeMux() 143 | mux.Handle("/pull", CORSMiddleware(http.HandlerFunc(hello))) 144 | mux.Handle("/auth", CORSMiddleware(http.HandlerFunc(auth))) 145 | mux.Handle("/signup", CORSMiddleware(http.HandlerFunc(signup))) 146 | mux.Handle("/upgrade", CORSMiddleware(http.HandlerFunc(upgrade))) 147 | http.ListenAndServe(":9091", mux) 148 | } 149 | -------------------------------------------------------------------------------- /config/consul-values.yaml: -------------------------------------------------------------------------------- 1 | global: 2 | datacenter: image-hub 3 | image: nicholasjackson/consul-envoy:dev-dev 4 | imageK8S: nicholasjackson/consul-k8s-dev:latest 5 | 6 | # Specify a container which has Envoy and any referenced filters 7 | imageEnvoy: "layer5/image-hub-envoy:latest" 8 | 9 | # Available parameters and their default values for the Consul chart. 10 | # Server, when enabled, configures a server cluster to run. This should 11 | # be disabled if you plan on connecting to a Consul cluster external to 12 | # the Kube cluster. 13 | server: 14 | replicas: 1 15 | bootstrapExpect: 1 # Should <= replicas count 16 | 17 | # storage and storageClass are the settings for configuring stateful 18 | # storage for the server pods. storage should be set to the disk size of 19 | # the attached volume. storageClass is the class of storage which defaults 20 | # to null (the Kube cluster will pick the default). 21 | storage: 64Mi 22 | # storageClass: local-path 23 | 24 | # Client, when enabled, configures Consul clients to run on every node 25 | # within the Kube cluster. The current deployment model follows a traditional 26 | # DC where a single agent is deployed per node. 27 | client: 28 | enabled: true 29 | 30 | # grpc should be set to true if the gRPC listener should be enabled. 31 | # This should be set to true if connectInject or meshGateway is enabled. 32 | grpc: true 33 | 34 | ui: 35 | # True if you want to enable the Consul UI. The UI will run only 36 | # on the server nodes. This makes UI access via the service below (if 37 | # enabled) predictable rather than "any node" if you're running Consul 38 | # clients as well. 39 | enabled: true 40 | 41 | # True if you want to create a Service entry for the Consul UI. 42 | # 43 | # serviceType can be used to control the type of service created. For 44 | # example, setting this to "LoadBalancer" will create an external load 45 | # balancer (for supported K8S installations) to access the UI. 46 | service: 47 | enabled: true 48 | type: 'NodePort' 49 | 50 | # ConnectInject will enable the automatic Connect sidecar injector. 51 | connectInject: 52 | enabled: true 53 | default: false # true will inject by default, otherwise requires annotation 54 | 55 | # Requires Consul v1.5+ and consul-k8s v0.8.1+ 56 | centralConfig: 57 | enabled: "true" 58 | 59 | # defaultProtocol allows you to specify a convenience default protocol if 60 | # most of your services are of the same protocol type. The individual annotation 61 | # on any given pod will override this value. A protocol must be provided, 62 | # either through this setting or individual annotation, for a service to be 63 | # registered correctly. Valid values are "http", "http2", "grpc" and "tcp". 64 | defaultProtocol: "http" -------------------------------------------------------------------------------- /config/image-hub.yaml: -------------------------------------------------------------------------------- 1 | # Service to expose web frontend 2 | 3 | apiVersion: v1 4 | kind: Service 5 | metadata: 6 | name: web-service 7 | spec: 8 | type: ClusterIP 9 | selector: 10 | app: web 11 | ports: 12 | - name: http 13 | protocol: TCP 14 | port: 8080 15 | targetPort: 8080 16 | --- 17 | # Web frontend 18 | 19 | apiVersion: apps/v1 20 | kind: Deployment 21 | metadata: 22 | name: web-deployment 23 | labels: 24 | app: web 25 | spec: 26 | replicas: 1 27 | selector: 28 | matchLabels: 29 | app: web 30 | template: 31 | metadata: 32 | labels: 33 | app: web 34 | annotations: 35 | "consul.hashicorp.com/connect-inject": "true" 36 | "consul.hashicorp.com/connect-service-upstreams": "api:9091" 37 | "consul.hashicorp.com/connect-service-protocol": "http" 38 | spec: 39 | containers: 40 | - name: web 41 | image: layer5/image-hub-web:latest 42 | ports: 43 | - containerPort: 8080 44 | env: 45 | - name: "LISTEN_ADDR" 46 | value: "0.0.0.0:8080" 47 | - name: "UPSTREAM_URIS" 48 | value: "http://localhost:9091" 49 | - name: "NAME" 50 | value: "web" 51 | - name: "MESSAGE" 52 | value: "Hello World" 53 | - name: "HTTP_CLIENT_KEEP_ALIVES" 54 | value: "false" 55 | - name: "TRACING_ZIPKIN" 56 | value: "http://jaeger-collector:9411" 57 | 58 | --- 59 | # API service version 2 60 | 61 | apiVersion: apps/v1 62 | kind: Deployment 63 | metadata: 64 | name: api-deployment-v1 65 | labels: 66 | app: api-v1 67 | spec: 68 | replicas: 1 69 | selector: 70 | matchLabels: 71 | app: api-v1 72 | template: 73 | metadata: 74 | labels: 75 | app: api-v1 76 | annotations: 77 | "consul.hashicorp.com/connect-inject": "true" 78 | "consul.hashicorp.com/service-meta-version": "1" 79 | "consul.hashicorp.com/service-tags": "v1" 80 | "consul.hashicorp.com/connect-service-protocol": "http" 81 | "consul.hashicorp.com/connect-wasm-filter-add_header": "/filters/optimized.wasm" 82 | spec: 83 | containers: 84 | - name: api 85 | image: layer5/image-hub-api:latest 86 | ports: 87 | - containerPort: 9091 88 | env: 89 | - name: "LISTEN_ADDR" 90 | value: "0.0.0.0:9091" 91 | - name: "NAME" 92 | value: "api-v1" 93 | - name: "MESSAGE" 94 | value: "Response from API v1" 95 | --- 96 | apiVersion: v1 97 | kind: Service 98 | metadata: 99 | name: ingess 100 | labels: 101 | app: envoy 102 | spec: 103 | # type: LoadBalancer 104 | # If you are testing on Docker Desktop or Minikube 105 | type: NodePort 106 | ports: 107 | - port: 80 108 | targetPort: 80 109 | selector: 110 | app: envoy 111 | 112 | --- 113 | apiVersion: v1 114 | kind: ConfigMap 115 | metadata: 116 | name: envoy-configmap 117 | data: 118 | config: | 119 | static_resources: 120 | listeners: 121 | - address: 122 | socket_address: 123 | address: 0.0.0.0 124 | port_value: 80 125 | filter_chains: 126 | - filters: 127 | - name: envoy.http_connection_manager 128 | typed_config: 129 | "@type": type.googleapis.com/envoy.config.filter.network.http_connection_manager.v2.HttpConnectionManager 130 | codec_type: http1 131 | stat_prefix: ingress_http 132 | route_config: 133 | name: local_route 134 | virtual_hosts: 135 | - name: backend 136 | domains: 137 | - "*" 138 | routes: 139 | - match: 140 | prefix: "/api/" 141 | route: 142 | prefix_rewrite: "/" 143 | cluster: api-service 144 | - match: 145 | prefix: "/" 146 | route: 147 | cluster: web-service 148 | http_filters: 149 | - name: envoy.router 150 | typed_config: {} 151 | clusters: 152 | - name: web-service 153 | connect_timeout: 1.00s 154 | type: strict_dns 155 | lb_policy: round_robin 156 | load_assignment: 157 | cluster_name: web-service 158 | endpoints: 159 | - lb_endpoints: 160 | - endpoint: 161 | address: 162 | socket_address: 163 | address: web-service 164 | port_value: 8080 165 | ipv4_compat: true 166 | - name: api-service 167 | connect_timeout: 0.25s 168 | type: strict_dns 169 | lb_policy: round_robin 170 | load_assignment: 171 | cluster_name: terminal 172 | endpoints: 173 | - lb_endpoints: 174 | - endpoint: 175 | address: 176 | socket_address: 177 | address: 0.0.0.0 178 | port_value: 9091 179 | ipv4_compat: true 180 | admin: 181 | access_log_path: "/dev/null" 182 | address: 183 | socket_address: 184 | address: 0.0.0.0 185 | port_value: 8001 186 | 187 | --- 188 | apiVersion: apps/v1 189 | kind: Deployment 190 | metadata: 191 | name: envoy 192 | spec: 193 | replicas: 1 194 | selector: 195 | matchLabels: 196 | service: envoy 197 | app: envoy 198 | template: 199 | metadata: 200 | labels: 201 | service: envoy 202 | app: envoy 203 | annotations: 204 | "consul.hashicorp.com/connect-inject": "true" 205 | "consul.hashicorp.com/connect-service-upstreams": "api:9091" 206 | "consul.hashicorp.com/connect-service-protocol": "http" 207 | spec: 208 | volumes: 209 | - name: config 210 | configMap: 211 | name: envoy-configmap 212 | items: 213 | - key: config 214 | path: envoy.yaml 215 | containers: 216 | - name: envoy 217 | image: envoyproxy/envoy-alpine:v1.10.0 218 | ports: 219 | - containerPort: 80 220 | volumeMounts: 221 | - name: config 222 | mountPath: /etc/envoy 223 | readOnly: true -------------------------------------------------------------------------------- /deployment.yaml: -------------------------------------------------------------------------------- 1 | # Copyright Layer5 Authors 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | --- 15 | apiVersion: v1 16 | kind: Service 17 | metadata: 18 | name: api 19 | labels: 20 | app: api 21 | service: api 22 | spec: 23 | ports: 24 | - port: 9091 25 | name: http 26 | selector: 27 | app: api 28 | --- 29 | apiVersion: v1 30 | kind: ServiceAccount 31 | metadata: 32 | name: imagehub-api 33 | labels: 34 | account: api 35 | --- 36 | apiVersion: apps/v1 37 | kind: Deployment 38 | metadata: 39 | name: api-v1 40 | labels: 41 | app: api 42 | version: v1 43 | spec: 44 | replicas: 1 45 | selector: 46 | matchLabels: 47 | app: api 48 | version: v1 49 | template: 50 | metadata: 51 | labels: 52 | app: api 53 | version: v1 54 | spec: 55 | serviceAccountName: imagehub-api 56 | containers: 57 | - name: api 58 | image: layer5/image-hub-api:latest 59 | imagePullPolicy: IfNotPresent 60 | ports: 61 | - containerPort: 9091 62 | volumes: 63 | - name: wasm-filter 64 | emptyDir: {} 65 | --- 66 | apiVersion: v1 67 | kind: Service 68 | metadata: 69 | name: web 70 | labels: 71 | app: web 72 | service: web 73 | spec: 74 | ports: 75 | - port: 8080 76 | name: http 77 | selector: 78 | app: web 79 | --- 80 | apiVersion: v1 81 | kind: ServiceAccount 82 | metadata: 83 | name: imagehub-web 84 | labels: 85 | account: web 86 | --- 87 | apiVersion: apps/v1 88 | kind: Deployment 89 | metadata: 90 | name: web-v1 91 | labels: 92 | app: web 93 | version: v1 94 | spec: 95 | replicas: 1 96 | selector: 97 | matchLabels: 98 | app: web 99 | version: v1 100 | template: 101 | metadata: 102 | labels: 103 | app: web 104 | version: v1 105 | spec: 106 | serviceAccountName: imagehub-web 107 | containers: 108 | - name: web 109 | image: layer5/image-hub-web:latest 110 | imagePullPolicy: IfNotPresent 111 | ports: 112 | - containerPort: 8080 113 | -------------------------------------------------------------------------------- /docker-compose.yaml: -------------------------------------------------------------------------------- 1 | version: '2' 2 | services: 3 | 4 | proxy: 5 | build: 6 | context: ./ 7 | dockerfile: envoy.Dockerfile 8 | volumes: 9 | - ./envoy.yaml:/etc/envoy.yaml 10 | - ./rate-limit-filter/target/wasm32-unknown-unknown/release/rate_limit_filter.wasm:/etc/rate_limit_filter.wasm 11 | networks: 12 | - envoymesh 13 | expose: 14 | - "80" 15 | - "8001" 16 | ports: 17 | - "9091:80" 18 | - "18001:8001" 19 | 20 | web_service: 21 | image: layer5/image-hub-api:latest 22 | networks: 23 | envoymesh: 24 | aliases: 25 | - web_service 26 | expose: 27 | - "9091" 28 | ports: 29 | - "9000:9091" 30 | 31 | networks: 32 | envoymesh: {} 33 | -------------------------------------------------------------------------------- /docs/assets/img/readme/docker-con-2020.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/layer5io/image-hub/626ca0c1782cdb9cd5c07ba2cfe7af33da668812/docs/assets/img/readme/docker-con-2020.png -------------------------------------------------------------------------------- /envoy.Dockerfile: -------------------------------------------------------------------------------- 1 | FROM istio/proxyv2:1.5.0 2 | ENTRYPOINT /usr/local/bin/envoy -c /etc/envoy.yaml -l debug --service-cluster proxy -------------------------------------------------------------------------------- /envoy.yaml: -------------------------------------------------------------------------------- 1 | static_resources: 2 | listeners: 3 | - name: main 4 | address: 5 | socket_address: 6 | address: 0.0.0.0 7 | port_value: 80 8 | filter_chains: 9 | - filters: 10 | - name: envoy.http_connection_manager 11 | config: 12 | stat_prefix: ingress_http 13 | codec_type: auto 14 | route_config: 15 | name: local_route 16 | virtual_hosts: 17 | - name: local_service 18 | domains: 19 | - "*" 20 | routes: 21 | - match: 22 | prefix: "/" 23 | route: 24 | cluster: web_service 25 | http_filters: 26 | - name: envoy.filters.http.wasm 27 | config: 28 | config: 29 | name: "rate_limit_filter" 30 | root_id: "rate_limit_filter" 31 | vm_config: 32 | runtime: "envoy.wasm.runtime.v8" 33 | code: 34 | local: 35 | filename: "/etc/rate_limit_filter.wasm" 36 | allow_precompiled: true 37 | - name: envoy.router 38 | config: {} 39 | - name: staticreply 40 | address: 41 | socket_address: 42 | address: 127.0.0.1 43 | port_value: 8099 44 | filter_chains: 45 | - filters: 46 | - name: envoy.http_connection_manager 47 | config: 48 | stat_prefix: ingress_http 49 | codec_type: auto 50 | route_config: 51 | name: local_route 52 | virtual_hosts: 53 | - name: local_service 54 | domains: 55 | - "*" 56 | routes: 57 | - match: 58 | prefix: "/" 59 | direct_response: 60 | status: 200 61 | body: 62 | inline_string: "example body\n" 63 | http_filters: 64 | - name: envoy.router 65 | config: {} 66 | clusters: 67 | - name: web_service 68 | connect_timeout: 0.25s 69 | type: STRICT_DNS 70 | lb_policy: round_robin 71 | hosts: 72 | - socket_address: 73 | address: web_service 74 | port_value: 9091 75 | # - name: wasm_upstream 76 | # connect_timeout: 0.25s 77 | # type: STRICT_DNS 78 | # lb_policy: round_robin 79 | # hosts: 80 | # - socket_address: 81 | # address: wasm_upstream 82 | # port_value: 8080 83 | admin: 84 | access_log_path: "/dev/null" 85 | address: 86 | socket_address: 87 | address: 0.0.0.0 88 | port_value: 8001 89 | -------------------------------------------------------------------------------- /gateway.yaml: -------------------------------------------------------------------------------- 1 | apiVersion: networking.istio.io/v1alpha3 2 | kind: Gateway 3 | metadata: 4 | name: imagehub-gateway 5 | spec: 6 | selector: 7 | istio: ingressgateway # use istio default controller 8 | servers: 9 | - port: 10 | number: 9091 11 | name: http 12 | protocol: HTTP 13 | hosts: 14 | - "*" 15 | --- 16 | apiVersion: networking.istio.io/v1alpha3 17 | kind: VirtualService 18 | metadata: 19 | name: imagehub 20 | spec: 21 | hosts: 22 | - "*" 23 | gateways: 24 | - imagehub-gateway 25 | http: 26 | - route: 27 | - destination: 28 | host: api 29 | port: 30 | number: 9091 31 | -------------------------------------------------------------------------------- /img/readme/community.svg: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /img/readme/image-hub-on-consul-with-wasm-and-meshery.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/layer5io/image-hub/626ca0c1782cdb9cd5c07ba2cfe7af33da668812/img/readme/image-hub-on-consul-with-wasm-and-meshery.png -------------------------------------------------------------------------------- /img/readme/layer5-image-hub.svg: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /img/readme/service-mesh-architecture-consul.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/layer5io/image-hub/626ca0c1782cdb9cd5c07ba2cfe7af33da668812/img/readme/service-mesh-architecture-consul.png -------------------------------------------------------------------------------- /img/readme/slack-128.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/layer5io/image-hub/626ca0c1782cdb9cd5c07ba2cfe7af33da668812/img/readme/slack-128.png -------------------------------------------------------------------------------- /img/readme/slack-dark-128.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/layer5io/image-hub/626ca0c1782cdb9cd5c07ba2cfe7af33da668812/img/readme/slack-dark-128.png -------------------------------------------------------------------------------- /rate-limit-filter/.dockerignore: -------------------------------------------------------------------------------- 1 | target/ -------------------------------------------------------------------------------- /rate-limit-filter/Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "rate_limit_filter" 3 | version = "0.1.0" 4 | authors = ["kanishkarj "] 5 | edition = "2018" 6 | # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html 7 | 8 | [lib] 9 | crate-type = ["cdylib"] 10 | 11 | [dependencies] 12 | base64 = "0.13.0" 13 | bincode = "1.0" 14 | proxy-wasm = "^0.1" 15 | serde = { version = "1.0", default-features = false, features = ["derive"] } 16 | serde_json ="1.0" 17 | wasm-bindgen = "0.2" 18 | -------------------------------------------------------------------------------- /rate-limit-filter/Dockerfile: -------------------------------------------------------------------------------- 1 | 2 | FROM rustlang/rust:nightly as build 3 | 4 | RUN rustup default nightly 5 | RUN rustup target add wasm32-unknown-unknown 6 | 7 | RUN mkdir /app 8 | COPY . /app 9 | WORKDIR /app 10 | 11 | RUN cargo +nightly build --target=wasm32-unknown-unknown --release 12 | 13 | # Current dev build of Envoy only supports systems with glibC 14 | FROM ubuntu:latest 15 | 16 | # RUN apt update && apt install -y wget 17 | 18 | RUN mkdir /filters 19 | 20 | # Add Envoy with WASM support built in 21 | COPY ./envoy ./ 22 | RUN mv ./envoy /usr/local/bin/envoy && chmod +x /usr/local/bin/envoy 23 | 24 | # Copy your compiled filter to the container 25 | COPY --from=0 /app/target/wasm32-unknown-unknown/release/rate_limit_filter.wasm /filters/optimized.wasm -------------------------------------------------------------------------------- /rate-limit-filter/README.md: -------------------------------------------------------------------------------- 1 | # wasm_test -------------------------------------------------------------------------------- /rate-limit-filter/envoy: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/layer5io/image-hub/626ca0c1782cdb9cd5c07ba2cfe7af33da668812/rate-limit-filter/envoy -------------------------------------------------------------------------------- /rate-limit-filter/pkg/rate_limit_filter_bg.wasm: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/layer5io/image-hub/626ca0c1782cdb9cd5c07ba2cfe7af33da668812/rate-limit-filter/pkg/rate_limit_filter_bg.wasm -------------------------------------------------------------------------------- /rate-limit-filter/src/json_parse/mod.rs: -------------------------------------------------------------------------------- 1 | mod rules; 2 | 3 | pub use rules::JsonPath; 4 | pub use rules::RateLimiterJson; 5 | pub use rules::Rule; 6 | -------------------------------------------------------------------------------- /rate-limit-filter/src/json_parse/rules.rs: -------------------------------------------------------------------------------- 1 | use serde::Deserialize; 2 | 3 | #[derive(Clone, Debug, Deserialize, PartialEq, PartialOrd)] 4 | pub struct JsonPath { 5 | pub name: String, 6 | pub rule: Rule, 7 | } 8 | 9 | #[derive(Clone, Debug, Deserialize, PartialEq, PartialOrd)] 10 | #[serde(rename_all(deserialize = "kebab-case"))] 11 | #[serde(tag = "ruleType", content = "parameters")] 12 | pub enum Rule { 13 | RateLimiter(Vec), 14 | None, 15 | } 16 | 17 | #[derive(Clone, Debug, Deserialize, PartialEq, PartialOrd)] 18 | pub struct RateLimiterJson { 19 | pub identifier: String, 20 | pub limit: u32, 21 | } 22 | -------------------------------------------------------------------------------- /rate-limit-filter/src/lib.rs: -------------------------------------------------------------------------------- 1 | mod json_parse; 2 | mod rate_limiter; 3 | 4 | use json_parse::{JsonPath, RateLimiterJson, Rule}; 5 | use proxy_wasm::traits::*; 6 | use proxy_wasm::types::*; 7 | use rate_limiter::RateLimiter; 8 | use serde::Deserialize; 9 | 10 | use std::collections::HashMap; 11 | use std::time::SystemTime; 12 | 13 | // We need to make sure a HTTP root context is created and initialized when the filter is initialized. 14 | // The _start() function initialises this root context 15 | #[no_mangle] 16 | pub fn _start() { 17 | proxy_wasm::set_log_level(LogLevel::Info); 18 | proxy_wasm::set_root_context(|_| -> Box { 19 | Box::new(UpstreamCallRoot { 20 | config_json: HashMap::new(), 21 | }) 22 | }); 23 | } 24 | 25 | // Defining standard CORS headers 26 | static CORS_HEADERS: [(&str, &str); 5] = [ 27 | ("Powered-By", "proxy-wasm"), 28 | ("Access-Control-Allow-Origin", "*"), 29 | ("Access-Control-Allow-Methods", "*"), 30 | ("Access-Control-Allow-Headers", "*"), 31 | ("Access-Control-Max-Age", "3600"), 32 | ]; 33 | 34 | // This struct is what the JWT token sent by the user will deserialize to 35 | #[derive(Deserialize, Debug)] 36 | struct Data { 37 | username: String, 38 | plan: String, 39 | } 40 | 41 | // This is the instance of a call made. It sorta derives from the root context 42 | #[derive(Debug)] 43 | struct UpstreamCall { 44 | config_json: HashMap, 45 | } 46 | 47 | impl UpstreamCall { 48 | // Takes in the HashMap created in the root context mapping path name to rule type 49 | fn new(json_hm: &HashMap) -> Self { 50 | Self { 51 | //TODO this clone is super heavy, find a way to get rid of it 52 | config_json: json_hm.clone(), 53 | } 54 | } 55 | 56 | // Check if the path specified in the incoming request's path header has rule type None. 57 | // Returns Option containing path name that was sent 58 | fn rule_is_none(&self, path: String) -> Option { 59 | let rule = self.config_json.get(&path).unwrap(); 60 | // checking based only on type 61 | if std::mem::discriminant(rule) == std::mem::discriminant(&Rule::None) { 62 | return Some(path); 63 | } 64 | return None; 65 | } 66 | 67 | // Check if the path specified in the incoming request's path header has rule type RateLimiter. 68 | // Returns Option containing vector of RateLimiterJson objects (list of plan names with limits) 69 | fn rule_is_rate_limiter(&self, path: String) -> Option> { 70 | let rule = self.config_json.get(&path).unwrap(); 71 | // checking based only on type 72 | if std::mem::discriminant(rule) == std::mem::discriminant(&Rule::RateLimiter(Vec::new())) { 73 | if let Rule::RateLimiter(plans_vec) = rule { 74 | return Some(plans_vec.to_vec()); 75 | } 76 | } 77 | return None; 78 | } 79 | } 80 | 81 | impl Context for UpstreamCall {} 82 | 83 | impl HttpContext for UpstreamCall { 84 | fn on_http_request_headers(&mut self, _num_headers: usize) -> Action { 85 | // Options 86 | if let Some(method) = self.get_http_request_header(":method") { 87 | if method == "OPTIONS" { 88 | self.send_http_response(204, CORS_HEADERS.to_vec(), None); 89 | return Action::Pause; 90 | } 91 | } 92 | 93 | // Action for rule type: None 94 | if let Some(_) = self.rule_is_none(self.get_http_request_header(":path").unwrap()) { 95 | return Action::Continue; 96 | } 97 | 98 | // Action for rule type: RateLimiter 99 | if let Some(plans_vec) = 100 | self.rule_is_rate_limiter(self.get_http_request_header(":path").unwrap()) 101 | { 102 | if let Some(header) = self.get_http_request_header("Authorization") { 103 | // Decoding JWT token 104 | if let Ok(token) = base64::decode(header) { 105 | //Deserializing token 106 | let obj: Data = serde_json::from_slice(&token).unwrap(); 107 | 108 | proxy_wasm::hostcalls::log(LogLevel::Debug, format!("Obj {:?}", obj).as_str()) 109 | .ok(); 110 | 111 | // Since the rate limit works on a rate per minute based quota, we find current time 112 | let curr = self.get_current_time(); 113 | let tm = curr.duration_since(SystemTime::UNIX_EPOCH).unwrap(); 114 | let mn = (tm.as_secs() / 60) % 60; 115 | let _sc = tm.as_secs() % 60; 116 | 117 | // Initialise RateLimiter object 118 | let mut rl = RateLimiter::get(&obj.username, &obj.plan); 119 | 120 | // Initialising headers to send back 121 | let mut headers = CORS_HEADERS.to_vec(); 122 | let count: String; 123 | 124 | // Extracting limits based on plan stated in JWT token from the corresponding RateLimiterJson 125 | let limit = plans_vec 126 | .into_iter() 127 | .filter(|x| x.identifier == obj.plan) 128 | .map(|x| x.limit) 129 | .collect::>(); 130 | 131 | // Checking if the appropriate plan exists 132 | if limit.len() != 1 { 133 | self.send_http_response( 134 | 429, 135 | headers, 136 | Some(b"Invalid plan name or duplicate plan names defined.\n"), 137 | ); 138 | return Action::Pause; 139 | } 140 | 141 | //Update request count in RateLimiter object, and check if it exceeds limits 142 | if rl.update(mn as i32) > limit[0] { 143 | count = rl.count.to_string(); 144 | headers 145 | .append(&mut vec![("x-rate-limit", &count), ("x-app-user", &rl.key)]); 146 | self.send_http_response(429, headers, Some(b"Limit exceeded.\n")); 147 | rl.set(); 148 | return Action::Pause; 149 | } 150 | proxy_wasm::hostcalls::log(LogLevel::Debug, format!("Obj {:?}", &rl).as_str()) 151 | .ok(); 152 | // set the new count in headers, and proxy_wasm storage 153 | count = rl.count.to_string(); 154 | rl.set(); 155 | headers.append(&mut vec![("x-rate-limit", &count), ("x-app-user", &rl.key)]); 156 | self.send_http_response(200, headers, Some(b"All Good!\n")); 157 | return Action::Continue; 158 | } 159 | } 160 | } 161 | self.send_http_response(401, CORS_HEADERS.to_vec(), Some(b"Unauthorized\n")); 162 | Action::Pause 163 | } 164 | 165 | fn on_http_response_headers(&mut self, _num_headers: usize) -> Action { 166 | self.set_http_response_header("x-app-serving", Some("rate-limit-filter")); 167 | proxy_wasm::hostcalls::log(LogLevel::Debug, format!("RESPONDING").as_str()).ok(); 168 | Action::Continue 169 | } 170 | } 171 | 172 | struct UpstreamCallRoot { 173 | config_json: HashMap, 174 | } 175 | 176 | impl Context for UpstreamCallRoot {} 177 | impl<'a> RootContext for UpstreamCallRoot { 178 | //TODO: Revisit this once the read only feature is released in Istio 1.10 179 | // Get Base64 encoded JSON from envoy config file when WASM VM starts 180 | fn on_vm_start(&mut self, _: usize) -> bool { 181 | if let Some(config_bytes) = self.get_configuration() { 182 | // bytestring passed by VM -> String of base64 encoded JSON 183 | let config_str = String::from_utf8(config_bytes).unwrap(); 184 | // String of base64 encoded JSON -> bytestring of decoded JSON 185 | let config_b64 = base64::decode(config_str).unwrap(); 186 | // bytestring of decoded JSON -> String of decoded JSON 187 | let json_str = String::from_utf8(config_b64).unwrap(); 188 | // Deserializing JSON String into vector of JsonPath objects 189 | let json_vec: Vec = serde_json::from_str(&json_str).unwrap(); 190 | // Creating HashMap of pattern ("path name", "rule type") and saving into UpstreamCallRoot object 191 | for i in json_vec { 192 | self.config_json.insert(i.name, i.rule); 193 | } 194 | } 195 | true 196 | } 197 | 198 | fn create_http_context(&self, _: u32) -> Option> { 199 | // creating UpstreamCall object for each new call 200 | Some(Box::new(UpstreamCall::new(&self.config_json))) 201 | } 202 | 203 | fn get_type(&self) -> Option { 204 | Some(ContextType::HttpContext) 205 | } 206 | } 207 | -------------------------------------------------------------------------------- /rate-limit-filter/src/rate_limiter/mod.rs: -------------------------------------------------------------------------------- 1 | mod rate_limiter; 2 | 3 | pub use rate_limiter::*; 4 | -------------------------------------------------------------------------------- /rate-limit-filter/src/rate_limiter/rate_limiter.rs: -------------------------------------------------------------------------------- 1 | use proxy_wasm; 2 | 3 | use proxy_wasm::types::*; 4 | use serde::{Deserialize, Serialize}; 5 | 6 | #[derive(Debug, Serialize, Deserialize, Clone)] 7 | pub struct RateLimiter { 8 | // Tracks time 9 | pub min: i32, 10 | // Tracks number of calls made 11 | pub count: u32, 12 | // stores a key(username according to example) 13 | pub key: String, 14 | } 15 | 16 | impl RateLimiter { 17 | fn new(key: &String, _plan: &String) -> Self { 18 | Self { 19 | min: -1, 20 | count: 0, 21 | key: key.clone(), 22 | } 23 | } 24 | // Get key and plan from proxy_wasm shared data store (username+plan name) 25 | pub fn get(key: &String, plan: &String) -> Self { 26 | if let Ok(data) = proxy_wasm::hostcalls::get_shared_data(&key.clone()) { 27 | if let Some(data) = data.0 { 28 | let data: Option = bincode::deserialize(&data).unwrap_or(None); 29 | if let Some(obj) = data { 30 | return obj; 31 | } 32 | } 33 | } 34 | return Self::new(&key, &plan); 35 | } 36 | // Set key and plan in proxy_wasm shared data store (username+plan name) 37 | pub fn set(&self) { 38 | let target: Option = Some(self.clone()); 39 | let encoded: Vec = bincode::serialize(&target).unwrap(); 40 | proxy_wasm::hostcalls::set_shared_data(&self.key.clone(), Some(&encoded), None).ok(); 41 | } 42 | // Update time (minute by minute) and increment count 43 | pub fn update(&mut self, time: i32) -> u32 { 44 | if self.min != time { 45 | self.min = time; 46 | self.count = 0; 47 | } 48 | self.count += 1; 49 | proxy_wasm::hostcalls::log(LogLevel::Debug, format!("Obj {:?} ", self.count).as_str()).ok(); 50 | self.count 51 | } 52 | } 53 | -------------------------------------------------------------------------------- /web/.gitignore: -------------------------------------------------------------------------------- 1 | .DS_Store 2 | node_modules 3 | /dist 4 | 5 | # local env files 6 | .env.local 7 | .env.*.local 8 | 9 | # Log files 10 | npm-debug.log* 11 | yarn-debug.log* 12 | yarn-error.log* 13 | 14 | # Editor directories and files 15 | .idea 16 | .vscode 17 | *.suo 18 | *.ntvs* 19 | *.njsproj 20 | *.sln 21 | *.sw? 22 | -------------------------------------------------------------------------------- /web/Dockerfile: -------------------------------------------------------------------------------- 1 | FROM node:alpine 2 | 3 | # install simple http server for serving static content 4 | RUN npm install -g http-server 5 | 6 | # make the 'app' folder the current working directory 7 | WORKDIR /app 8 | 9 | # copy project files and folders to the current working directory (i.e. 'app' folder) 10 | COPY . . 11 | 12 | # install dependencies and build app for production with minification 13 | RUN npm install 14 | RUN npm run build 15 | 16 | EXPOSE 8080 17 | CMD [ "http-server", "dist" ] 18 | -------------------------------------------------------------------------------- /web/README.md: -------------------------------------------------------------------------------- 1 | # web 2 | 3 | ## Project setup 4 | ``` 5 | yarn install 6 | ``` 7 | 8 | ### Compiles and hot-reloads for development 9 | ``` 10 | yarn serve 11 | ``` 12 | 13 | ### Compiles and minifies for production 14 | ``` 15 | yarn build 16 | ``` 17 | 18 | ### Lints and fixes files 19 | ``` 20 | yarn lint 21 | ``` 22 | 23 | ### Customize configuration 24 | See [Configuration Reference](https://cli.vuejs.org/config/). 25 | -------------------------------------------------------------------------------- /web/babel.config.js: -------------------------------------------------------------------------------- 1 | module.exports = { 2 | presets: [ 3 | '@vue/cli-plugin-babel/preset' 4 | ] 5 | } 6 | -------------------------------------------------------------------------------- /web/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "Hub", 3 | "version": "0.1.0", 4 | "private": true, 5 | "scripts": { 6 | "serve": "vue-cli-service serve", 7 | "build": "vue-cli-service build", 8 | "lint": "vue-cli-service lint" 9 | }, 10 | "dependencies": { 11 | "axios": "^0.21.1", 12 | "core-js": "^3.6.4", 13 | "vue": "^2.6.11", 14 | "vue-router": "^3.1.6", 15 | "vuetify": "^2.2.11" 16 | }, 17 | "devDependencies": { 18 | "@vue/cli-plugin-babel": "~4.3.0", 19 | "@vue/cli-plugin-eslint": "~4.3.0", 20 | "@vue/cli-plugin-router": "~4.3.0", 21 | "@vue/cli-service": "~4.3.0", 22 | "babel-eslint": "^10.1.0", 23 | "eslint": "^6.7.2", 24 | "eslint-plugin-vue": "^6.2.2", 25 | "sass": "^1.19.0", 26 | "sass-loader": "^8.0.0", 27 | "vue-cli-plugin-vuetify": "~2.0.5", 28 | "vue-template-compiler": "^2.6.11", 29 | "vuetify-loader": "^1.3.0" 30 | }, 31 | "eslintConfig": { 32 | "root": true, 33 | "env": { 34 | "node": true 35 | }, 36 | "extends": [ 37 | "plugin:vue/essential", 38 | "eslint:recommended" 39 | ], 40 | "parserOptions": { 41 | "parser": "babel-eslint" 42 | }, 43 | "rules": {} 44 | }, 45 | "browserslist": [ 46 | "> 1%", 47 | "last 2 versions", 48 | "not dead" 49 | ] 50 | } 51 | -------------------------------------------------------------------------------- /web/public/favicon.ico: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/layer5io/image-hub/626ca0c1782cdb9cd5c07ba2cfe7af33da668812/web/public/favicon.ico -------------------------------------------------------------------------------- /web/public/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | <%= htmlWebpackPlugin.options.title %> 9 | 10 | 11 | 12 | 13 | 16 |
17 | 18 | 19 | 20 | -------------------------------------------------------------------------------- /web/src/App.vue: -------------------------------------------------------------------------------- 1 | 41 | 42 | 57 | -------------------------------------------------------------------------------- /web/src/assets/layer5-image-hub-white.ai: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/layer5io/image-hub/626ca0c1782cdb9cd5c07ba2cfe7af33da668812/web/src/assets/layer5-image-hub-white.ai -------------------------------------------------------------------------------- /web/src/assets/layer5-image-hub-white.svg: -------------------------------------------------------------------------------- 1 | 2 | 3 | 5 | 22 | 42 | 43 | 44 | 45 | 46 | 47 | 49 | 50 | 51 | 52 | 53 | 56 | 57 | 58 | 59 | 60 | 61 | 62 | 66 | 67 | 68 | 69 | 70 | 77 | 78 | 79 | 80 | 81 | 82 | 83 | 86 | 87 | 88 | 89 | 90 | 95 | 96 | 97 | 98 | 99 | 100 | 101 | 105 | 106 | 107 | 108 | 109 | 117 | 118 | 119 | 120 | 121 | 122 | 123 | 127 | 128 | 129 | 130 | 131 | 139 | 140 | 141 | 142 | 143 | 144 | 145 | 148 | 149 | 150 | 151 | 152 | 157 | 158 | 159 | 160 | 161 | 162 | 163 | 166 | 167 | 168 | 169 | 170 | 177 | 178 | 179 | -------------------------------------------------------------------------------- /web/src/assets/layer5-image-hub.ai: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/layer5io/image-hub/626ca0c1782cdb9cd5c07ba2cfe7af33da668812/web/src/assets/layer5-image-hub.ai -------------------------------------------------------------------------------- /web/src/assets/layer5-image-hub.svg: -------------------------------------------------------------------------------- 1 | 2 | 3 | 5 | 22 | 42 | 43 | 44 | 45 | 46 | 47 | 49 | 50 | 51 | 52 | 53 | 56 | 57 | 58 | 59 | 60 | 61 | 62 | 66 | 67 | 68 | 69 | 70 | 77 | 78 | 79 | 80 | 81 | 82 | 83 | 86 | 87 | 88 | 89 | 90 | 95 | 96 | 97 | 98 | 99 | 100 | 101 | 105 | 106 | 107 | 108 | 109 | 117 | 118 | 119 | 120 | 121 | 122 | 123 | 127 | 128 | 129 | 130 | 131 | 139 | 140 | 141 | 142 | 143 | 144 | 145 | 148 | 149 | 150 | 151 | 152 | 157 | 158 | 159 | 160 | 161 | 162 | 163 | 166 | 167 | 168 | 169 | 170 | 177 | 178 | 179 | -------------------------------------------------------------------------------- /web/src/main.js: -------------------------------------------------------------------------------- 1 | import Vue from 'vue' 2 | import App from './App.vue' 3 | import vuetify from './plugins/vuetify'; 4 | import router from './router' 5 | 6 | Vue.config.productionTip = false 7 | 8 | Vue.prototype.$BASE_URL = "" 9 | // Vue.prototype.$BASE_URL = "http://0.0.0.0:9091" 10 | 11 | new Vue({ 12 | vuetify, 13 | router, 14 | render: h => h(App) 15 | }).$mount('#app') 16 | -------------------------------------------------------------------------------- /web/src/plugins/vuetify.js: -------------------------------------------------------------------------------- 1 | import Vue from 'vue'; 2 | import Vuetify from 'vuetify/lib'; 3 | 4 | Vue.use(Vuetify); 5 | 6 | export default new Vuetify({ 7 | }); 8 | -------------------------------------------------------------------------------- /web/src/router/index.js: -------------------------------------------------------------------------------- 1 | import Vue from 'vue' 2 | import VueRouter from 'vue-router' 3 | 4 | import Hello from '../views/Hello.vue' 5 | import Auth from '../views/Auth.vue' 6 | import Signup from '../views/Signup.vue' 7 | import Upgrade from '../views/Upgrade.vue' 8 | 9 | Vue.use(VueRouter) 10 | 11 | const routes = [ 12 | { 13 | path: '/', 14 | name: 'Hello', 15 | component: Hello 16 | },{ 17 | path: '/login', 18 | name: 'Auth', 19 | component: Auth 20 | },{ 21 | path: '/signup', 22 | name: 'Signup', 23 | component: Signup 24 | },{ 25 | path: '/upgrade', 26 | name: 'Upgrade', 27 | component: Upgrade 28 | } 29 | ] 30 | 31 | const router = new VueRouter({ 32 | // mode: 'history', 33 | // base: process.env.BASE_URL, 34 | routes 35 | }) 36 | 37 | export default router 38 | -------------------------------------------------------------------------------- /web/src/views/Auth.vue: -------------------------------------------------------------------------------- 1 | 67 | 68 | 97 | -------------------------------------------------------------------------------- /web/src/views/Hello.vue: -------------------------------------------------------------------------------- 1 | 89 | 90 | -------------------------------------------------------------------------------- /web/src/views/Signup.vue: -------------------------------------------------------------------------------- 1 | 74 | 75 | 110 | -------------------------------------------------------------------------------- /web/src/views/Upgrade.vue: -------------------------------------------------------------------------------- 1 | 35 | 36 | -------------------------------------------------------------------------------- /web/vue.config.js: -------------------------------------------------------------------------------- 1 | module.exports = { 2 | "transpileDependencies": [ 3 | "vuetify" 4 | ] 5 | } --------------------------------------------------------------------------------