├── .github
└── workflows
│ ├── codecov.yml
│ ├── publish_npm.yaml
│ └── release.yml
├── .gitignore
├── .goreleaser.debug.yaml
├── .goreleaser.yaml
├── LICENSE
├── README.md
├── api
├── gateway
│ └── openapi.yaml
└── index.html
├── build
├── scripts
│ ├── migration
│ │ ├── script.d
│ │ │ └── 01-migrate-gateway.sh
│ │ └── service.d
│ │ │ └── gateway
│ │ │ └── migration.list
│ └── setup
│ │ ├── script.d
│ │ └── 01-setup-gateway.sh
│ │ └── service.d
│ │ └── gateway
│ │ ├── arch
│ │ └── setup-gateway.sh
│ │ ├── debian
│ │ ├── bullseye
│ │ │ └── setup-gateway.sh
│ │ └── setup-gateway.sh
│ │ └── ubuntu
│ │ ├── jammy
│ │ └── setup-gateway.sh
│ │ └── setup-gateway.sh
└── sysroot
│ ├── etc
│ └── casaos
│ │ └── gateway.ini.sample
│ └── usr
│ ├── lib
│ └── systemd
│ │ └── system
│ │ ├── casaos-gateway.service
│ │ └── casaos-gateway.service.buildroot
│ └── share
│ └── casaos
│ └── cleanup
│ ├── script.d
│ └── 01-cleanup-gateway.sh
│ └── service.d
│ └── gateway
│ ├── arch
│ └── cleanup-gateway.sh
│ ├── debian
│ ├── bullseye
│ │ └── cleanup-gateway.sh
│ └── cleanup-gateway.sh
│ └── ubuntu
│ ├── cleanup-gateway.sh
│ └── jammy
│ └── cleanup-gateway.sh
├── cmd
└── migration-tool
│ ├── log.go
│ ├── main.go
│ └── migration_dummy.go
├── common
├── config.go
└── version.go
├── go.mod
├── go.sum
├── main.go
├── package.json
├── pkg
└── port.go
├── route
├── gateway_route.go
├── management_route.go
├── management_route_test.go
└── static_route.go
├── service
├── management.go
├── management_test.go
└── state.go
└── tsconfig.json
/.github/workflows/codecov.yml:
--------------------------------------------------------------------------------
1 | name: Collect Code Coverage
2 |
3 | on:
4 | push:
5 | branches:
6 | - main
7 | pull_request:
8 | branches:
9 | - main
10 |
11 | jobs:
12 | build:
13 | runs-on: ubuntu-22.04
14 | steps:
15 | - name: Checkout
16 | uses: actions/checkout@v3
17 | with:
18 | fetch-depth: 0
19 | - name: Set up Go
20 | uses: actions/setup-go@v4
21 | with:
22 | go-version: "1.20"
23 | - name: Go Generate
24 | run: go generate
25 | - name: Run coverage
26 | run: go test -race -failfast -coverprofile=coverage.txt -covermode=atomic -v ./...
27 | - name: Upload coverage to Codecov
28 | uses: codecov/codecov-action@v3
29 |
--------------------------------------------------------------------------------
/.github/workflows/publish_npm.yaml:
--------------------------------------------------------------------------------
1 | name: publish npm
2 |
3 | on:
4 | push:
5 | tags:
6 | - v*.*.*
7 | workflow_dispatch:
8 |
9 | permissions:
10 | contents: write
11 |
12 | jobs:
13 | call-workflow-passing-data:
14 | uses: IceWhaleTech/github/.github/workflows/npm_release.yml@main
15 | secrets:
16 | NPM_TOKEN_PRIVATE: ${{ secrets.NPM_TOKEN_PRIVATE }}
17 |
--------------------------------------------------------------------------------
/.github/workflows/release.yml:
--------------------------------------------------------------------------------
1 | name: goreleaser
2 |
3 | on:
4 | push:
5 | tags:
6 | - v*.*.*
7 |
8 | permissions:
9 | contents: write
10 | jobs:
11 | call-workflow-passing-data:
12 | uses: IceWhaleTech/github/.github/workflows/go_release.yml@main
13 | with:
14 | project-name: CasaOS-Gateway
15 | file-name: casaos-gateway
16 | secrets:
17 | OSS_KEY_ID: ${{ secrets.OSS_KEY_ID }}
18 | OSS_KEY_SECRET: ${{ secrets.OSS_KEY_SECRET }}
--------------------------------------------------------------------------------
/.gitignore:
--------------------------------------------------------------------------------
1 | # If you prefer the allow list template instead of the deny list, see community template:
2 | # https://github.com/github/gitignore/blob/main/community/Golang/Go.AllowList.gitignore
3 | #
4 | # Binaries for programs and plugins
5 | *.exe
6 | *.exe~
7 | *.dll
8 | *.so
9 | *.dylib
10 |
11 | # Test binary, built with `go test -c`
12 | *.test
13 |
14 | # Output of the go coverage tool, specifically when used with LiteIDE
15 | *.out
16 |
17 | # Dependency directories (remove the comment below to include it)
18 | # vendor/
19 |
20 | # Go workspace file
21 | go.work
22 |
23 | conf/
24 | target/
25 |
26 | # IDE
27 | .vscode/
28 | __debug_bin
29 |
30 |
31 | dist/
32 | /github
33 | node_modules
34 | yarn.lock
35 | generate
36 | openapitools.json
37 |
--------------------------------------------------------------------------------
/.goreleaser.debug.yaml:
--------------------------------------------------------------------------------
1 | # This is an example .goreleaser.yml file with some sensible defaults.
2 | # Make sure to check the documentation at https://goreleaser.com
3 | project_name: casaos-gateway
4 | before:
5 | hooks:
6 | - go generate
7 | - go run github.com/google/go-licenses@latest check . --disallowed_types=restricted
8 | - go mod tidy
9 | - go test -race -v ./...
10 | builds:
11 | - id: casaos-gateway-amd64
12 | binary: build/sysroot/usr/bin/casaos-gateway
13 | env:
14 | - CC=x86_64-linux-gnu-gcc
15 | gcflags:
16 | - all=-N -l
17 | ldflags:
18 | - -X main.commit={{.Commit}}
19 | - -X main.date={{.Date}}
20 | - -extldflags "-static"
21 | tags:
22 | - musl
23 | - netgo
24 | - osusergo
25 | goos:
26 | - linux
27 | goarch:
28 | - amd64
29 | - id: casaos-gateway-arm64
30 | binary: build/sysroot/usr/bin/casaos-gateway
31 | env:
32 | - CC=aarch64-linux-gnu-gcc
33 | gcflags:
34 | - all=-N -l
35 | ldflags:
36 | - -X main.commit={{.Commit}}
37 | - -X main.date={{.Date}}
38 | - -extldflags "-static"
39 | tags:
40 | - musl
41 | - netgo
42 | - osusergo
43 | goos:
44 | - linux
45 | goarch:
46 | - arm64
47 | - id: casaos-gateway-arm-7
48 | binary: build/sysroot/usr/bin/casaos-gateway
49 | env:
50 | - CC=arm-linux-gnueabihf-gcc
51 | gcflags:
52 | - all=-N -l
53 | ldflags:
54 | - -X main.commit={{.Commit}}
55 | - -X main.date={{.Date}}
56 | - -extldflags "-static"
57 | tags:
58 | - musl
59 | - netgo
60 | - osusergo
61 | goos:
62 | - linux
63 | goarch:
64 | - arm
65 | goarm:
66 | - "7"
67 | - id: casaos-gateway-riscv64
68 | binary: build/sysroot/usr/bin/casaos-gateway
69 | env:
70 | - CC=riscv64-linux-gnu-gcc
71 | gcflags:
72 | - all=-N -l
73 | ldflags:
74 | - -X main.commit={{.Commit}}
75 | - -X main.date={{.Date}}
76 | - -extldflags "-static"
77 | tags:
78 | - musl
79 | - netgo
80 | - osusergo
81 | goos:
82 | - linux
83 | goarch:
84 | - riscv64
85 | - id: casaos-gateway-migration-tool-amd64
86 | binary: build/sysroot/usr/bin/casaos-gateway-migration-tool
87 | main: ./cmd/migration-tool
88 | env:
89 | - CC=x86_64-linux-gnu-gcc
90 | gcflags:
91 | - all=-N -l
92 | ldflags:
93 | - -X main.commit={{.Commit}}
94 | - -X main.date={{.Date}}
95 | - -extldflags "-static"
96 | tags:
97 | - musl
98 | - netgo
99 | - osusergo
100 | goos:
101 | - linux
102 | goarch:
103 | - amd64
104 | - id: casaos-gateway-migration-tool-arm64
105 | binary: build/sysroot/usr/bin/casaos-gateway-migration-tool
106 | main: ./cmd/migration-tool
107 | env:
108 | - CC=aarch64-linux-gnu-gcc
109 | gcflags:
110 | - all=-N -l
111 | ldflags:
112 | - -X main.commit={{.Commit}}
113 | - -X main.date={{.Date}}
114 | - -extldflags "-static"
115 | tags:
116 | - musl
117 | - netgo
118 | - osusergo
119 | goos:
120 | - linux
121 | goarch:
122 | - arm64
123 | - id: casaos-gateway-migration-tool-arm-7
124 | binary: build/sysroot/usr/bin/casaos-gateway-migration-tool
125 | main: ./cmd/migration-tool
126 | env:
127 | - CC=arm-linux-gnueabihf-gcc
128 | gcflags:
129 | - all=-N -l
130 | ldflags:
131 | - -X main.commit={{.Commit}}
132 | - -X main.date={{.Date}}
133 | - -extldflags "-static"
134 | tags:
135 | - musl
136 | - netgo
137 | - osusergo
138 | goos:
139 | - linux
140 | goarch:
141 | - arm
142 | goarm:
143 | - "7"
144 | - id: casaos-gateway-migration-tool-riscv64
145 | binary: build/sysroot/usr/bin/casaos-gateway-migration-tool
146 | main: ./cmd/migration-tool
147 | env:
148 | - CC=riscv64-linux-gnu-gcc
149 | gcflags:
150 | - all=-N -l
151 | ldflags:
152 | - -X main.commit={{.Commit}}
153 | - -X main.date={{.Date}}
154 | - -extldflags "-static"
155 | tags:
156 | - musl
157 | - netgo
158 | - osusergo
159 | goos:
160 | - linux
161 | goarch:
162 | - riscv64
163 | archives:
164 | - name_template: >-
165 | {{ .Os }}-{{- if eq .Arch "arm" }}arm-7{{- else }}{{ .Arch }}{{- end }}-{{ .ProjectName }}-v{{ .Version }}
166 | id: casaos-gateway
167 | builds:
168 | - casaos-gateway-amd64
169 | - casaos-gateway-arm64
170 | - casaos-gateway-arm-7
171 | - casaos-gateway-riscv64
172 | files:
173 | - build/**/*
174 | - name_template: >-
175 | {{ .Os }}-{{- if eq .Arch "arm" }}arm-7{{- else }}{{ .Arch }}{{- end }}-{{ .ProjectName }}-migration-tool-v{{ .Version }}
176 | id: casaos-gateway-migration-tool
177 | builds:
178 | - casaos-gateway-migration-tool-amd64
179 | - casaos-gateway-migration-tool-arm64
180 | - casaos-gateway-migration-tool-arm-7
181 | - casaos-gateway-migration-tool-riscv64
182 | files:
183 | - build/sysroot/etc/**/*
184 | checksum:
185 | name_template: "checksums.txt"
186 | snapshot:
187 | name_template: "{{ incpatch .Version }}"
188 | changelog:
189 | sort: asc
190 | filters:
191 | exclude:
192 | - "^docs:"
193 | - "^test:"
194 | release:
195 | github:
196 | owner: IceWhaleTech
197 | name: CasaOS-Gateway
198 | draft: true
199 | prerelease: auto
200 | mode: replace
201 | name_template: "v{{ .Version }}"
202 |
--------------------------------------------------------------------------------
/.goreleaser.yaml:
--------------------------------------------------------------------------------
1 | # This is an example .goreleaser.yml file with some sensible defaults.
2 | # Make sure to check the documentation at https://goreleaser.com
3 | project_name: casaos-gateway
4 | before:
5 | hooks:
6 | - go generate
7 | - go run github.com/google/go-licenses@latest check . --disallowed_types=restricted
8 | - go mod tidy
9 | - go test -race -v ./...
10 | builds:
11 | - id: casaos-gateway-amd64
12 | binary: build/sysroot/usr/bin/casaos-gateway
13 | hooks:
14 | post:
15 | - upx --best --lzma -v --no-progress "{{ .Path }}"
16 | env:
17 | - CC=x86_64-linux-gnu-gcc
18 | ldflags:
19 | - -X main.commit={{.Commit}}
20 | - -X main.date={{.Date}}
21 | - -s
22 | - -w
23 | - -extldflags "-static"
24 | tags:
25 | - musl
26 | - netgo
27 | - osusergo
28 | goos:
29 | - linux
30 | goarch:
31 | - amd64
32 | - id: casaos-gateway-arm64
33 | binary: build/sysroot/usr/bin/casaos-gateway
34 | # hooks:
35 | # post:
36 | # - upx --best --lzma -v --no-progress "{{ .Path }}"
37 | env:
38 | - CC=aarch64-linux-gnu-gcc
39 | ldflags:
40 | - -X main.commit={{.Commit}}
41 | - -X main.date={{.Date}}
42 | - -s
43 | - -w
44 | - -extldflags "-static"
45 | tags:
46 | - musl
47 | - netgo
48 | - osusergo
49 | goos:
50 | - linux
51 | goarch:
52 | - arm64
53 | - id: casaos-gateway-arm-7
54 | binary: build/sysroot/usr/bin/casaos-gateway
55 | hooks:
56 | post:
57 | - upx --best --lzma -v --no-progress "{{ .Path }}"
58 | env:
59 | - CC=arm-linux-gnueabihf-gcc
60 | ldflags:
61 | - -X main.commit={{.Commit}}
62 | - -X main.date={{.Date}}
63 | - -s
64 | - -w
65 | - -extldflags "-static"
66 | tags:
67 | - musl
68 | - netgo
69 | - osusergo
70 | goos:
71 | - linux
72 | goarch:
73 | - arm
74 | goarm:
75 | - "7"
76 | - id: casaos-gateway-riscv64
77 | binary: build/sysroot/usr/bin/casaos-gateway
78 | env:
79 | - CC=riscv64-linux-gnu-gcc
80 | ldflags:
81 | - -X main.commit={{.Commit}}
82 | - -X main.date={{.Date}}
83 | - -s
84 | - -w
85 | - -extldflags "-static"
86 | tags:
87 | - musl
88 | - netgo
89 | - osusergo
90 | goos:
91 | - linux
92 | goarch:
93 | - riscv64
94 | - id: casaos-gateway-migration-tool-amd64
95 | binary: build/sysroot/usr/bin/casaos-gateway-migration-tool
96 | hooks:
97 | post:
98 | - upx --best --lzma -v --no-progress "{{ .Path }}"
99 | main: ./cmd/migration-tool
100 | env:
101 | - CC=x86_64-linux-gnu-gcc
102 | ldflags:
103 | - -X main.commit={{.Commit}}
104 | - -X main.date={{.Date}}
105 | - -s
106 | - -w
107 | - -extldflags "-static"
108 | tags:
109 | - musl
110 | - netgo
111 | - osusergo
112 | goos:
113 | - linux
114 | goarch:
115 | - amd64
116 | - id: casaos-gateway-migration-tool-arm64
117 | binary: build/sysroot/usr/bin/casaos-gateway-migration-tool
118 | # hooks:
119 | # post:
120 | # - upx --best --lzma -v --no-progress "{{ .Path }}"
121 | main: ./cmd/migration-tool
122 | env:
123 | - CC=aarch64-linux-gnu-gcc
124 | ldflags:
125 | - -X main.commit={{.Commit}}
126 | - -X main.date={{.Date}}
127 | - -s
128 | - -w
129 | - -extldflags "-static"
130 | tags:
131 | - musl
132 | - netgo
133 | - osusergo
134 | goos:
135 | - linux
136 | goarch:
137 | - arm64
138 | - id: casaos-gateway-migration-tool-arm-7
139 | binary: build/sysroot/usr/bin/casaos-gateway-migration-tool
140 | hooks:
141 | post:
142 | - upx --best --lzma -v --no-progress "{{ .Path }}"
143 | main: ./cmd/migration-tool
144 | env:
145 | - CC=arm-linux-gnueabihf-gcc
146 | ldflags:
147 | - -X main.commit={{.Commit}}
148 | - -X main.date={{.Date}}
149 | - -s
150 | - -w
151 | - -extldflags "-static"
152 | tags:
153 | - musl
154 | - netgo
155 | - osusergo
156 | goos:
157 | - linux
158 | goarch:
159 | - arm
160 | goarm:
161 | - "7"
162 | - id: casaos-gateway-migration-tool-riscv64
163 | binary: build/sysroot/usr/bin/casaos-gateway-migration-tool
164 | main: ./cmd/migration-tool
165 | env:
166 | - CC=riscv64-linux-gnu-gcc
167 | ldflags:
168 | - -X main.commit={{.Commit}}
169 | - -X main.date={{.Date}}
170 | - -s
171 | - -w
172 | - -extldflags "-static"
173 | tags:
174 | - musl
175 | - netgo
176 | - osusergo
177 | goos:
178 | - linux
179 | goarch:
180 | - riscv64
181 | archives:
182 | - name_template: >-
183 | {{ .Os }}-{{- if eq .Arch "arm" }}arm-7{{- else }}{{ .Arch }}{{- end }}-{{ .ProjectName }}-v{{ .Version }}
184 | id: casaos-gateway
185 | builds:
186 | - casaos-gateway-amd64
187 | - casaos-gateway-arm64
188 | - casaos-gateway-arm-7
189 | - casaos-gateway-riscv64
190 | files:
191 | - build/**/*
192 | - name_template: >-
193 | {{ .Os }}-{{- if eq .Arch "arm" }}arm-7{{- else }}{{ .Arch }}{{- end }}-{{ .ProjectName }}-migration-tool-v{{ .Version }}
194 | id: casaos-gateway-migration-tool
195 | builds:
196 | - casaos-gateway-migration-tool-amd64
197 | - casaos-gateway-migration-tool-arm64
198 | - casaos-gateway-migration-tool-arm-7
199 | - casaos-gateway-migration-tool-riscv64
200 | files:
201 | - build/sysroot/etc/**/*
202 | checksum:
203 | name_template: "checksums.txt"
204 | snapshot:
205 | name_template: "{{ incpatch .Version }}"
206 | changelog:
207 | sort: asc
208 | filters:
209 | exclude:
210 | - "^docs:"
211 | - "^test:"
212 | release:
213 | github:
214 | owner: IceWhaleTech
215 | name: CasaOS-Gateway
216 | draft: false
217 | prerelease: auto
218 | mode: replace
219 | name_template: "v{{ .Version }}"
220 |
--------------------------------------------------------------------------------
/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 [yyyy] [name of copyright owner]
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 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # CasaOS-Gateway
2 |
3 | [](https://pkg.go.dev/github.com/IceWhaleTech/CasaOS-Gateway) [](https://goreportcard.com/report/github.com/IceWhaleTech/CasaOS-Gateway) [](https://github.com/IceWhaleTech/CasaOS-Gateway/actions/workflows/release.yml) [](https://codecov.io/gh/IceWhaleTech/CasaOS-Gateway)
4 |
5 | CasaOS Gateway is a dynamic API gateway service that can be used to expose APIs from different other HTTP based services.
6 |
7 | This gateway service comes with a simple management API for other services to register their APIs by route paths. A HTTP request arrived at gateway port will be forwarded to the service that is registered for the route path.
8 |
9 | > As a best practice, a service behind this gateway should bind to localhost (`127.0.0.1` for IPv4, `::1` for IPv6) ONLY, so no external network access is allowed.
10 |
11 | ## Configuration
12 |
13 | Upon launching, it will search for `gateway.ini` file in the following order:
14 |
15 | ```bash
16 | ./gateway.ini
17 | ./conf/gateway.ini
18 | $HOME/.casaos/gateway.ini
19 | /etc/casaos/gateway.ini
20 | ```
21 |
22 | See [gateway.ini.sample](./build/etc/casaos/gateway.ini.sample) for default configuration.
23 |
24 | ## Running
25 |
26 | Once running, gateway address and management address will be available in the files under `RuntimePath` specified in configuration.
27 |
28 | ```bash
29 | $ cat /var/run/casaos/gateway.url
30 | [::]:8080 # port is specified in configuration
31 |
32 | $ cat /var/run/casaos/management.url
33 | [::]:34703 # port is randomly assigned
34 | ```
35 |
36 | ## Example
37 |
38 | Assuming that
39 |
40 | - the management API is running on port `34703`
41 | - the gateway is running on port `8080`
42 | - some API running at `http://localhost:12345/ping` that simply returns `pong`.
43 |
44 | Then register the API as follows:
45 |
46 | - POST `http://localhost:34703/v1/gateway/routes`
47 |
48 | ```json
49 | {
50 | "path": "/ping",
51 | "target": "http://localhost:12345"
52 | }
53 | ```
54 |
55 | or in command line:
56 |
57 | ```bash
58 | $ curl 'localhost:34703/v1/gateway/routes' --data-raw '
59 | {"path": "/ping", "target": "http://localhost:12345"}
60 | '
61 | ```
62 |
63 | Now run
64 |
65 | ```bash
66 | $ curl localhost:8080/ping
67 | {"message":"pong"}
68 | ```
69 |
70 | ... which is equivalent as
71 |
72 | ```bash
73 | $ curl localhost:12345/ping
74 | {"message":"pong"}
75 | ```
76 |
--------------------------------------------------------------------------------
/api/gateway/openapi.yaml:
--------------------------------------------------------------------------------
1 | openapi: 3.0.3
2 |
3 | info:
4 | title: CasaOS Gateway API
5 | version: v1
6 | description: |-
7 |
8 |
9 |
10 |
11 |
12 |
13 | servers:
14 | - url: /v1/gateway
15 |
16 | tags:
17 | - name: USB methods
18 | description: |-
19 | USB methods
20 |
21 | security:
22 | - access_token: []
23 |
24 | paths:
25 | /port:
26 | put:
27 | summary: Set gateway port
28 | description: |-
29 | Set gateway port
30 | operationId: setGatewayPort
31 | tags:
32 | - Gateway methods
33 | requestBody:
34 | content:
35 | application/json:
36 | schema:
37 | type: object
38 | properties:
39 | port:
40 | type: string
41 | description: Gateway port
42 | example: "80"
43 | responses:
44 | "200":
45 | $ref: "#/components/responses/ResponseOK"
46 | get:
47 | summary: Get gateway port
48 | description: |-
49 | Get gateway port
50 | operationId: getGatewayPort
51 | tags:
52 | - Gateway methods
53 | responses:
54 | "200":
55 | $ref: "#/components/responses/ResponseStringOK"
56 | "400":
57 | $ref: "#/components/responses/ResponseBadRequest"
58 | "500":
59 | $ref: "#/components/responses/ResponseInternalServerError"
60 |
61 | components:
62 | securitySchemes:
63 | access_token:
64 | type: apiKey
65 | in: header
66 | name: Authorization
67 |
68 | responses:
69 | ResponseOK:
70 | description: OK
71 | content:
72 | application/json:
73 | schema:
74 | $ref: "#/components/schemas/BaseResponse"
75 | ResponseStringOK:
76 | description: OK
77 | content:
78 | application/json:
79 | schema:
80 | $ref: "#/components/schemas/SuccessResponseString"
81 | ResponseBadRequest:
82 | description: Bad Request
83 | content:
84 | application/json:
85 | schema:
86 | readOnly: true
87 | allOf:
88 | - $ref: "#/components/schemas/BaseResponse"
89 | example:
90 | message: "Bad Request"
91 | ResponseInternalServerError:
92 | description: Internal Server Error
93 | content:
94 | application/json:
95 | schema:
96 | readOnly: true
97 | allOf:
98 | - $ref: "#/components/schemas/BaseResponse"
99 | example:
100 | message: "Internal Server Error"
101 | schemas:
102 | BaseResponse:
103 | properties:
104 | message:
105 | readOnly: true
106 | description: message returned by server side if there is any
107 | type: string
108 | example: ""
109 |
110 | SuccessResponseString:
111 | allOf:
112 | - $ref: "#/components/schemas/BaseResponse"
113 | - properties:
114 | data:
115 | type: string
116 | description: When the interface returns success, this field is the specific success information
117 |
--------------------------------------------------------------------------------
/api/index.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |