oracle: change neofs URI scheme

Strip '//', see neo-project/neo-modules#518.
This commit is contained in:
Roman Khimov 2021-04-06 16:56:19 +03:00
parent bd9a303e29
commit d2f7f00997
2 changed files with 11 additions and 11 deletions

View file

@ -47,7 +47,7 @@ var (
) )
// Get returns neofs object from the provided url. // Get returns neofs object from the provided url.
// URI scheme is "neofs://<Container-ID>/<Object-ID/<Command>/<Params>". // URI scheme is "neofs:<Container-ID>/<Object-ID/<Command>/<Params>".
// If Command is not provided, full object is requested. // If Command is not provided, full object is requested.
func Get(ctx context.Context, priv *keys.PrivateKey, u *url.URL, addr string) ([]byte, error) { func Get(ctx context.Context, priv *keys.PrivateKey, u *url.URL, addr string) ([]byte, error) {
objectAddr, ps, err := parseNeoFSURL(u) objectAddr, ps, err := parseNeoFSURL(u)
@ -80,25 +80,25 @@ func parseNeoFSURL(u *url.URL) (*object.Address, []string, error) {
return nil, nil, ErrInvalidScheme return nil, nil, ErrInvalidScheme
} }
ps := strings.Split(strings.TrimPrefix(u.Path, "/"), "/") ps := strings.Split(u.Opaque, "/")
if len(ps) == 0 || ps[0] == "" { if len(ps) < 2 {
return nil, nil, ErrMissingObject return nil, nil, ErrMissingObject
} }
containerID := container.NewID() containerID := container.NewID()
if err := containerID.Parse(u.Hostname()); err != nil { if err := containerID.Parse(ps[0]); err != nil {
return nil, nil, fmt.Errorf("%w: %v", ErrInvalidContainer, err) return nil, nil, fmt.Errorf("%w: %v", ErrInvalidContainer, err)
} }
objectID := object.NewID() objectID := object.NewID()
if err := objectID.Parse(ps[0]); err != nil { if err := objectID.Parse(ps[1]); err != nil {
return nil, nil, fmt.Errorf("%w: %v", ErrInvalidObject, err) return nil, nil, fmt.Errorf("%w: %v", ErrInvalidObject, err)
} }
objectAddr := object.NewAddress() objectAddr := object.NewAddress()
objectAddr.SetContainerID(containerID) objectAddr.SetContainerID(containerID)
objectAddr.SetObjectID(objectID) objectAddr.SetObjectID(objectID)
return objectAddr, ps[1:], nil return objectAddr, ps[2:], nil
} }
func getPayload(ctx context.Context, c *client.Client, addr *object.Address) ([]byte, error) { func getPayload(ctx context.Context, c *client.Client, addr *object.Address) ([]byte, error) {

View file

@ -44,7 +44,7 @@ func TestParseNeoFSURL(t *testing.T) {
oid := object.NewID() oid := object.NewID()
require.NoError(t, oid.Parse(oStr)) require.NoError(t, oid.Parse(oStr))
validPrefix := "neofs://" + cStr + "/" + oStr validPrefix := "neofs:" + cStr + "/" + oStr
objectAddr := object.NewAddress() objectAddr := object.NewAddress()
objectAddr.SetContainerID(cid) objectAddr.SetContainerID(cid)
objectAddr.SetObjectID(oid) objectAddr.SetObjectID(oid)
@ -57,10 +57,10 @@ func TestParseNeoFSURL(t *testing.T) {
{validPrefix, nil, nil}, {validPrefix, nil, nil},
{validPrefix + "/", []string{""}, nil}, {validPrefix + "/", []string{""}, nil},
{validPrefix + "/range/1|2", []string{"range", "1|2"}, nil}, {validPrefix + "/range/1|2", []string{"range", "1|2"}, nil},
{"neoffs://" + cStr + "/" + oStr, nil, ErrInvalidScheme}, {"neoffs:" + cStr + "/" + oStr, nil, ErrInvalidScheme},
{"neofs://" + cStr, nil, ErrMissingObject}, {"neofs:" + cStr, nil, ErrMissingObject},
{"neofs://" + cStr + "ooo/" + oStr, nil, ErrInvalidContainer}, {"neofs:" + cStr + "ooo/" + oStr, nil, ErrInvalidContainer},
{"neofs://" + cStr + "/ooo" + oStr, nil, ErrInvalidObject}, {"neofs:" + cStr + "/ooo" + oStr, nil, ErrInvalidObject},
} }
for _, tc := range testCases { for _, tc := range testCases {
t.Run(tc.url, func(t *testing.T) { t.Run(tc.url, func(t *testing.T) {