File tree Expand file tree Collapse file tree 4 files changed +71
-0
lines changed Expand file tree Collapse file tree 4 files changed +71
-0
lines changed Original file line number Diff line number Diff line change @@ -16,6 +16,11 @@ import (
1616 "gopkg.in/yaml.v2"
1717)
1818
19+ // ConfigDir is a view of the ConfigSupport.configDir.
20+ type ConfigDir struct {
21+ Dir string
22+ }
23+
1924// ConfigSupport is a clingy helper, which loads the configuration.
2025type ConfigSupport struct {
2126 configDir string
Original file line number Diff line number Diff line change @@ -46,6 +46,12 @@ func Run(module func(ball *mud.Ball)) {
4646 })
4747
4848 cfg := & ConfigSupport {}
49+ mud .Supply [* ConfigSupport ](ball , cfg )
50+ mud .View [* ConfigSupport , ConfigDir ](ball , func (support * ConfigSupport ) ConfigDir {
51+ return ConfigDir {
52+ Dir : support .configDir ,
53+ }
54+ })
4955 ok , err := clingy.Environment {
5056 Dynamic : cfg .GetValue ,
5157 }.Run (ctx , clingyRunner (cfg , ball ))
Original file line number Diff line number Diff line change @@ -5,6 +5,7 @@ package root
55
66import (
77 "storj.io/storj/shared/modular"
8+ "storj.io/storj/shared/modular/cli"
89 "storj.io/storj/shared/modular/logger"
910 "storj.io/storj/shared/mud"
1011 "storj.io/storj/storagenode"
@@ -15,4 +16,6 @@ func Module(ball *mud.Ball) {
1516 logger .Module (ball )
1617 modular .IdentityModule (ball )
1718 storagenode .Module (ball )
19+ mud .Provide [* Setup ](ball , NewSetup )
20+ cli .RegisterSubcommand [* Setup ](ball , "setup" , "setup storagenode configuration" )
1821}
Original file line number Diff line number Diff line change 1+ // Copyright (C) 2025 Storj Labs, Inc.
2+ // See LICENSE for copying information.
3+
4+ package root
5+
6+ import (
7+ "context"
8+ "fmt"
9+
10+ "go.uber.org/zap"
11+
12+ "storj.io/common/fpath"
13+ "storj.io/common/identity"
14+ "storj.io/storj/shared/modular/cli"
15+ "storj.io/storj/storagenode/storagenodedb"
16+ )
17+
18+ // SetupArgs contains arguments for the setup command.
19+ type SetupArgs struct {
20+ }
21+
22+ // Setup handles storagenode configuration setup.
23+ type Setup struct {
24+ dbConfig storagenodedb.Config
25+ confDir cli.ConfigDir
26+ identity * identity.FullIdentity
27+ }
28+
29+ // NewSetup creates a new Setup instance for storagenode configuration.
30+ func NewSetup (dbConfig storagenodedb.Config , confDir cli.ConfigDir , identity * identity.FullIdentity ) * Setup {
31+ return & Setup {
32+ dbConfig : dbConfig ,
33+ confDir : confDir ,
34+ identity : identity ,
35+ }
36+ }
37+
38+ // Run executes the storagenode setup process.
39+ func (s * Setup ) Run (ctx context.Context ) error {
40+ setupDir := s .confDir .Dir
41+ valid , _ := fpath .IsValidSetupDir (setupDir )
42+ if ! valid {
43+ return fmt .Errorf ("storagenode configuration already exists (%v)" , setupDir )
44+ }
45+
46+ // create db
47+ db , err := storagenodedb .OpenNew (ctx , zap .L ().Named ("db" ), s .dbConfig )
48+ if err != nil {
49+ return err
50+ }
51+
52+ if err := db .Pieces ().CreateVerificationFile (ctx , s .identity .ID ); err != nil {
53+ return err
54+ }
55+
56+ return nil
57+ }
You can’t perform that action at this time.
0 commit comments