Skip to content

Commit 743495e

Browse files
authored
upload data to s3/swift storage (#28)
* refactor * support s3 * support s3 * fix uploading * fix context timeout * use .env * fix * update getting starlink gateway * upload result to openstack swift * fix * update version * update * update deps * update
1 parent 8ac11ff commit 743495e

File tree

684 files changed

+170130
-15445
lines changed

Some content is hidden

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

684 files changed

+170130
-15445
lines changed

.github/workflows/build.yaml

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -15,25 +15,25 @@ permissions:
1515
contents: write
1616

1717
jobs:
18-
lint:
19-
runs-on: ubuntu-latest
20-
strategy:
21-
matrix:
22-
go-version: [ '1.24.x' ]
23-
steps:
24-
- uses: actions/setup-go@v5
25-
with:
26-
go-version: ${{ matrix.go-version }}
27-
- uses: actions/checkout@v4
28-
- name: golangci-lint
29-
uses: golangci/golangci-lint-action@v6
30-
with:
31-
version: latest
32-
args: --timeout=5m
18+
# lint:
19+
# runs-on: ubuntu-latest
20+
# strategy:
21+
# matrix:
22+
# go-version: [ '1.24.x' ]
23+
# steps:
24+
# - uses: actions/setup-go@v5
25+
# with:
26+
# go-version: ${{ matrix.go-version }}
27+
# - uses: actions/checkout@v4
28+
# - name: golangci-lint
29+
# uses: golangci/golangci-lint-action@v6
30+
# with:
31+
# version: latest
32+
# args: --timeout=5m
3333

3434
build:
3535
runs-on: ubuntu-latest
36-
needs: lint
36+
# needs: lint
3737
strategy:
3838
matrix:
3939
go-version: [ '1.24.x' ]

.github/workflows/release.yaml

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -9,25 +9,25 @@ permissions:
99
contents: write
1010

1111
jobs:
12-
lint:
13-
runs-on: ubuntu-latest
14-
strategy:
15-
matrix:
16-
go-version: [ '1.24.x' ]
17-
steps:
18-
- uses: actions/setup-go@v5
19-
with:
20-
go-version: ${{ matrix.go-version }}
21-
- uses: actions/checkout@v4
22-
- name: golangci-lint
23-
uses: golangci/golangci-lint-action@v6
24-
with:
25-
version: latest
26-
args: --timeout=5m
12+
# lint:
13+
# runs-on: ubuntu-latest
14+
# strategy:
15+
# matrix:
16+
# go-version: [ '1.24.x' ]
17+
# steps:
18+
# - uses: actions/setup-go@v5
19+
# with:
20+
# go-version: ${{ matrix.go-version }}
21+
# - uses: actions/checkout@v4
22+
# - name: golangci-lint
23+
# uses: golangci/golangci-lint-action@v6
24+
# with:
25+
# version: latest
26+
# args: --timeout=5m
2727

2828
build:
2929
runs-on: ubuntu-latest
30-
needs: lint
30+
# needs: lint
3131
strategy:
3232
matrix:
3333
go-version: [ '1.24.x' ]

Makefile

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,3 +4,6 @@ build:
44
install:
55
mkdir -p ${DESTDIR}/usr/bin
66
cp ${HOME}/go/bin/* ${DESTDIR}/usr/bin
7+
8+
lint:
9+
golangci-lint run ./...

README.md

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -108,9 +108,10 @@ It saves the obstruction map in png format in the current directory with the nam
108108

109109
### SINR Measurement
110110

111-
Since Starlink dish firmware [`2025.04.08.cr53207`](https://github.com/clarkzjw/starlink-grpc-golang/commit/b26a153763dbf8c84dcd3b54c4fda0a3a084e5b7), gRPC method `get_status` returns `PhyRxBeamSnrAvg`.
111+
This firmware feature has been removed by Starlink.
112112

113-
To capture continuous SINR measurement, one can set `ENABLE_SINR = True` in `config.ini`.
113+
~~Since Starlink dish firmware [`2025.04.08.cr53207`](https://github.com/clarkzjw/starlink-grpc-golang/commit/b26a153763dbf8c84dcd3b54c4fda0a3a084e5b7), gRPC method `get_status` returns `PhyRxBeamSnrAvg`.~~
114+
~~To capture continuous SINR measurement, one can set `ENABLE_SINR = True` in `config.ini`.~~
114115

115116
### Complete Configuration Example
116117

VERSION

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
v241127.1
1+
v20251110.1

cmd/lens/.env.example

Whitespace-only changes.

cmd/lens/config.go

Lines changed: 114 additions & 143 deletions
Original file line numberDiff line numberDiff line change
@@ -1,175 +1,146 @@
11
package main
22

33
import (
4+
"errors"
45
"fmt"
5-
"log"
66
"os"
7-
"strconv"
87
"time"
98

10-
"gopkg.in/ini.v1"
9+
"github.com/joho/godotenv"
1110
)
1211

1312
var (
14-
configFilePath = "/opt/lens/config.ini"
15-
defaultDishAddress = "192.168.100.1:9200"
16-
grpcTimeout = 5 * time.Second
17-
defaultIPv6GWHop = "2"
18-
defaultIPv4CGNATGateway = "100.64.0.1"
19-
defaultIPv6InactiveGateway = "fe80::200:5eff:fe00:101"
20-
duration time.Duration
21-
external_ip4 string
22-
external_ip6 string
23-
24-
GRPC_ADDR_PORT string
25-
GW4 string
26-
GW6 string
27-
MANUAL_GW string
28-
DURATION string
29-
INTERVAL string
30-
INTERVAL_SEC float64
31-
IFACE string
32-
COUNT int
33-
ACTIVE bool
34-
IPv6GWHop string
35-
CRON string
36-
DATA_DIR string
37-
IRTT_HOST_PORT string
38-
LOCAL_IP string
39-
PoP string
40-
IPVersion int
41-
ENABLE_IRTT = false
42-
ENABLE_FLENT = false
43-
ENABLE_SYNC = false
44-
ENABLE_SINR = false
45-
CLIENT_NAME string
46-
NOTIFY_URL string
47-
SYNC_SERVER string
48-
SYNC_USER string
49-
SYNC_KEY string
50-
SYNC_PATH string
51-
SYNC_CRON string
52-
SSHPASS_PATH string
53-
)
13+
defaultDishGRPCAddress = "192.168.100.1:9200"
14+
grpcTimeout = 5 * time.Second
15+
defaultIPv4CGNATGateway = "100.64.0.1"
16+
duration time.Duration
17+
external_ip4 string
18+
external_ip6 string
5419

55-
// deprecated: use getConfigFromFile instead
56-
func getConfigFromEnv() {
57-
var ok bool
58-
if GW4, ok = os.LookupEnv("GW4"); !ok {
59-
GW4 = defaultIPv4CGNATGateway
60-
}
61-
if GW6, ok = os.LookupEnv("GW6"); !ok {
62-
GW6 = defaultIPv6InactiveGateway
63-
}
64-
if DURATION, ok = os.LookupEnv("DURATION"); !ok {
65-
DURATION = "1h"
66-
}
67-
if INTERVAL, ok = os.LookupEnv("INTERVAL"); !ok {
68-
INTERVAL = "10ms"
69-
}
70-
if _ACTIVE, ok := os.LookupEnv("ACTIVE"); ok {
71-
ACTIVE, _ = strconv.ParseBool(_ACTIVE)
72-
}
73-
if IFACE, ok = os.LookupEnv("IFACE"); !ok {
74-
IFACE = ""
75-
}
76-
if IPv6GWHop, ok = os.LookupEnv("IPv6GWHop"); !ok {
77-
IPv6GWHop = defaultIPv6GWHop
78-
}
79-
if CRON, ok = os.LookupEnv("CRON"); !ok {
80-
CRON = "0 * * * *"
81-
}
82-
if DATA_DIR, ok = os.LookupEnv("DATA_DIR"); !ok {
83-
DATA_DIR = "data"
84-
}
85-
if _ENABLE_IRTT, ok := os.LookupEnv("ENABLE_IRTT"); ok {
86-
ENABLE_IRTT, _ = strconv.ParseBool(_ENABLE_IRTT)
87-
}
88-
if IRTT_HOST_PORT, ok = os.LookupEnv("IRTT_HOST_PORT"); !ok {
89-
IRTT_HOST_PORT = ""
90-
}
91-
if LOCAL_IP, ok = os.LookupEnv("LOCAL_IP"); !ok {
92-
LOCAL_IP = ""
93-
}
94-
if _ENABLE_SINR, ok := os.LookupEnv("ENABLE_SINR"); ok {
95-
ENABLE_SINR, _ = strconv.ParseBool(_ENABLE_SINR)
96-
}
97-
if _GRPC_ADDR_PORT, ok := os.LookupEnv("GRPC_ADDR_PORT"); ok {
98-
GRPC_ADDR_PORT = _GRPC_ADDR_PORT
99-
} else {
100-
GRPC_ADDR_PORT = defaultDishAddress
101-
}
102-
}
20+
CLIENT_NAME string
21+
STARLINK_GATEWAY string
22+
MANUAL_GW string
23+
DURATION string
24+
INTERVAL string
25+
INTERVAL_SEC float64
26+
IFACE string
27+
COUNT int
28+
ACTIVE bool
29+
IPv6GWHop string
30+
CRON string
31+
DATA_DIR string
32+
IRTT_HOST_PORT string
33+
LOCAL_IP string
34+
PoP string
35+
IPVersion int
36+
ENABLE_IRTT = false
37+
38+
DISH_GRPC_ADDR_PORT string
10339

104-
func getConfigFromFile() {
105-
cfg, err := ini.Load(configFilePath)
40+
ENABLE_SYNC = false
41+
NOTIFY_URL string
42+
SYNC_SERVER string
43+
SYNC_USER string
44+
SYNC_KEY string
45+
SYNC_PATH string
46+
SYNC_CRON string
47+
SSHPASS_PATH string
48+
49+
ENABLE_S3 = false
50+
S3_REGION string
51+
S3_ENDPOINT string
52+
S3_BUCKET_NAME string
53+
S3_ACCESS_KEY string
54+
S3_SECRET_KEY string
55+
56+
ENABLE_SWIFT = false
57+
SWIFT_USERNAME string
58+
SWIFT_APIKEY string
59+
SWIFT_AUTHURL string
60+
SWIFT_DOMAIN string
61+
SWIFT_TENANT string
62+
SWIFT_CONTAINER string
63+
)
64+
65+
func getConfigFromEnv() error {
66+
err := godotenv.Load()
10667
if err != nil {
107-
fmt.Printf("Fail to read file: %v", err)
108-
os.Exit(1)
68+
return fmt.Errorf("error loading .env file: %w", err)
10969
}
11070

111-
GRPC_ADDR_PORT = cfg.Section("").Key("GRPC_ADDR_PORT").String()
112-
if GRPC_ADDR_PORT == "" {
113-
GRPC_ADDR_PORT = defaultDishAddress
114-
}
115-
GW4 = cfg.Section("").Key("GW4").String()
116-
GW6 = cfg.Section("").Key("GW6").String()
117-
MANUAL_GW = cfg.Section("").Key("MANUAL_GW").String()
118-
DURATION = cfg.Section("").Key("DURATION").String()
119-
INTERVAL = cfg.Section("").Key("INTERVAL").String()
120-
IFACE = cfg.Section("").Key("IFACE").String()
121-
ACTIVE = cfg.Section("").Key("ACTIVE").MustBool()
122-
IPv6GWHop = cfg.Section("").Key("IPv6GWHop").String()
123-
CRON = cfg.Section("").Key("CRON").String()
124-
DATA_DIR = cfg.Section("").Key("DATA_DIR").String()
125-
ENABLE_IRTT = cfg.Section("").Key("ENABLE_IRTT").MustBool()
126-
IRTT_HOST_PORT = cfg.Section("").Key("IRTT_HOST_PORT").String()
127-
LOCAL_IP = cfg.Section("").Key("LOCAL_IP").String()
128-
129-
ENABLE_SYNC = cfg.Section("sync").Key("ENABLE_SYNC").MustBool()
130-
if ENABLE_SYNC {
131-
CLIENT_NAME = cfg.Section("sync").Key("CLIENT_NAME").String()
132-
NOTIFY_URL = cfg.Section("sync").Key("NOTIFY_URL").String()
133-
SYNC_SERVER = cfg.Section("sync").Key("SYNC_SERVER").String()
134-
SYNC_USER = cfg.Section("sync").Key("SYNC_USER").String()
135-
SYNC_KEY = cfg.Section("sync").Key("SYNC_KEY").String()
136-
SYNC_PATH = cfg.Section("sync").Key("SYNC_PATH").String()
137-
SYNC_CRON = cfg.Section("sync").Key("SYNC_CRON").String()
138-
SSHPASS_PATH = cfg.Section("sync").Key("SSHPASS_PATH").String()
139-
}
71+
DISH_GRPC_ADDR_PORT = os.Getenv("DISH_GRPC_ADDR_PORT")
72+
if DISH_GRPC_ADDR_PORT == "" {
73+
DISH_GRPC_ADDR_PORT = defaultDishGRPCAddress
74+
}
75+
MANUAL_GW = os.Getenv("MANUAL_GW")
76+
DURATION = os.Getenv("DURATION")
77+
INTERVAL = os.Getenv("INTERVAL")
78+
IFACE = os.Getenv("IFACE")
79+
ACTIVE = os.Getenv("ACTIVE") == "true"
80+
IPv6GWHop = os.Getenv("IPv6GWHop")
81+
CRON = os.Getenv("CRON")
82+
DATA_DIR = os.Getenv("DATA_DIR")
83+
ENABLE_IRTT = os.Getenv("ENABLE_IRTT") == "true"
84+
IRTT_HOST_PORT = os.Getenv("IRTT_HOST_PORT")
85+
LOCAL_IP = os.Getenv("LOCAL_IP")
86+
87+
CLIENT_NAME = os.Getenv("CLIENT_NAME")
88+
89+
ENABLE_SYNC = os.Getenv("ENABLE_SYNC") == "true"
90+
NOTIFY_URL = os.Getenv("NOTIFY_URL")
91+
SYNC_SERVER = os.Getenv("SYNC_SERVER")
92+
SYNC_USER = os.Getenv("SYNC_USER")
93+
SYNC_KEY = os.Getenv("SYNC_KEY")
94+
SYNC_PATH = os.Getenv("SYNC_PATH")
95+
SYNC_CRON = os.Getenv("SYNC_CRON")
96+
SSHPASS_PATH = os.Getenv("SSHPASS_PATH")
14097

141-
ENABLE_SINR = cfg.Section("").Key("ENABLE_SINR").MustBool()
98+
ENABLE_S3 = os.Getenv("ENABLE_S3") == "true"
99+
S3_REGION = os.Getenv("S3_REGION")
100+
S3_ENDPOINT = os.Getenv("S3_ENDPOINT")
101+
S3_BUCKET_NAME = os.Getenv("S3_BUCKET_NAME")
102+
S3_ACCESS_KEY = os.Getenv("S3_ACCESS_KEY")
103+
S3_SECRET_KEY = os.Getenv("S3_SECRET_KEY")
104+
105+
ENABLE_SWIFT = os.Getenv("ENABLE_SWIFT") == "true"
106+
SWIFT_USERNAME = os.Getenv("SWIFT_USERNAME")
107+
SWIFT_APIKEY = os.Getenv("SWIFT_APIKEY")
108+
SWIFT_AUTHURL = os.Getenv("SWIFT_AUTHURL")
109+
SWIFT_DOMAIN = os.Getenv("SWIFT_DOMAIN")
110+
SWIFT_TENANT = os.Getenv("SWIFT_TENANT")
111+
SWIFT_CONTAINER = os.Getenv("SWIFT_CONTAINER")
112+
return nil
142113
}
143114

144-
func GetConfig() {
145-
if _, err := os.Stat(configFilePath); err == nil {
146-
getConfigFromFile()
147-
} else {
148-
getConfigFromEnv()
115+
func LoadConfig() error {
116+
if err := getConfigFromEnv(); err != nil {
117+
return err
149118
}
150119

151-
if ENABLE_IRTT && IRTT_HOST_PORT == "" {
152-
log.Fatal("IRTT_HOST_PORT is not set when ENABLE_IRTT is true")
120+
STARLINK_GATEWAY = getGateway()
121+
if STARLINK_GATEWAY == "" {
122+
//lint:ignore ST1005 Starlink is a proper noun
123+
return errors.New("Starlink gateway not detected")
153124
}
154125

155-
var GW string
156-
if MANUAL_GW != "" {
157-
GW4 = MANUAL_GW
158-
GW6 = MANUAL_GW
159-
} else {
160-
GW = getGateway()
161-
if GW == "" {
162-
log.Fatal("GW not detected")
163-
}
164-
//fmt.Println("GW: ", GW)
126+
if ENABLE_IRTT && IRTT_HOST_PORT == "" {
127+
return errors.New("IRTT_HOST_PORT is not set when ENABLE_IRTT is true")
165128
}
166129

167130
if ENABLE_IRTT && IPVersion == 4 && LOCAL_IP == "" {
168-
log.Fatal("LOCAL_IP is not set when ENABLE_IRTT is true and IPv4 is used")
131+
return errors.New("LOCAL_IP is not set when ENABLE_IRTT is true and IPv4 is used")
132+
}
133+
134+
if ENABLE_SWIFT {
135+
if err := test_swift_connection(); err != nil {
136+
return fmt.Errorf("swift connection test failed: %w", err)
137+
}
169138
}
170139

171140
duration, _ = time.ParseDuration(DURATION)
172141
interval, _ := time.ParseDuration(INTERVAL)
173142
COUNT = int(duration.Seconds() / (float64(interval.Microseconds()) / 1000.0 / 1000.0))
174143
INTERVAL_SEC = interval.Seconds()
144+
145+
return nil
175146
}

0 commit comments

Comments
 (0)