Skip to content

Commit d7695ee

Browse files
committed
Initial commit.
0 parents  commit d7695ee

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

73 files changed

+46615
-0
lines changed

.gitignore

+15
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
# hidden files
2+
.*
3+
4+
# excluded hidden files
5+
!.gitmodules
6+
!.goreleaser.yaml
7+
8+
# builds
9+
/build
10+
/dist
11+
12+
# For testing
13+
Vagrantfile
14+
15+
dist/

.gitmodules

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
[submodule "chirpstack"]
2+
path = chirpstack
3+
url = https://github.com/chirpstack/chirpstack.git

.goreleaser.yaml

+46
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
project_name: chirpstack-rest-api
2+
3+
builds:
4+
-
5+
binary: chirpstack-rest-api
6+
env:
7+
- CGO_ENABLED=0
8+
goos:
9+
- linux
10+
goarch:
11+
- amd64
12+
- arm64
13+
14+
archives:
15+
-
16+
format: tar.gz
17+
18+
release:
19+
disable: true
20+
21+
nfpms:
22+
-
23+
vendor: ChirpStack
24+
homepage: https://www.chirpstack.io/
25+
maintainer: Orne Brocaar <[email protected]>
26+
description: ChirpStack gRPC to REST proxy
27+
license: MIT
28+
formats:
29+
- deb
30+
- rpm
31+
bindir: /usr/bin
32+
contents:
33+
-
34+
src: packaging/files/chirpstack-rest-api.service
35+
dst: /lib/systemd/system/chirpstack-rest-api.service
36+
-
37+
src: packaging/files/environment
38+
dst: /etc/chirpstack-rest-api/environment
39+
type: "config|noreplace"
40+
file_info:
41+
owner: chirpstack
42+
group: chirpstack
43+
scripts:
44+
preinstall: packaging/files/pre-install.sh
45+
postinstall: packaging/files/post-install.sh
46+
preremove: packaging/files/pre-remove.sh

Dockerfile

+22
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
FROM golang:1.18-alpine AS development
2+
3+
ENV PROJECT_PATH=/chirpstack-rest-api
4+
ENV PATH=$PATH:$PROJECT_PATH/build
5+
ENV CGO_ENABLED=0
6+
ENV GO_EXTRA_BUILD_ARGS="-a -installsuffix cgo"
7+
8+
RUN apk add --no-cache ca-certificates make git bash
9+
10+
RUN mkdir -p $PROJECT_PATH
11+
COPY . $PROJECT_PATH
12+
WORKDIR $PROJECT_PATH
13+
14+
RUN make dev-requirements
15+
RUN make
16+
17+
FROM alpine:3.15.0 AS production
18+
19+
RUN apk --no-cache add ca-certificates
20+
COPY --from=development /chirpstack-rest-api/build/chirpstack-rest-api /usr/bin/chirpstack-rest-api
21+
USER nobody:nogroup
22+
ENTRYPOINT ["/usr/bin/chirpstack-rest-api"]

Dockerfile-devel

+17
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
FROM golang:1.18-alpine
2+
3+
ENV PROJECT_PATH=/chirpstack-rest-api
4+
ENV PATH=$PATH:$PROJECT_PATH/build
5+
ENV CGO_ENABLED=0
6+
ENV GO_EXTRA_BUILD_ARGS="-a -installsuffix cgo"
7+
8+
RUN apk add --no-cache ca-certificates make git bash alpine-sdk protobuf protobuf-dev
9+
RUN git clone https://github.com/googleapis/googleapis.git /googleapis
10+
RUN git config --global --add safe.directory /chirpstack-rest-api
11+
git config --global --add safe.directory /chirpstack-rest-api/chirpstack
12+
13+
RUN mkdir -p $PROJECT_PATH
14+
COPY . $PROJECT_PATH
15+
WORKDIR $PROJECT_PATH
16+
17+
RUN make dev-requirements

LICENSE

+22
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
The MIT License (MIT)
2+
3+
Copyright (c) 2022 Orne Brocaar
4+
5+
Permission is hereby granted, free of charge, to any person obtaining a copy
6+
of this software and associated documentation files (the "Software"), to deal
7+
in the Software without restriction, including without limitation the rights
8+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
copies of the Software, and to permit persons to whom the Software is
10+
furnished to do so, subject to the following conditions:
11+
12+
The above copyright notice and this permission notice shall be included in all
13+
copies or substantial portions of the Software.
14+
15+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21+
SOFTWARE.
22+

Makefile

