Skip to content

Commit 2078107

Browse files
authored
feat: verify checksum (SHA256) (#16)
1 parent f506067 commit 2078107

Some content is hidden

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

45 files changed

+1016
-445
lines changed

.env.example

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
# APP CONFIG
2+
ADDRESS=
3+
LOG_LEVEL=
4+
STORE_INTERVAL=
5+
FILE_STORAGE_PATH=
6+
RESTORE=
7+
DATABASE_DSN=
8+
9+
# GOOSE CONFIG
10+
GOOSE_DRIVER=
11+
GOOSE_DBSTRING=
12+
GOOSE_MIGRATION_DIR=
13+
GOOSE_TABLE=

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,9 @@ cmd/agent/agent
1818
cmd/server/main
1919
cmd/server/server
2020

21+
# Envs
22+
.env
23+
2124
# Dependency directories (remove the comment below to include it)
2225
vendor/
2326

Makefile

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
BINARY_SERVER = server
2+
BINARY_AGENT = agent
3+
4+
default: build
5+
6+
build: build_server build_agent
7+
8+
build_server:
9+
go build -o ${BINARY_SERVER} cmd/server/main.go
10+
11+
build_agent:
12+
go build -o ${BINARY_AGENT} cmd/agent/main.go
13+
14+
test_server:
15+
go test ./... -timeout 60m --tags=server -v
16+
17+
test_agent:
18+
go test ./... -timeout 60m --tags=agent -v
19+
20+
clean:
21+
go clean
22+
rm -f $(BINARY_SERVER) $(BINARY_AGENT)
23+
24+
lint:
25+
go fmt ./...

README.md

Lines changed: 58 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,64 @@
22

33
Metrics collection and alerting service
44

5-
## For students
5+
[![go report card](https://goreportcard.com/badge/github.com/srg-bnd/observator?style=flat-square)](https://goreportcard.com/report/github.com/srg-bnd/observator)
6+
[![test status](https://github.com/srg-bnd/observator/workflows/mertricstest/badge.svg?branch=main "test status")](https://github.com/srg-bnd/observator/actions)
7+
8+
## Getting Started
9+
10+
Dependencies:
11+
12+
* Go `1.23`
13+
* PostgreSQL
14+
* Linux or macOS platform
15+
16+
### Startup
17+
18+
#### Server
19+
20+
To build a server, run in the terminal:
21+
22+
```bash
23+
cd cmd/server && go run . # in the root directory of the project
24+
```
25+
26+
To startup the server, run in the terminal:
27+
28+
```bash
29+
./cmd/server/server # in the root directory of the project
30+
```
31+
32+
##### Envs & flags
33+
34+
* `ADDRESS` | `-a` – address and port to run server. Default `:8080`
35+
* `LOG_LEVEL` | `-l` – log level. Default `info`
36+
* `STORE_INTERVAL` | `-i` – store interval in seconds (zero for sync). Default `300`
37+
* `FILE_STORAGE_PATH` | `-f` – file storage path. Default `./temp.storage.db`
38+
* `RESTORE` | `-r` – load data from storage. Default `true`
39+
* `DATABASE_DSN` | `-d` – DB connection address
40+
41+
#### Agent
42+
43+
To build a agent, run in the terminal:
44+
45+
```bash
46+
cd cmd/agent && go run . # in the root directory of the project
47+
```
48+
49+
To startup the agent, run in the terminal:
50+
51+
```bash
52+
./cmd/server/agent # in the root directory of the project
53+
```
54+
55+
##### Envs & flags
56+
57+
* `POLL_INTERVAL` | `-p` – frequency (seconds) of metric polling. Default `2`
58+
* `REPORT_INTERVAL` | `-r` – frequency (seconds) of sending values to the server. Default `10`
59+
* `ADDRESS` | `-a` – address and port to run agent. Default `localhost:8080`
60+
* `KEY` | `-k` – encryption key
61+
62+
## Development
663

764
### Updating the template
865

cmd/agent/README.md

Lines changed: 0 additions & 3 deletions
This file was deleted.

cmd/agent/flags.go

Lines changed: 0 additions & 39 deletions
This file was deleted.

cmd/agent/main.go

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -4,26 +4,28 @@ package main
44
import (
55
"log"
66

7+
config "github.com/srg-bnd/observator/config/agent"
78
"github.com/srg-bnd/observator/internal/agent"
9+
"github.com/srg-bnd/observator/internal/shared/services"
810
"github.com/srg-bnd/observator/internal/storage"
911
)
1012

11-
// Application
12-
type App struct {
13-
agent *agent.Agent
13+
func init() {
14+
config.Flags.ParseFlags()
1415
}
1516

16-
// Returns a new application
17-
func NewApp() *App {
18-
return &App{
19-
agent: agent.NewAgent(storage.NewMemStorage(), appConfigs.serverAddr),
17+
func main() {
18+
// Init DI container
19+
container := &config.Container{
20+
Storage: storage.NewMemStorage(),
21+
ServerAddr: config.Flags.ServerAddr,
2022
}
21-
}
2223

23-
func main() {
24-
parseFlags()
24+
if config.Flags.SecretKey != "" {
25+
container.ChecksumService = services.NewChecksum(config.Flags.SecretKey)
26+
}
2527

26-
if err := NewApp().agent.Start(appConfigs.pollInterval, appConfigs.reportInterval); err != nil {
28+
if err := agent.NewAgent(container).Start(config.Flags.PollInterval, config.Flags.ReportInterval); err != nil {
2729
log.Fatal(err)
2830
}
2931
}

cmd/agent/main_test.go

Lines changed: 0 additions & 12 deletions
This file was deleted.

cmd/server/README.md

Lines changed: 0 additions & 3 deletions
This file was deleted.

cmd/server/flags.go

Lines changed: 0 additions & 59 deletions
This file was deleted.

0 commit comments

Comments
 (0)