├── .github ├── CODEOWNERS └── workflows │ └── build.yml ├── .gitignore ├── .release ├── ci.hcl ├── release.metadata.hcl └── security-scan.hcl ├── Dockerfile ├── LICENSE ├── Makefile ├── README.md ├── docs └── release.md ├── go.mod ├── handlers.go ├── main.go └── version ├── VERSION └── version.go /.github/CODEOWNERS: -------------------------------------------------------------------------------- 1 | * @hashicorp/consul-core 2 | 3 | # release configuration 4 | /.release/ @hashicorp/release-engineering 5 | /.github/workflows/build.yml @hashicorp/release-engineering 6 | -------------------------------------------------------------------------------- /.github/workflows/build.yml: -------------------------------------------------------------------------------- 1 | name: build 2 | 3 | on: [workflow_dispatch, push] 4 | 5 | env: 6 | PKG_NAME: "http-echo" 7 | 8 | jobs: 9 | get-go-version: 10 | name: "Determine Go toolchain version" 11 | runs-on: ubuntu-latest 12 | outputs: 13 | go-version: ${{ steps.get-go-version.outputs.go-version }} 14 | steps: 15 | - uses: actions/checkout@c85c95e3d7251135ab7dc9ce3241c5835cc595a9 # v3.5.3 16 | - uses: actions/setup-go@93397bea11091df50f3d7e59dc26a7711a8bcfbe # v4.1.0 17 | with: 18 | # This is the minimum required version. Go 1.21+ should pull in new 19 | # toolchains as indicated in go.mod. 20 | go-version: '1.21' 21 | - name: Determine Go version 22 | id: get-go-version 23 | # With go1.21+, we can use `go version` to print out the exact toolchain that will be used 24 | run: | 25 | echo "Building with Go $(go version | awk '{print $3}' | sed -e 's/^go//')" 26 | echo "go-version=$(go version | awk '{print $3}' | sed -e 's/^go//')" >> $GITHUB_OUTPUT 27 | 28 | set-product-version: 29 | runs-on: ubuntu-latest 30 | outputs: 31 | product-version: ${{ steps.set-product-version.outputs.product-version }} 32 | product-base-version: ${{ steps.set-product-version.outputs.base-product-version }} 33 | product-prerelease-version: ${{ steps.set-product-version.outputs.prerelease-product-version }} 34 | steps: 35 | - uses: actions/checkout@c85c95e3d7251135ab7dc9ce3241c5835cc595a9 # v3.5.3 36 | - name: Set Product version 37 | id: set-product-version 38 | uses: hashicorp/actions-set-product-version@v1 39 | 40 | generate-metadata-file: 41 | needs: set-product-version 42 | runs-on: ubuntu-latest 43 | outputs: 44 | filepath: ${{ steps.generate-metadata-file.outputs.filepath }} 45 | steps: 46 | - name: "Checkout directory" 47 | uses: actions/checkout@c85c95e3d7251135ab7dc9ce3241c5835cc595a9 # v3.5.3 48 | - name: Generate metadata file 49 | id: generate-metadata-file 50 | uses: hashicorp/actions-generate-metadata@v1 51 | with: 52 | version: ${{ needs.set-product-version.outputs.product-version }} 53 | product: ${{ env.PKG_NAME }} 54 | repositoryOwner: "hashicorp" 55 | repository: "http-echo" 56 | - uses: actions/upload-artifact@0b7f8abb1508181956e8e162db84b466c27e18ce # v3.1.2 57 | with: 58 | name: metadata.json 59 | path: ${{ steps.generate-metadata-file.outputs.filepath }} 60 | 61 | build-other: 62 | needs: 63 | - get-go-version 64 | - set-product-version 65 | runs-on: ubuntu-latest 66 | strategy: 67 | fail-fast: true 68 | matrix: 69 | goos: [windows] 70 | goarch: ["386", "amd64"] 71 | 72 | name: Go ${{ needs.get-go-version.outputs.go-version }} ${{ matrix.goos }} ${{ matrix.goarch }} build 73 | 74 | steps: 75 | - uses: actions/checkout@c85c95e3d7251135ab7dc9ce3241c5835cc595a9 # v3.5.3 76 | 77 | - uses: hashicorp/actions-go-build@v0.1.7 78 | env: 79 | BASE_VERSION: ${{ needs.set-product-version.outputs.product-base-version }} 80 | PRERELEASE_VERSION: ${{ needs.set-product-version.outputs.product-prerelease-version}} 81 | METADATA_VERSION: ${{ env.METADATA }} 82 | with: 83 | product_name: ${{ env.PKG_NAME }} 84 | product_version: ${{ needs.set-product-version.outputs.product-version }} 85 | go_version: ${{ needs.get-go-version.outputs.go-version }} 86 | os: ${{ matrix.goos }} 87 | arch: ${{ matrix.goarch }} 88 | reproducible: report 89 | instructions: | 90 | cp LICENSE $TARGET_DIR/LICENSE.txt 91 | make build 92 | 93 | build-linux: 94 | needs: 95 | - get-go-version 96 | - set-product-version 97 | runs-on: ubuntu-latest 98 | strategy: 99 | matrix: 100 | goos: [linux] 101 | goarch: ["arm", "arm64", "386", "amd64"] 102 | 103 | fail-fast: true 104 | 105 | name: Go ${{ needs.get-go-version.outputs.go-version }} ${{ matrix.goos }} ${{ matrix.goarch }} build 106 | 107 | steps: 108 | - uses: actions/checkout@c85c95e3d7251135ab7dc9ce3241c5835cc595a9 # v3.5.3 109 | 110 | - uses: hashicorp/actions-go-build@v0.1.7 111 | env: 112 | BASE_VERSION: ${{ needs.set-product-version.outputs.product-base-version }} 113 | PRERELEASE_VERSION: ${{ needs.set-product-version.outputs.product-prerelease-version}} 114 | METADATA_VERSION: ${{ env.METADATA }} 115 | with: 116 | product_name: ${{ env.PKG_NAME }} 117 | product_version: ${{ needs.set-product-version.outputs.product-version }} 118 | go_version: ${{ needs.get-go-version.outputs.go-version }} 119 | os: ${{ matrix.goos }} 120 | arch: ${{ matrix.goarch }} 121 | reproducible: report 122 | instructions: | 123 | cp LICENSE $TARGET_DIR/LICENSE.txt 124 | make build 125 | 126 | build-darwin: 127 | needs: 128 | - get-go-version 129 | - set-product-version 130 | runs-on: macos-latest 131 | strategy: 132 | matrix: 133 | goos: [darwin] 134 | goarch: ["amd64", "arm64"] 135 | fail-fast: true 136 | 137 | name: Go ${{ needs.get-go-version.outputs.go-version }} ${{ matrix.goos }} ${{ matrix.goarch }} build 138 | 139 | env: 140 | GOOS: ${{ matrix.goos }} 141 | GOARCH: ${{ matrix.goarch }} 142 | 143 | steps: 144 | - uses: actions/checkout@c85c95e3d7251135ab7dc9ce3241c5835cc595a9 # v3.5.3 145 | 146 | - uses: hashicorp/actions-go-build@v0.1.7 147 | env: 148 | BASE_VERSION: ${{ needs.set-product-version.outputs.product-base-version }} 149 | PRERELEASE_VERSION: ${{ needs.set-product-version.outputs.product-prerelease-version}} 150 | METADATA_VERSION: ${{ env.METADATA }} 151 | with: 152 | product_name: ${{ env.PKG_NAME }} 153 | product_version: ${{ needs.set-product-version.outputs.product-version }} 154 | go_version: ${{ needs.get-go-version.outputs.go-version }} 155 | os: ${{ matrix.goos }} 156 | arch: ${{ matrix.goarch }} 157 | reproducible: report 158 | instructions: | 159 | cp LICENSE $TARGET_DIR/LICENSE.txt 160 | make build 161 | 162 | build-docker-default: 163 | name: Docker ${{ matrix.arch }} default release build 164 | needs: 165 | - set-product-version 166 | - build-linux 167 | runs-on: ubuntu-latest 168 | strategy: 169 | matrix: 170 | arch: ["arm64", "amd64"] 171 | env: 172 | repo: ${{ github.event.repository.name }} 173 | version: ${{ needs.set-product-version.outputs.product-version }} 174 | 175 | steps: 176 | - uses: actions/checkout@c85c95e3d7251135ab7dc9ce3241c5835cc595a9 # v3.5.3 177 | - name: Docker Build (Action) 178 | uses: hashicorp/actions-docker-build@v1 179 | with: 180 | smoke_test: | 181 | TEST_VERSION="$(docker run "${IMAGE_NAME}" -version | awk '/http-echo/{print $2}' | sed s/v//)" 182 | if [ "${TEST_VERSION}" != "${version}" ]; then 183 | echo "Test FAILED" 184 | echo "Test Version: ${TEST_VERSION}" 185 | echo "Version: ${version}" 186 | exit 1 187 | fi 188 | echo "Test PASSED" 189 | version: ${{ env.version }} 190 | target: default 191 | arch: ${{ matrix.arch }} 192 | tags: | 193 | docker.io/hashicorp/${{env.repo}}:${{env.version}} 194 | dev_tags: | 195 | docker.io/hashicorppreview/${{ env.repo }}:${{ env.version }}-dev 196 | docker.io/hashicorppreview/${{ env.repo }}:${{ env.version }}-${{ github.sha }} 197 | 198 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | ### Custom ### 2 | /bin 3 | /pkg 4 | dist/ 5 | 6 | ### Golang ### 7 | # Compiled Object files, Static and Dynamic libs (Shared Objects) 8 | *.o 9 | *.a 10 | *.so 11 | 12 | # Folders 13 | _obj 14 | _test 15 | 16 | # Architecture specific extensions/prefixes 17 | *.[568vq] 18 | [568vq].out 19 | 20 | *.cgo1.go 21 | *.cgo2.c 22 | _cgo_defun.c 23 | _cgo_gotypes.go 24 | _cgo_export.* 25 | 26 | _testmain.go 27 | 28 | *.exe 29 | *.test 30 | .proc 31 | *.conf 32 | 33 | # IDE files 34 | *.iml 35 | *.idea 36 | 37 | ### OSX ### 38 | *.DS_Store 39 | .AppleDouble 40 | .LSOverride 41 | 42 | # Icon must end with two \r 43 | Icon 44 | # Thumbnails 45 | ._* 46 | # Files that might appear in the root of a volume 47 | .DocumentRevisions-V100 48 | .fseventsd 49 | .Spotlight-V100 50 | .TemporaryItems 51 | .Trashes 52 | .VolumeIcon.icns 53 | .com.apple.timemachine.donotpresent 54 | # Directories potentially created on remote AFP share 55 | .AppleDB 56 | .AppleDesktop 57 | Network Trash Folder 58 | Temporary Items 59 | .apdisk 60 | -------------------------------------------------------------------------------- /.release/ci.hcl: -------------------------------------------------------------------------------- 1 | schema = "1" 2 | 3 | project "http-echo" { 4 | // the team key is not used by CRT currently 5 | team = "team-consul" 6 | slack { 7 | notification_channel = "C0253EQ5B40" 8 | } 9 | github { 10 | organization = "hashicorp" 11 | repository = "http-echo" 12 | // An allow-list of branch names where artifacts are built. Note that wildcards are accepted! 13 | // Artifacts built from these branches will be processed through CRT and get into a 14 | // "release ready" state. 15 | release_branches = [ 16 | "main", 17 | "release/**" 18 | ] 19 | } 20 | } 21 | 22 | event "merge" { 23 | // "entrypoint" to use if build is not run automatically 24 | // i.e. send "merge" complete signal to orchestrator to trigger build 25 | } 26 | 27 | event "build" { 28 | depends = ["merge"] 29 | action "build" { 30 | organization = "hashicorp" 31 | repository = "http-echo" 32 | workflow = "build" 33 | } 34 | } 35 | 36 | // Read more about what the `prepare` workflow does here: 37 | // https://hashicorp.atlassian.net/wiki/spaces/RELENG/pages/2489712686/Dec+7th+2022+-+Introducing+the+new+Prepare+workflow 38 | event "prepare" { 39 | depends = ["build"] 40 | 41 | action "prepare" { 42 | organization = "hashicorp" 43 | repository = "crt-workflows-common" 44 | workflow = "prepare" 45 | depends = ["build"] 46 | } 47 | 48 | notification { 49 | on = "fail" 50 | } 51 | } 52 | 53 | ## These are promotion and post-publish events 54 | ## they should be added to the end of the file after the verify event stanza. 55 | 56 | event "trigger-staging" { 57 | // This event is dispatched by the bob trigger-promotion command 58 | // and is required - do not delete. 59 | } 60 | 61 | event "promote-staging" { 62 | depends = ["trigger-staging"] 63 | action "promote-staging" { 64 | organization = "hashicorp" 65 | repository = "crt-workflows-common" 66 | workflow = "promote-staging" 67 | config = "release.metadata.hcl" 68 | } 69 | 70 | notification { 71 | on = "always" 72 | } 73 | } 74 | 75 | event "promote-staging-docker" { 76 | depends = ["promote-staging"] 77 | action "promote-staging-docker" { 78 | organization = "hashicorp" 79 | repository = "crt-workflows-common" 80 | workflow = "promote-staging-docker" 81 | } 82 | 83 | notification { 84 | on = "always" 85 | } 86 | } 87 | 88 | event "trigger-production" { 89 | // This event is dispatched by the bob trigger-promotion command 90 | // and is required - do not delete. 91 | } 92 | 93 | event "promote-production" { 94 | depends = ["trigger-production"] 95 | action "promote-production" { 96 | organization = "hashicorp" 97 | repository = "crt-workflows-common" 98 | workflow = "promote-production" 99 | } 100 | 101 | notification { 102 | on = "always" 103 | } 104 | } 105 | 106 | event "promote-production-docker" { 107 | depends = ["promote-production"] 108 | action "promote-production-docker" { 109 | organization = "hashicorp" 110 | repository = "crt-workflows-common" 111 | workflow = "promote-production-docker" 112 | } 113 | 114 | notification { 115 | on = "always" 116 | } 117 | } 118 | 119 | 120 | event "bump-version-patch" { 121 | depends = ["promote-production-docker"] 122 | action "bump-version" { 123 | organization = "HashiCorp-RelEng-Dev" 124 | repository = "crt-workflows-common" 125 | workflow = "bump-version" 126 | } 127 | 128 | notification { 129 | on = "fail" 130 | } 131 | } 132 | -------------------------------------------------------------------------------- /.release/release.metadata.hcl: -------------------------------------------------------------------------------- 1 | url_docker_registry_dockerhub = "https://hub.docker.com/r/hashicorp/http-echo" 2 | url_source_repository = "https://github/hashicorp/http-echo" 3 | url_project_website = "https://github/hashicorp/http-echo" 4 | url_license = "https://github.com/hashicorp/http-echo/blob/main/LICENSE" 5 | url_release_notes = "https://github.com/hashicorp/http-echo/releases" 6 | -------------------------------------------------------------------------------- /.release/security-scan.hcl: -------------------------------------------------------------------------------- 1 | container { 2 | dependencies = true 3 | alpine_secdb = true 4 | secrets = true 5 | } 6 | 7 | binary { 8 | secrets = true 9 | go_modules = true 10 | osv = true 11 | oss_index = false 12 | nvd = false 13 | } 14 | -------------------------------------------------------------------------------- /Dockerfile: -------------------------------------------------------------------------------- 1 | # Copyright (c) HashiCorp, Inc. 2 | # SPDX-License-Identifier: MPL-2.0 3 | 4 | FROM gcr.io/distroless/static-debian12:nonroot as default 5 | 6 | # TARGETOS and TARGETARCH are set automatically when --platform is provided. 7 | ARG TARGETOS 8 | ARG TARGETARCH 9 | ARG PRODUCT_VERSION 10 | ARG BIN_NAME 11 | ENV PRODUCT_NAME=$BIN_NAME 12 | 13 | LABEL name="http-echo" \ 14 | maintainer="HashiCorp Consul Team " \ 15 | vendor="HashiCorp" \ 16 | version=$PRODUCT_VERSION \ 17 | release=$PRODUCT_VERSION \ 18 | licenses="MPL-2.0" \ 19 | summary="A test webserver that echos a response. You know, for kids." 20 | 21 | COPY dist/$TARGETOS/$TARGETARCH/$BIN_NAME / 22 | COPY LICENSE /usr/share/doc/$PRODUCT_NAME/LICENSE.txt 23 | 24 | EXPOSE 5678/tcp 25 | 26 | ENV ECHO_TEXT="hello-world" 27 | 28 | ENTRYPOINT ["/http-echo"] 29 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | Copyright (c) 2016 HashiCorp, Inc. 2 | 3 | Mozilla Public License, version 2.0 4 | 5 | 1. Definitions 6 | 7 | 1.1. “Contributor” 8 | 9 | means each individual or legal entity that creates, contributes to the 10 | creation of, or owns Covered Software. 11 | 12 | 1.2. “Contributor Version” 13 | 14 | means the combination of the Contributions of others (if any) used by a 15 | Contributor and that particular Contributor’s Contribution. 16 | 17 | 1.3. “Contribution” 18 | 19 | means Covered Software of a particular Contributor. 20 | 21 | 1.4. “Covered Software” 22 | 23 | means Source Code Form to which the initial Contributor has attached the 24 | notice in Exhibit A, the Executable Form of such Source Code Form, and 25 | Modifications of such Source Code Form, in each case including portions 26 | thereof. 27 | 28 | 1.5. “Incompatible With Secondary Licenses” 29 | means 30 | 31 | a. that the initial Contributor has attached the notice described in 32 | Exhibit B to the Covered Software; or 33 | 34 | b. that the Covered Software was made available under the terms of version 35 | 1.1 or earlier of the License, but not also under the terms of a 36 | Secondary License. 37 | 38 | 1.6. “Executable Form” 39 | 40 | means any form of the work other than Source Code Form. 41 | 42 | 1.7. “Larger Work” 43 | 44 | means a work that combines Covered Software with other material, in a separate 45 | file or files, that is not Covered Software. 46 | 47 | 1.8. “License” 48 | 49 | means this document. 50 | 51 | 1.9. “Licensable” 52 | 53 | means having the right to grant, to the maximum extent possible, whether at the 54 | time of the initial grant or subsequently, any and all of the rights conveyed by 55 | this License. 56 | 57 | 1.10. “Modifications” 58 | 59 | means any of the following: 60 | 61 | a. any file in Source Code Form that results from an addition to, deletion 62 | from, or modification of the contents of Covered Software; or 63 | 64 | b. any new file in Source Code Form that contains any Covered Software. 65 | 66 | 1.11. “Patent Claims” of a Contributor 67 | 68 | means any patent claim(s), including without limitation, method, process, 69 | and apparatus claims, in any patent Licensable by such Contributor that 70 | would be infringed, but for the grant of the License, by the making, 71 | using, selling, offering for sale, having made, import, or transfer of 72 | either its Contributions or its Contributor Version. 73 | 74 | 1.12. “Secondary License” 75 | 76 | means either the GNU General Public License, Version 2.0, the GNU Lesser 77 | General Public License, Version 2.1, the GNU Affero General Public 78 | License, Version 3.0, or any later versions of those licenses. 79 | 80 | 1.13. “Source Code Form” 81 | 82 | means the form of the work preferred for making modifications. 83 | 84 | 1.14. “You” (or “Your”) 85 | 86 | means an individual or a legal entity exercising rights under this 87 | License. For legal entities, “You” includes any entity that controls, is 88 | controlled by, or is under common control with You. For purposes of this 89 | definition, “control” means (a) the power, direct or indirect, to cause 90 | the direction or management of such entity, whether by contract or 91 | otherwise, or (b) ownership of more than fifty percent (50%) of the 92 | outstanding shares or beneficial ownership of such entity. 93 | 94 | 95 | 2. License Grants and Conditions 96 | 97 | 2.1. Grants 98 | 99 | Each Contributor hereby grants You a world-wide, royalty-free, 100 | non-exclusive license: 101 | 102 | a. under intellectual property rights (other than patent or trademark) 103 | Licensable by such Contributor to use, reproduce, make available, 104 | modify, display, perform, distribute, and otherwise exploit its 105 | Contributions, either on an unmodified basis, with Modifications, or as 106 | part of a Larger Work; and 107 | 108 | b. under Patent Claims of such Contributor to make, use, sell, offer for 109 | sale, have made, import, and otherwise transfer either its Contributions 110 | or its Contributor Version. 111 | 112 | 2.2. Effective Date 113 | 114 | The licenses granted in Section 2.1 with respect to any Contribution become 115 | effective for each Contribution on the date the Contributor first distributes 116 | such Contribution. 117 | 118 | 2.3. Limitations on Grant Scope 119 | 120 | The licenses granted in this Section 2 are the only rights granted under this 121 | License. No additional rights or licenses will be implied from the distribution 122 | or licensing of Covered Software under this License. Notwithstanding Section 123 | 2.1(b) above, no patent license is granted by a Contributor: 124 | 125 | a. for any code that a Contributor has removed from Covered Software; or 126 | 127 | b. for infringements caused by: (i) Your and any other third party’s 128 | modifications of Covered Software, or (ii) the combination of its 129 | Contributions with other software (except as part of its Contributor 130 | Version); or 131 | 132 | c. under Patent Claims infringed by Covered Software in the absence of its 133 | Contributions. 134 | 135 | This License does not grant any rights in the trademarks, service marks, or 136 | logos of any Contributor (except as may be necessary to comply with the 137 | notice requirements in Section 3.4). 138 | 139 | 2.4. Subsequent Licenses 140 | 141 | No Contributor makes additional grants as a result of Your choice to 142 | distribute the Covered Software under a subsequent version of this License 143 | (see Section 10.2) or under the terms of a Secondary License (if permitted 144 | under the terms of Section 3.3). 145 | 146 | 2.5. Representation 147 | 148 | Each Contributor represents that the Contributor believes its Contributions 149 | are its original creation(s) or it has sufficient rights to grant the 150 | rights to its Contributions conveyed by this License. 151 | 152 | 2.6. Fair Use 153 | 154 | This License is not intended to limit any rights You have under applicable 155 | copyright doctrines of fair use, fair dealing, or other equivalents. 156 | 157 | 2.7. Conditions 158 | 159 | Sections 3.1, 3.2, 3.3, and 3.4 are conditions of the licenses granted in 160 | Section 2.1. 161 | 162 | 163 | 3. Responsibilities 164 | 165 | 3.1. Distribution of Source Form 166 | 167 | All distribution of Covered Software in Source Code Form, including any 168 | Modifications that You create or to which You contribute, must be under the 169 | terms of this License. You must inform recipients that the Source Code Form 170 | of the Covered Software is governed by the terms of this License, and how 171 | they can obtain a copy of this License. You may not attempt to alter or 172 | restrict the recipients’ rights in the Source Code Form. 173 | 174 | 3.2. Distribution of Executable Form 175 | 176 | If You distribute Covered Software in Executable Form then: 177 | 178 | a. such Covered Software must also be made available in Source Code Form, 179 | as described in Section 3.1, and You must inform recipients of the 180 | Executable Form how they can obtain a copy of such Source Code Form by 181 | reasonable means in a timely manner, at a charge no more than the cost 182 | of distribution to the recipient; and 183 | 184 | b. You may distribute such Executable Form under the terms of this License, 185 | or sublicense it under different terms, provided that the license for 186 | the Executable Form does not attempt to limit or alter the recipients’ 187 | rights in the Source Code Form under this License. 188 | 189 | 3.3. Distribution of a Larger Work 190 | 191 | You may create and distribute a Larger Work under terms of Your choice, 192 | provided that You also comply with the requirements of this License for the 193 | Covered Software. If the Larger Work is a combination of Covered Software 194 | with a work governed by one or more Secondary Licenses, and the Covered 195 | Software is not Incompatible With Secondary Licenses, this License permits 196 | You to additionally distribute such Covered Software under the terms of 197 | such Secondary License(s), so that the recipient of the Larger Work may, at 198 | their option, further distribute the Covered Software under the terms of 199 | either this License or such Secondary License(s). 200 | 201 | 3.4. Notices 202 | 203 | You may not remove or alter the substance of any license notices (including 204 | copyright notices, patent notices, disclaimers of warranty, or limitations 205 | of liability) contained within the Source Code Form of the Covered 206 | Software, except that You may alter any license notices to the extent 207 | required to remedy known factual inaccuracies. 208 | 209 | 3.5. Application of Additional Terms 210 | 211 | You may choose to offer, and to charge a fee for, warranty, support, 212 | indemnity or liability obligations to one or more recipients of Covered 213 | Software. However, You may do so only on Your own behalf, and not on behalf 214 | of any Contributor. You must make it absolutely clear that any such 215 | warranty, support, indemnity, or liability obligation is offered by You 216 | alone, and You hereby agree to indemnify every Contributor for any 217 | liability incurred by such Contributor as a result of warranty, support, 218 | indemnity or liability terms You offer. You may include additional 219 | disclaimers of warranty and limitations of liability specific to any 220 | jurisdiction. 221 | 222 | 4. Inability to Comply Due to Statute or Regulation 223 | 224 | If it is impossible for You to comply with any of the terms of this License 225 | with respect to some or all of the Covered Software due to statute, judicial 226 | order, or regulation then You must: (a) comply with the terms of this License 227 | to the maximum extent possible; and (b) describe the limitations and the code 228 | they affect. Such description must be placed in a text file included with all 229 | distributions of the Covered Software under this License. Except to the 230 | extent prohibited by statute or regulation, such description must be 231 | sufficiently detailed for a recipient of ordinary skill to be able to 232 | understand it. 233 | 234 | 5. Termination 235 | 236 | 5.1. The rights granted under this License will terminate automatically if You 237 | fail to comply with any of its terms. However, if You become compliant, 238 | then the rights granted under this License from a particular Contributor 239 | are reinstated (a) provisionally, unless and until such Contributor 240 | explicitly and finally terminates Your grants, and (b) on an ongoing basis, 241 | if such Contributor fails to notify You of the non-compliance by some 242 | reasonable means prior to 60 days after You have come back into compliance. 243 | Moreover, Your grants from a particular Contributor are reinstated on an 244 | ongoing basis if such Contributor notifies You of the non-compliance by 245 | some reasonable means, this is the first time You have received notice of 246 | non-compliance with this License from such Contributor, and You become 247 | compliant prior to 30 days after Your receipt of the notice. 248 | 249 | 5.2. If You initiate litigation against any entity by asserting a patent 250 | infringement claim (excluding declaratory judgment actions, counter-claims, 251 | and cross-claims) alleging that a Contributor Version directly or 252 | indirectly infringes any patent, then the rights granted to You by any and 253 | all Contributors for the Covered Software under Section 2.1 of this License 254 | shall terminate. 255 | 256 | 5.3. In the event of termination under Sections 5.1 or 5.2 above, all end user 257 | license agreements (excluding distributors and resellers) which have been 258 | validly granted by You or Your distributors under this License prior to 259 | termination shall survive termination. 260 | 261 | 6. Disclaimer of Warranty 262 | 263 | Covered Software is provided under this License on an “as is” basis, without 264 | warranty of any kind, either expressed, implied, or statutory, including, 265 | without limitation, warranties that the Covered Software is free of defects, 266 | merchantable, fit for a particular purpose or non-infringing. The entire 267 | risk as to the quality and performance of the Covered Software is with You. 268 | Should any Covered Software prove defective in any respect, You (not any 269 | Contributor) assume the cost of any necessary servicing, repair, or 270 | correction. This disclaimer of warranty constitutes an essential part of this 271 | License. No use of any Covered Software is authorized under this License 272 | except under this disclaimer. 273 | 274 | 7. Limitation of Liability 275 | 276 | Under no circumstances and under no legal theory, whether tort (including 277 | negligence), contract, or otherwise, shall any Contributor, or anyone who 278 | distributes Covered Software as permitted above, be liable to You for any 279 | direct, indirect, special, incidental, or consequential damages of any 280 | character including, without limitation, damages for lost profits, loss of 281 | goodwill, work stoppage, computer failure or malfunction, or any and all 282 | other commercial damages or losses, even if such party shall have been 283 | informed of the possibility of such damages. This limitation of liability 284 | shall not apply to liability for death or personal injury resulting from such 285 | party’s negligence to the extent applicable law prohibits such limitation. 286 | Some jurisdictions do not allow the exclusion or limitation of incidental or 287 | consequential damages, so this exclusion and limitation may not apply to You. 288 | 289 | 8. Litigation 290 | 291 | Any litigation relating to this License may be brought only in the courts of 292 | a jurisdiction where the defendant maintains its principal place of business 293 | and such litigation shall be governed by laws of that jurisdiction, without 294 | reference to its conflict-of-law provisions. Nothing in this Section shall 295 | prevent a party’s ability to bring cross-claims or counter-claims. 296 | 297 | 9. Miscellaneous 298 | 299 | This License represents the complete agreement concerning the subject matter 300 | hereof. If any provision of this License is held to be unenforceable, such 301 | provision shall be reformed only to the extent necessary to make it 302 | enforceable. Any law or regulation which provides that the language of a 303 | contract shall be construed against the drafter shall not be used to construe 304 | this License against a Contributor. 305 | 306 | 307 | 10. Versions of the License 308 | 309 | 10.1. New Versions 310 | 311 | Mozilla Foundation is the license steward. Except as provided in Section 312 | 10.3, no one other than the license steward has the right to modify or 313 | publish new versions of this License. Each version will be given a 314 | distinguishing version number. 315 | 316 | 10.2. Effect of New Versions 317 | 318 | You may distribute the Covered Software under the terms of the version of 319 | the License under which You originally received the Covered Software, or 320 | under the terms of any subsequent version published by the license 321 | steward. 322 | 323 | 10.3. Modified Versions 324 | 325 | If you create software not governed by this License, and you want to 326 | create a new license for such software, you may create and use a modified 327 | version of this License if you rename the license and remove any 328 | references to the name of the license steward (except to note that such 329 | modified license differs from this License). 330 | 331 | 10.4. Distributing Source Code Form that is Incompatible With Secondary Licenses 332 | If You choose to distribute Source Code Form that is Incompatible With 333 | Secondary Licenses under the terms of this version of the License, the 334 | notice described in Exhibit B of this License must be attached. 335 | 336 | Exhibit A - Source Code Form License Notice 337 | 338 | This Source Code Form is subject to the 339 | terms of the Mozilla Public License, v. 340 | 2.0. If a copy of the MPL was not 341 | distributed with this file, You can 342 | obtain one at 343 | http://mozilla.org/MPL/2.0/. 344 | 345 | If it is not possible or desirable to put the notice in a particular file, then 346 | You may include the notice in a location (such as a LICENSE file in a relevant 347 | directory) where a recipient would be likely to look for such a notice. 348 | 349 | You may add additional accurate notices of copyright ownership. 350 | 351 | Exhibit B - “Incompatible With Secondary Licenses” Notice 352 | 353 | This Source Code Form is “Incompatible 354 | With Secondary Licenses”, as defined by 355 | the Mozilla Public License, v. 2.0. 356 | 357 | -------------------------------------------------------------------------------- /Makefile: -------------------------------------------------------------------------------- 1 | # Metadata about this makefile and position 2 | MKFILE_PATH := $(lastword $(MAKEFILE_LIST)) 3 | CURRENT_DIR := $(patsubst %/,%,$(dir $(realpath $(MKFILE_PATH)))) 4 | 5 | # Ensure GOPATH 6 | GOPATH ?= $(HOME)/go 7 | GOBIN ?= $(GOPATH)/bin 8 | 9 | # List all our actual files, excluding vendor 10 | GOFILES ?= $(shell go list $(TEST) | grep -v /vendor/) 11 | 12 | # Tags specific for building 13 | GOTAGS ?= 14 | 15 | # Number of procs to use 16 | GOMAXPROCS ?= 4 17 | 18 | # Get the project metadata 19 | GOVERSION := $(shell go version | awk '{print $3}' | sed -e 's/^go//') 20 | PROJECT := $(CURRENT_DIR:$(GOPATH)/src/%=%) 21 | OWNER ?= hashicorp 22 | NAME ?= http-echo 23 | REVISION ?= $(shell git rev-parse --short HEAD) 24 | VERSION := $(shell cat "${CURRENT_DIR}/version/VERSION") 25 | TIMESTAMP := $(shell date) 26 | 27 | # Get local ARCH; on Intel Mac, 'uname -m' returns x86_64 which we turn into amd64. 28 | # Not using 'go env GOOS/GOARCH' here so 'make docker' will work without local Go install. 29 | ARCH ?= $(shell A=$$(uname -m); [ $$A = x86_64 ] && A=amd64; echo $$A) 30 | OS ?= $(shell uname | tr [[:upper:]] [[:lower:]]) 31 | PLATFORM = $(OS)/$(ARCH) 32 | DIST = dist/$(PLATFORM) 33 | BIN = $(DIST)/$(NAME) 34 | 35 | # Default os-arch combination to build 36 | XC_OS ?= darwin linux windows 37 | XC_ARCH ?= amd64 arm64 38 | XC_EXCLUDE ?= 39 | 40 | # List of ldflags 41 | LD_FLAGS ?= \ 42 | -s \ 43 | -w \ 44 | -X 'github.com/hashicorp/http-echo/version.Version=${VERSION}' \ 45 | -X 'github.com/hashicorp/http-echo/version.GitCommit=${REVISION}' \ 46 | -X 'github.com/hashicorp/http-echo/version.Timestamp=${TIMESTAMP}' 47 | 48 | # List of tests to run 49 | TEST ?= ./... 50 | 51 | version: 52 | @echo $(VERSION) 53 | .PHONY: version 54 | 55 | 56 | dist: 57 | mkdir -p $(DIST) 58 | 59 | # build is used for the CRT build.yml workflow. 60 | # Environment variables are populated by hashicorp/actions-go-build, not the makefile. 61 | # https://github.com/hashicorp/actions-go-build 62 | build: 63 | CGO_ENABLED=0 go build \ 64 | -a \ 65 | -o="${BIN_PATH}" \ 66 | -ldflags " \ 67 | -X 'github.com/hashicorp/http-echo/version.Version=${PRODUCT_VERSION}' \ 68 | -X 'github.com/hashicorp/http-echo/version.GitCommit=${PRODUCT_REVISION}' \ 69 | -X 'github.com/hashicorp/http-echo/version.Timestamp=${PRODUCT_REVISION_TIME}' \ 70 | " \ 71 | -tags "${GOTAGS}" \ 72 | -trimpath \ 73 | -buildvcs=false 74 | .PHONY: build 75 | 76 | bin: dist 77 | @echo "==> Building ${BIN}" 78 | @GOARCH=$(ARCH) GOOS=$(OS) CGO_ENABLED=0 go build -trimpath -buildvcs=false -ldflags="$(LD_FLAGS)" -o $(BIN) 79 | .PHONY: bin 80 | 81 | # dev builds and installs the project locally. 82 | dev: bin 83 | cp $(BIN) $(GOBIN)/$(BIN_NAME) 84 | .PHONY: dev 85 | 86 | # Docker Stuff. 87 | export DOCKER_BUILDKIT=1 88 | BUILD_ARGS = BIN_NAME=http-echo PRODUCT_VERSION=$(VERSION) 89 | TAG = $(NAME):local 90 | BA_FLAGS = $(addprefix --build-arg=,$(BUILD_ARGS)) 91 | FLAGS = --platform $(PLATFORM) --tag $(TAG) $(BA_FLAGS) 92 | 93 | # Set OS to linux for all docker/* targets. 94 | docker: OS = linux 95 | 96 | docker: bin 97 | docker build ${FLAGS} . 98 | @echo 'Image built; run "docker run --rm ${TAG}" to try it out.' 99 | .PHONY: docker 100 | 101 | # test runs the test suite. 102 | test: 103 | @echo "==> Testing ${NAME}" 104 | @go test -timeout=30s -parallel=20 -tags="${GOTAGS}" ${GOFILES} ${TESTARGS} 105 | .PHONY: test 106 | 107 | # test-race runs the test suite. 108 | test-race: 109 | @echo "==> Testing ${NAME} (race)" 110 | @go test -timeout=60s -race -tags="${GOTAGS}" ${GOFILES} ${TESTARGS} 111 | .PHONY: test-race 112 | 113 | # clean removes any previous binaries 114 | clean: 115 | @rm -rf "${CURRENT_DIR}/pkg/" 116 | @rm -rf "${CURRENT_DIR}/bin/" 117 | .PHONY: clean 118 | 119 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | http-echo 2 | ========= 3 | HTTP Echo is a small go web server that serves the contents it was started with 4 | as an HTML page. 5 | 6 | The default port is 5678, but this is configurable via the `-listen` flag: 7 | 8 | ``` 9 | http-echo -listen=:8080 -text="hello world" 10 | ``` 11 | 12 | Then visit http://localhost:8080/ in your browser. 13 | -------------------------------------------------------------------------------- /docs/release.md: -------------------------------------------------------------------------------- 1 | # Releasing `http-echo` 2 | 3 | This repository uses HashiCorp's internal CRT process for releasing. 4 | IYKYK. 5 | 6 | ## Prepartion 7 | 1. You have the the `bob` CLI installed 8 | 1. You have all of the necessary rights that you would need to perform a Consul core release. 9 | See those docs for more information. 10 | 1. The commit you intend to release from `main` has passed the CRT `build` and `prepare` workflows. 11 | 12 | ## Promote to staging 13 | 14 | ```bash 15 | bob trigger-promotion \ 16 | --product-name=http-echo \ 17 | --repo=http-echo \ 18 | --product-version="" \ 19 | --sha="" \ 20 | --environment="http-echo-oss" \ 21 | --slack-channel="C0253EQ5B40" \ 22 | --org="hashicorp" \ 23 | --branch "main" \ 24 | staging 25 | ``` 26 | 27 | ## Promote to production 28 | ```bash 29 | bob trigger-promotion \ 30 | --product-name=http-echo \ 31 | --repo=http-echo \ 32 | --product-version="" \ 33 | --sha="" \ 34 | --environment="http-echo-oss" \ 35 | --slack-channel="C0253EQ5B40" \ 36 | --org="hashicorp" \ 37 | --branch "main" \ 38 | production 39 | ``` 40 | 41 | ## Edit the GH Release 42 | 43 | Manually edit the [new release page in GitHub](https://github.com/hashicorp/http-echo/releases/latest) to point to the release artifacts: 44 | 45 | ``` 46 | [Binaries can be downloaded here](https://releases.hashicorp.com/http-echo/${insert your version here}/). 47 | ``` 48 | -------------------------------------------------------------------------------- /go.mod: -------------------------------------------------------------------------------- 1 | module github.com/hashicorp/http-echo 2 | 3 | go 1.21.0 4 | 5 | toolchain go1.21.1 6 | -------------------------------------------------------------------------------- /handlers.go: -------------------------------------------------------------------------------- 1 | // Copyright (c) HashiCorp, Inc. 2 | // SPDX-License-Identifier: MPL-2.0 3 | 4 | package main 5 | 6 | import ( 7 | "fmt" 8 | "io" 9 | "net/http" 10 | "time" 11 | 12 | "github.com/hashicorp/http-echo/version" 13 | ) 14 | 15 | const ( 16 | httpHeaderAppName string = "X-App-Name" 17 | httpHeaderAppVersion string = "X-App-Version" 18 | 19 | httpLogDateFormat string = "2006/01/02 15:04:05" 20 | httpLogFormat string = "%v %s %s \"%s %s %s\" %d %d \"%s\" %v\n" 21 | ) 22 | 23 | // withAppHeaders adds application headers such as X-App-Version and X-App-Name. 24 | func withAppHeaders(c int, h http.HandlerFunc) http.HandlerFunc { 25 | return func(w http.ResponseWriter, r *http.Request) { 26 | w.Header().Set(httpHeaderAppName, version.Name) 27 | w.Header().Set(httpHeaderAppVersion, version.Version) 28 | w.WriteHeader(c) 29 | h(w, r) 30 | } 31 | } 32 | 33 | // metaResponseWriter is a response writer that saves information about the 34 | // response for logging. 35 | type metaResponseWriter struct { 36 | writer http.ResponseWriter 37 | status int 38 | length int 39 | } 40 | 41 | // Header implements the http.ResponseWriter interface. 42 | func (w *metaResponseWriter) Header() http.Header { 43 | return w.writer.Header() 44 | } 45 | 46 | // WriteHeader implements the http.ResponseWriter interface. 47 | func (w *metaResponseWriter) WriteHeader(s int) { 48 | w.status = s 49 | w.writer.WriteHeader(s) 50 | } 51 | 52 | // Write implements the http.ResponseWriter interface. 53 | func (w *metaResponseWriter) Write(b []byte) (int, error) { 54 | if w.status == 0 { 55 | w.status = http.StatusOK 56 | } 57 | w.length = len(b) 58 | return w.writer.Write(b) 59 | } 60 | 61 | // httpLog accepts an io object and logs the request and response objects to the 62 | // given io.Writer. 63 | func httpLog(out io.Writer, h http.HandlerFunc) http.HandlerFunc { 64 | return func(w http.ResponseWriter, r *http.Request) { 65 | var mrw metaResponseWriter 66 | mrw.writer = w 67 | 68 | defer func(start time.Time) { 69 | status := mrw.status 70 | length := mrw.length 71 | end := time.Now() 72 | dur := end.Sub(start) 73 | fmt.Fprintf(out, httpLogFormat, 74 | end.Format(httpLogDateFormat), 75 | r.Host, r.RemoteAddr, r.Method, r.URL.Path, r.Proto, 76 | status, length, r.UserAgent(), dur) 77 | }(time.Now()) 78 | 79 | h(&mrw, r) 80 | } 81 | } 82 | -------------------------------------------------------------------------------- /main.go: -------------------------------------------------------------------------------- 1 | // Copyright (c) HashiCorp, Inc. 2 | // SPDX-License-Identifier: MPL-2.0 3 | 4 | package main 5 | 6 | import ( 7 | "context" 8 | "flag" 9 | "fmt" 10 | "log" 11 | "net/http" 12 | "os" 13 | "os/signal" 14 | "syscall" 15 | "time" 16 | 17 | "github.com/hashicorp/http-echo/version" 18 | ) 19 | 20 | var ( 21 | listenFlag = flag.String("listen", ":5678", "address and port to listen") 22 | textFlag = flag.String("text", "", "text to put on the webpage") 23 | versionFlag = flag.Bool("version", false, "display version information") 24 | statusFlag = flag.Int("status-code", 200, "http response code, e.g.: 200") 25 | 26 | // stdoutW and stderrW are for overriding in test. 27 | stdoutW = os.Stdout 28 | stderrW = os.Stderr 29 | ) 30 | 31 | func main() { 32 | flag.Parse() 33 | 34 | // Asking for the version? 35 | if *versionFlag { 36 | fmt.Fprintln(stdoutW, version.HumanVersion) 37 | os.Exit(0) 38 | } 39 | 40 | // Get text to echo from env var or flag 41 | echoText := os.Getenv("ECHO_TEXT") 42 | if *textFlag != "" { 43 | echoText = *textFlag 44 | } 45 | 46 | // Validation 47 | if echoText == "" { 48 | fmt.Fprintln(stderrW, "Missing -text option or ECHO_TEXT env var!") 49 | os.Exit(127) 50 | } 51 | 52 | args := flag.Args() 53 | if len(args) > 0 { 54 | fmt.Fprintln(stderrW, "Too many arguments!") 55 | os.Exit(127) 56 | } 57 | 58 | // Flag gets printed as a page 59 | mux := http.NewServeMux() 60 | mux.HandleFunc("/", httpLog(stdoutW, withAppHeaders(*statusFlag, httpEcho(echoText)))) 61 | 62 | // Health endpoint 63 | mux.HandleFunc("/health", withAppHeaders(200, httpHealth())) 64 | 65 | server := &http.Server{ 66 | Addr: *listenFlag, 67 | Handler: mux, 68 | } 69 | serverCh := make(chan struct{}) 70 | go func() { 71 | log.Printf("[INFO] server is listening on %s\n", *listenFlag) 72 | if err := server.ListenAndServe(); err != http.ErrServerClosed { 73 | log.Fatalf("[ERR] server exited with: %s", err) 74 | } 75 | close(serverCh) 76 | }() 77 | 78 | signalCh := make(chan os.Signal, 1) 79 | signal.Notify(signalCh, os.Interrupt, syscall.SIGTERM) 80 | 81 | // Wait for interrupt 82 | <-signalCh 83 | 84 | log.Printf("[INFO] received interrupt, shutting down...") 85 | ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second) 86 | defer cancel() 87 | 88 | if err := server.Shutdown(ctx); err != nil { 89 | log.Fatalf("[ERR] failed to shutdown server: %s", err) 90 | } 91 | 92 | // If we got this far, it was an interrupt, so don't exit cleanly 93 | os.Exit(2) 94 | } 95 | 96 | func httpEcho(v string) http.HandlerFunc { 97 | return func(w http.ResponseWriter, r *http.Request) { 98 | fmt.Fprintln(w, v) 99 | } 100 | } 101 | 102 | func httpHealth() http.HandlerFunc { 103 | return func(w http.ResponseWriter, r *http.Request) { 104 | fmt.Fprintln(w, `{"status":"ok"}`) 105 | } 106 | } 107 | -------------------------------------------------------------------------------- /version/VERSION: -------------------------------------------------------------------------------- 1 | 1.0.1 2 | -------------------------------------------------------------------------------- /version/version.go: -------------------------------------------------------------------------------- 1 | // Copyright (c) HashiCorp, Inc. 2 | // SPDX-License-Identifier: MPL-2.0 3 | 4 | package version 5 | 6 | import "fmt" 7 | 8 | const Name = "http-echo" 9 | 10 | var ( 11 | GitCommit string 12 | Version string 13 | Timestamp string 14 | 15 | HumanVersion = fmt.Sprintf("%s v%s (%s)\nBuilt: %s", Name, Version, GitCommit, Timestamp) 16 | ) 17 | --------------------------------------------------------------------------------