+60
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
.PHONY: build dev-requirements devshell
2+
VERSION := $(shell git describe --always |sed -e "s/^v//")
3+
4+
GW_GEN := protoc -I=/googleapis -I=chirpstack/api/proto --grpc-gateway_out=paths=source_relative,logtostderr=true:.
5+
API_GEN := protoc -I=/googleapis -I=chirpstack/api/proto --openapiv2_out ./openapiv2 --openapiv2_opt logtostderr=true
6+
GRPC_GEN := protoc -I=/googleapis -I=chirpstack/api/proto --go_out=. --go_opt=paths=source_relative --go-grpc_out=. --go-grpc_opt=paths=source_relative
7+
8+
build:
9+
mkdir -p build
10+
go build $(GO_EXTRA_BUILD_ARGS) -ldflags "-s -w -X main.version=$(VERSION)" -o build/chirpstack-rest-api main.go
11+
12+
dist:
13+
goreleaser
14+
15+
snapshot:
16+
goreleaser --snapshot
17+
18+
dev-requirements:
19+
git submodule update --init
20+
go mod download
21+
go install google.golang.org/protobuf/cmd/protoc-gen-go
22+
go install google.golang.org/grpc/cmd/protoc-gen-go-grpc
23+
go install github.com/grpc-ecosystem/grpc-gateway/v2/protoc-gen-grpc-gateway
24+
go install github.com/grpc-ecosystem/grpc-gateway/v2/protoc-gen-openapiv2
25+
go install github.com/goreleaser/goreleaser@latest
26+
go install github.com/goreleaser/nfpm/v2/cmd/nfpm
27+
28+
devshell:
29+
docker-compose run --rm chirpstack-rest-api bash
30+
31+
generate:
32+
cd chirpstack && git fetch && git checkout ${VERSION}
33+
${GW_GEN} api/application.proto
34+
${GW_GEN} api/device.proto
35+
${GW_GEN} api/device_profile.proto
36+
${GW_GEN} api/device_profile_template.proto
37+
${GW_GEN} api/gateway.proto
38+
${GW_GEN} api/multicast_group.proto
39+
${GW_GEN} api/tenant.proto
40+
${GW_GEN} api/user.proto
41+
42+
${GRPC_GEN} api/application.proto
43+
${GRPC_GEN} api/device.proto
44+
${GRPC_GEN} api/device_profile.proto
45+
${GRPC_GEN} api/device_profile_template.proto
46+
${GRPC_GEN} api/gateway.proto
47+
${GRPC_GEN} api/multicast_group.proto
48+
${GRPC_GEN} api/tenant.proto
49+
${GRPC_GEN} api/user.proto
50+
51+
${API_GEN} api/application.proto
52+
${API_GEN} api/device.proto
53+
${API_GEN} api/device_profile.proto
54+
${API_GEN} api/device_profile_template.proto
55+
${API_GEN} api/gateway.proto
56+
${API_GEN} api/multicast_group.proto
57+
${API_GEN} api/tenant.proto
58+
${API_GEN} api/user.proto
59+
60+
cd ui && go run merge.go ${VERSION} ../openapiv2/api > api.json

README.md

+53
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
# ChirpStack gRPC to REST API proxy
2+
3+
The ChirpStack gRPC to REST API proxy exposes the ChirpStack (v4) gRPC as REST
4+
API. While the gRPC API interface exposed by ChirpStack (v4) is recommended,
5+
in some use-cases a REST API cna be more convenient. It could also help when
6+
migrating from ChirpStack v3 to v4 as previously this proxy was embedded inside
7+
the ChirpStack Application Server.
8+
9+
## Usage
10+
11+
```bash
12+
chirpstack-rest-api --server localhost:8080 --bind 0.0.0.0:8090 --insecure
13+
```
14+
15+
* `--server` points to the ChirpStack gRPC endpoint. If ChirpStack is installed
16+
on the same machine and uses port `8080` (default), you can use the default
17+
value. You can also use the environment variable `SERVER`.
18+
* `--bind` defines to which interface and port the REST API server will bind.
19+
In the above example (and default value), the REST API server will be exposed
20+
on port `8090`. YOu can also use the environment variable `BIND`.
21+
* `--insecure` indicates that the gRPC interface is not secured using a TLS
22+
certificate. You can also use the environment variable `INSECURE` (setting
23+
this to any value enables insecure mode, e.g. do not use `INSECURE=false`!).
24+
25+
## Building from source
26+
27+
To start the Docker Compose based development environment:
28+
29+
```
30+
make devshell
31+
```
32+
33+
Within this development shell, you can use one of the following commands
34+
(see also the included `Makefile`):
35+
36+
```bash
37+
# Compile binary
38+
make build
39+
40+
# Create distributable archives and packages.
41+
make dist
42+
43+
# Create snapshot archives and packages.
44+
make snapshot
45+
46+
# Re-generate API definitions (VERSION must be set to the ChirpStack version)
47+
VERSION=v4.0.0 make generate
48+
```
49+
50+
## License
51+
52+
ChirpStack REST API is distributed under the MIT license. See also
53+
[LICENSE](https://github.com/chirpstack/chirpstack-rest-api/blob/master/LICENSE).

0 commit comments

Comments
 (0)