Skip to content

Commit

Permalink
fix: wire up config.ForgeClient settings
Browse files Browse the repository at this point in the history
  • Loading branch information
lidel committed Sep 20, 2024
1 parent fe307da commit bfc73d0
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 23 deletions.
4 changes: 2 additions & 2 deletions core/node/groups.go
Original file line number Diff line number Diff line change
Expand Up @@ -134,8 +134,8 @@ func LibP2P(bcfg *BuildCfg, cfg *config.Config, userResourceOverrides rcmgr.Part

// Services (resource management)
fx.Provide(libp2p.ResourceManager(cfg.Swarm, userResourceOverrides)),
maybeProvide(libp2p.P2PForgeCertMgr, enableForgeClient),
maybeInvoke(libp2p.StartP2PForgeCertMgr, enableForgeClient),
maybeProvide(libp2p.P2PForgeCertMgr(cfg.Swarm.ForgeClient), enableForgeClient),
maybeInvoke(libp2p.StartP2PForgeClient, enableForgeClient),
fx.Provide(libp2p.AddrFilters(cfg.Swarm.AddrFilters)),
fx.Provide(libp2p.AddrsFactory(cfg.Addresses.Announce, cfg.Addresses.AppendAnnounce, cfg.Addresses.NoAnnounce)),
fx.Provide(libp2p.SmuxTransport(cfg.Swarm.Transports)),
Expand Down
51 changes: 30 additions & 21 deletions core/node/libp2p/addrs.go
Original file line number Diff line number Diff line change
Expand Up @@ -131,32 +131,41 @@ func ListenOn(addresses []string) interface{} {
}
}

func P2PForgeCertMgr() (*p2pforge.P2PForgeCertMgr, error) {
storagePath, err := config.Path("", "p2p-forge-certs")
if err != nil {
return nil, err
}
func P2PForgeCertMgr(cfg config.ForgeClient) interface{} {
return func() (*p2pforge.P2PForgeCertMgr, error) {
storagePath, err := config.Path("", "p2p-forge-certs")
if err != nil {
return nil, err
}

const authEnvVar = "FORGE_ACCESS_TOKEN"
const authForgeHeader = "Forge-Authorization"
authKey, foundAuthKey := os.LookupEnv(authEnvVar)
const authEnvVar = "FORGE_ACCESS_TOKEN"
const authForgeHeader = "Forge-Authorization" // TODO: move to p2pforge client lib
authKey, foundAuthKey := os.LookupEnv(authEnvVar)
if !foundAuthKey {
authKey = cfg.ForgeAuth.WithDefault("")
foundAuthKey = cfg.ForgeAuth.IsDefault()
}

certMgr, err := p2pforge.NewP2PForgeCertMgr(
p2pforge.WithModifiedForgeRequest(func(req *http.Request) error {
if foundAuthKey {
req.Header.Set(authForgeHeader, authKey)
}
return nil
}),
p2pforge.WithCertificateStorage(&certmagic.FileStorage{Path: storagePath}))
if err != nil {
return nil, err
}
certMgr, err := p2pforge.NewP2PForgeCertMgr(
p2pforge.WithForgeDomain(cfg.ForgeDomain.WithDefault(config.DefaultForgeDomain)),
p2pforge.WithForgeRegistrationEndpoint(cfg.ForgeEndpoint.WithDefault(config.DefaultForgeEndpoint)),
p2pforge.WithCAEndpoint(cfg.CAEndpoint.WithDefault(config.DefaultCAEndpoint)),
p2pforge.WithModifiedForgeRequest(func(req *http.Request) error {
if foundAuthKey {
req.Header.Set(authForgeHeader, authKey)
}
return nil
}),
p2pforge.WithCertificateStorage(&certmagic.FileStorage{Path: storagePath}))
if err != nil {
return nil, err
}

return certMgr, nil
return certMgr, nil
}
}

func StartP2PForgeCertMgr(lc fx.Lifecycle, certMgr *p2pforge.P2PForgeCertMgr, h host.Host) {
func StartP2PForgeClient(lc fx.Lifecycle, certMgr *p2pforge.P2PForgeCertMgr, h host.Host) {
lc.Append(fx.Hook{
OnStart: func(ctx context.Context) error {
certMgr.ProvideHost(h)
Expand Down

0 comments on commit bfc73d0

Please sign in to comment.