From 96414b9ac927d2bfb16f514404444ceca1312b0e Mon Sep 17 00:00:00 2001 From: Henrique Dias Date: Wed, 7 Dec 2022 15:40:41 +0100 Subject: [PATCH] fix: honour --ttl flag in 'ipfs name publish' --- core/coreapi/name.go | 15 +++++++++------ core/corehttp/gateway_test.go | 7 +------ docs/examples/kubo-as-a-library/go.mod | 4 ++-- docs/examples/kubo-as-a-library/go.sum | 8 ++++---- go.mod | 6 +++--- go.sum | 8 ++++---- 6 files changed, 23 insertions(+), 25 deletions(-) diff --git a/core/coreapi/name.go b/core/coreapi/name.go index 69dc1137bf0..87af34af476 100644 --- a/core/coreapi/name.go +++ b/core/coreapi/name.go @@ -15,6 +15,7 @@ import ( ipath "github.com/ipfs/go-path" coreiface "github.com/ipfs/interface-go-ipfs-core" caopts "github.com/ipfs/interface-go-ipfs-core/options" + nsopts "github.com/ipfs/interface-go-ipfs-core/options/namesys" path "github.com/ipfs/interface-go-ipfs-core/path" ci "github.com/libp2p/go-libp2p/core/crypto" peer "github.com/libp2p/go-libp2p/core/peer" @@ -37,8 +38,6 @@ func (e *ipnsEntry) Value() path.Path { return e.value } -type requestContextKey string - // Publish announces new IPNS name and returns the new IPNS entry. func (api *NameAPI) Publish(ctx context.Context, p path.Path, opts ...caopts.NamePublishOption) (coreiface.IpnsEntry, error) { ctx, span := tracing.Span(ctx, "CoreAPI.NameAPI", "Publish", trace.WithAttributes(attribute.String("path", p.String()))) @@ -76,13 +75,17 @@ func (api *NameAPI) Publish(ctx context.Context, p path.Path, opts ...caopts.Nam return nil, err } + eol := time.Now().Add(options.ValidTime) + + publishOptions := []nsopts.PublishOption{ + nsopts.PublishWithEOL(eol), + } + if options.TTL != nil { - // nolint: staticcheck // non-backward compatible change - ctx = context.WithValue(ctx, requestContextKey("ipns-publish-ttl"), *options.TTL) + publishOptions = append(publishOptions, nsopts.PublishWithTTL(*options.TTL)) } - eol := time.Now().Add(options.ValidTime) - err = api.namesys.PublishWithEOL(ctx, k, pth, eol) + err = api.namesys.Publish(ctx, k, pth, publishOptions...) if err != nil { return nil, err } diff --git a/core/corehttp/gateway_test.go b/core/corehttp/gateway_test.go index 0d2f07dbeaf..4972b8f0cfb 100644 --- a/core/corehttp/gateway_test.go +++ b/core/corehttp/gateway_test.go @@ -9,7 +9,6 @@ import ( "regexp" "strings" "testing" - "time" namesys "github.com/ipfs/go-namesys" version "github.com/ipfs/kubo" @@ -68,11 +67,7 @@ func (m mockNamesys) ResolveAsync(ctx context.Context, name string, opts ...nsop return out } -func (m mockNamesys) Publish(ctx context.Context, name ci.PrivKey, value path.Path) error { - return errors.New("not implemented for mockNamesys") -} - -func (m mockNamesys) PublishWithEOL(ctx context.Context, name ci.PrivKey, value path.Path, _ time.Time) error { +func (m mockNamesys) Publish(ctx context.Context, name ci.PrivKey, value path.Path, opts ...nsopts.PublishOption) error { return errors.New("not implemented for mockNamesys") } diff --git a/docs/examples/kubo-as-a-library/go.mod b/docs/examples/kubo-as-a-library/go.mod index 1c40cfe81ea..925b452c2af 100644 --- a/docs/examples/kubo-as-a-library/go.mod +++ b/docs/examples/kubo-as-a-library/go.mod @@ -8,7 +8,7 @@ replace github.com/ipfs/kubo => ./../../.. require ( github.com/ipfs/go-ipfs-files v0.2.0 - github.com/ipfs/interface-go-ipfs-core v0.8.1 + github.com/ipfs/interface-go-ipfs-core v0.8.2-0.20221213102858-77d51fc050db github.com/ipfs/kubo v0.14.0-rc1 github.com/libp2p/go-libp2p v0.24.1 github.com/multiformats/go-multiaddr v0.8.0 @@ -102,7 +102,7 @@ require ( github.com/ipfs/go-merkledag v0.8.1 // indirect github.com/ipfs/go-metrics-interface v0.0.1 // indirect github.com/ipfs/go-mfs v0.2.1 // indirect - github.com/ipfs/go-namesys v0.6.0 // indirect + github.com/ipfs/go-namesys v0.6.1-0.20221212115758-6b648ff31901 // indirect github.com/ipfs/go-path v0.3.0 // indirect github.com/ipfs/go-peertaskqueue v0.8.0 // indirect github.com/ipfs/go-unixfs v0.4.1 // indirect diff --git a/docs/examples/kubo-as-a-library/go.sum b/docs/examples/kubo-as-a-library/go.sum index f2d9d7ebdde..5f41a0d5ffd 100644 --- a/docs/examples/kubo-as-a-library/go.sum +++ b/docs/examples/kubo-as-a-library/go.sum @@ -579,8 +579,8 @@ github.com/ipfs/go-metrics-interface v0.0.1 h1:j+cpbjYvu4R8zbleSs36gvB7jR+wsL2fG github.com/ipfs/go-metrics-interface v0.0.1/go.mod h1:6s6euYU4zowdslK0GKHmqaIZ3j/b/tL7HTWtJ4VPgWY= github.com/ipfs/go-mfs v0.2.1 h1:5jz8+ukAg/z6jTkollzxGzhkl3yxm022Za9f2nL5ab8= github.com/ipfs/go-mfs v0.2.1/go.mod h1:Woj80iuw4ajDnIP6+seRaoHpPsc9hmL0pk/nDNDWP88= -github.com/ipfs/go-namesys v0.6.0 h1:w4+Wq9bCILnuZRT1RBBdzZQFqtJeDG1duzN8mIDnHZ0= -github.com/ipfs/go-namesys v0.6.0/go.mod h1:0L+3CHBgHxr08Cg+chVo9Ew285PGQfToThjll4g0/d4= +github.com/ipfs/go-namesys v0.6.1-0.20221212115758-6b648ff31901 h1:nK/gmRqL/8dxp4xwu/1F8ErJciiiv9XxTWtsfIPv5i4= +github.com/ipfs/go-namesys v0.6.1-0.20221212115758-6b648ff31901/go.mod h1:eRSVJHtD3ELCGpdbrCCxKXvTO/lAuJ/aegjyWn88vTg= github.com/ipfs/go-path v0.2.1/go.mod h1:NOScsVgxfC/eIw4nz6OiGwK42PjaSJ4Y/ZFPn1Xe07I= github.com/ipfs/go-path v0.3.0 h1:tkjga3MtpXyM5v+3EbRvOHEoo+frwi4oumw5K+KYWyA= github.com/ipfs/go-path v0.3.0/go.mod h1:NOScsVgxfC/eIw4nz6OiGwK42PjaSJ4Y/ZFPn1Xe07I= @@ -598,8 +598,8 @@ github.com/ipfs/go-unixfsnode v1.4.0/go.mod h1:qc7YFFZ8tABc58p62HnIYbUMwj9chhUuF github.com/ipfs/go-verifcid v0.0.1/go.mod h1:5Hrva5KBeIog4A+UpqlaIU+DEstipcJYQQZc0g37pY0= github.com/ipfs/go-verifcid v0.0.2 h1:XPnUv0XmdH+ZIhLGKg6U2vaPaRDXb9urMyNVCE7uvTs= github.com/ipfs/go-verifcid v0.0.2/go.mod h1:40cD9x1y4OWnFXbLNJYRe7MpNvWlMn3LZAG5Wb4xnPU= -github.com/ipfs/interface-go-ipfs-core v0.8.1 h1:nuFG0YJ429Wd5gtRb3ivlblpknZ5VfDVKZkmOG2TnNQ= -github.com/ipfs/interface-go-ipfs-core v0.8.1/go.mod h1:WYC2H6Mu7aGqhlupi/CVawcs0X1Me4uRvV0rcTlo3zM= +github.com/ipfs/interface-go-ipfs-core v0.8.2-0.20221213102858-77d51fc050db h1:oD5Hqo0LY2ahLzvet36P1lJkxE64lT2ItAP9mnjNmBs= +github.com/ipfs/interface-go-ipfs-core v0.8.2-0.20221213102858-77d51fc050db/go.mod h1:WYC2H6Mu7aGqhlupi/CVawcs0X1Me4uRvV0rcTlo3zM= github.com/ipld/edelweiss v0.2.0 h1:KfAZBP8eeJtrLxLhi7r3N0cBCo7JmwSRhOJp3WSpNjk= github.com/ipld/edelweiss v0.2.0/go.mod h1:FJAzJRCep4iI8FOFlRriN9n0b7OuX3T/S9++NpBDmA4= github.com/ipld/go-car v0.4.0 h1:U6W7F1aKF/OJMHovnOVdst2cpQE5GhmHibQkAixgNcQ= diff --git a/go.mod b/go.mod index f214d574399..a641ba5c363 100644 --- a/go.mod +++ b/go.mod @@ -15,6 +15,7 @@ require ( github.com/facebookgo/atomicfile v0.0.0-20151019160806-2de1f203e7d5 github.com/fsnotify/fsnotify v1.6.0 github.com/gabriel-vasile/mimetype v1.4.1 + github.com/gogo/protobuf v1.3.2 github.com/google/uuid v1.3.0 github.com/hashicorp/go-multierror v1.1.1 github.com/ipfs/go-bitswap v0.11.0 @@ -57,13 +58,13 @@ require ( github.com/ipfs/go-metrics-interface v0.0.1 github.com/ipfs/go-metrics-prometheus v0.0.2 github.com/ipfs/go-mfs v0.2.1 - github.com/ipfs/go-namesys v0.6.0 + github.com/ipfs/go-namesys v0.6.1-0.20221212115758-6b648ff31901 github.com/ipfs/go-path v0.3.0 github.com/ipfs/go-pinning-service-http-client v0.1.2 github.com/ipfs/go-unixfs v0.4.1 github.com/ipfs/go-unixfsnode v1.4.0 github.com/ipfs/go-verifcid v0.0.2 - github.com/ipfs/interface-go-ipfs-core v0.8.1 + github.com/ipfs/interface-go-ipfs-core v0.8.2-0.20221213102858-77d51fc050db github.com/ipld/go-car v0.4.0 github.com/ipld/go-car/v2 v2.4.0 github.com/ipld/go-codec-dagpb v1.4.1 @@ -144,7 +145,6 @@ require ( github.com/go-logr/stdr v1.2.2 // indirect github.com/go-task/slim-sprig v0.0.0-20210107165309-348f09dbbbc0 // indirect github.com/godbus/dbus/v5 v5.1.0 // indirect - github.com/gogo/protobuf v1.3.2 // indirect github.com/golang/groupcache v0.0.0-20210331224755-41bb18bfe9da // indirect github.com/golang/mock v1.6.0 // indirect github.com/golang/protobuf v1.5.2 // indirect diff --git a/go.sum b/go.sum index f890f22b08a..99eced7aee9 100644 --- a/go.sum +++ b/go.sum @@ -604,8 +604,8 @@ github.com/ipfs/go-metrics-prometheus v0.0.2 h1:9i2iljLg12S78OhC6UAiXi176xvQGiZa github.com/ipfs/go-metrics-prometheus v0.0.2/go.mod h1:ELLU99AQQNi+zX6GCGm2lAgnzdSH3u5UVlCdqSXnEks= github.com/ipfs/go-mfs v0.2.1 h1:5jz8+ukAg/z6jTkollzxGzhkl3yxm022Za9f2nL5ab8= github.com/ipfs/go-mfs v0.2.1/go.mod h1:Woj80iuw4ajDnIP6+seRaoHpPsc9hmL0pk/nDNDWP88= -github.com/ipfs/go-namesys v0.6.0 h1:w4+Wq9bCILnuZRT1RBBdzZQFqtJeDG1duzN8mIDnHZ0= -github.com/ipfs/go-namesys v0.6.0/go.mod h1:0L+3CHBgHxr08Cg+chVo9Ew285PGQfToThjll4g0/d4= +github.com/ipfs/go-namesys v0.6.1-0.20221212115758-6b648ff31901 h1:nK/gmRqL/8dxp4xwu/1F8ErJciiiv9XxTWtsfIPv5i4= +github.com/ipfs/go-namesys v0.6.1-0.20221212115758-6b648ff31901/go.mod h1:eRSVJHtD3ELCGpdbrCCxKXvTO/lAuJ/aegjyWn88vTg= github.com/ipfs/go-path v0.2.1/go.mod h1:NOScsVgxfC/eIw4nz6OiGwK42PjaSJ4Y/ZFPn1Xe07I= github.com/ipfs/go-path v0.3.0 h1:tkjga3MtpXyM5v+3EbRvOHEoo+frwi4oumw5K+KYWyA= github.com/ipfs/go-path v0.3.0/go.mod h1:NOScsVgxfC/eIw4nz6OiGwK42PjaSJ4Y/ZFPn1Xe07I= @@ -625,8 +625,8 @@ github.com/ipfs/go-unixfsnode v1.4.0/go.mod h1:qc7YFFZ8tABc58p62HnIYbUMwj9chhUuF github.com/ipfs/go-verifcid v0.0.1/go.mod h1:5Hrva5KBeIog4A+UpqlaIU+DEstipcJYQQZc0g37pY0= github.com/ipfs/go-verifcid v0.0.2 h1:XPnUv0XmdH+ZIhLGKg6U2vaPaRDXb9urMyNVCE7uvTs= github.com/ipfs/go-verifcid v0.0.2/go.mod h1:40cD9x1y4OWnFXbLNJYRe7MpNvWlMn3LZAG5Wb4xnPU= -github.com/ipfs/interface-go-ipfs-core v0.8.1 h1:nuFG0YJ429Wd5gtRb3ivlblpknZ5VfDVKZkmOG2TnNQ= -github.com/ipfs/interface-go-ipfs-core v0.8.1/go.mod h1:WYC2H6Mu7aGqhlupi/CVawcs0X1Me4uRvV0rcTlo3zM= +github.com/ipfs/interface-go-ipfs-core v0.8.2-0.20221213102858-77d51fc050db h1:oD5Hqo0LY2ahLzvet36P1lJkxE64lT2ItAP9mnjNmBs= +github.com/ipfs/interface-go-ipfs-core v0.8.2-0.20221213102858-77d51fc050db/go.mod h1:WYC2H6Mu7aGqhlupi/CVawcs0X1Me4uRvV0rcTlo3zM= github.com/ipld/edelweiss v0.2.0 h1:KfAZBP8eeJtrLxLhi7r3N0cBCo7JmwSRhOJp3WSpNjk= github.com/ipld/edelweiss v0.2.0/go.mod h1:FJAzJRCep4iI8FOFlRriN9n0b7OuX3T/S9++NpBDmA4= github.com/ipld/go-car v0.4.0 h1:U6W7F1aKF/OJMHovnOVdst2cpQE5GhmHibQkAixgNcQ=