Skip to content

Commit

Permalink
definitions: Implement GSP-706 Support HTTP Signer (#709)
Browse files Browse the repository at this point in the history
* definitions: Implement GSP-706 Support HTTP Signer

* Add comments for op name and dependency for service

* Update op name

* Update names

* Update var for op name
  • Loading branch information
JinnyYi authored Aug 19, 2021
1 parent 5aff212 commit cf8c0ed
Show file tree
Hide file tree
Showing 8 changed files with 269 additions and 17 deletions.
24 changes: 12 additions & 12 deletions cmd/definitions/bindata/bindata.go

Large diffs are not rendered by default.

16 changes: 16 additions & 0 deletions cmd/definitions/tmpl/operation.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,25 @@ package types
import (
"context"
"io"
"net/http"
"time"
)

{{- range $_, $i := .Interfaces }}
// Operation names in {{ $i.DisplayName }}.
const (
{{- range $_, $op := $i.Ops }}
// Op{{ $i.DisplayName }}{{ $op.Name | toPascal }} is the operation name for {{ $op.Name }} in {{ $i.Name }}.
Op{{ $i.DisplayName }}{{ $op.Name | toPascal }} = "{{ $op.Name }}"
{{- end }}
)

var (
{{- range $_, $op := $i.Ops }}
_ = Op{{ $i.DisplayName }}{{ $op.Name | toPascal }}
{{- end }}
)

{{ $i.Description }}
type {{ $i.DisplayName }} interface {
{{- if or (eq $i.Name "servicer") (eq $i.Name "storager")}}
Expand Down
2 changes: 2 additions & 0 deletions cmd/definitions/tmpl/service.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ package {{ .Name }}
import (
"context"
"io"
"net/http"
"time"

"github.com/beyondstorage/go-storage/v4/pkg/httpclient"
Expand All @@ -15,6 +16,7 @@ var _ Storager
var _ services.ServiceError
var _ httpclient.Options
var _ time.Duration
var _ http.Request

// Type is the type for {{ .Name }}
const Type = "{{ .Name }}"
Expand Down
9 changes: 9 additions & 0 deletions definitions/fields.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,9 @@ type = "string"
[err]
type = "error"

[expire]
type = "time.Duration"

[index]
type = "int"

Expand All @@ -34,6 +37,9 @@ type = "int64"
[oi]
type = "*ObjectIterator"

[op]
type = "string"

[pairs]
type = "...Pair"

Expand All @@ -52,6 +58,9 @@ type = "*PartIterator"
[r]
type = "io.Reader"

[req]
type = "*http.Request"

[size]
type = "int64"

Expand Down
8 changes: 8 additions & 0 deletions definitions/operations.toml
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,14 @@ will fetch from a given url to path.
- A successful fetch operation should be complete, which means the object's content and metadata should be the same as requiring from the url.
"""

[httpSigner]
description = "is the interface for Signer."

[httpSigner.op.query_sign_http]
description = "will return `*http.Request` with query string parameters containing signature in `URL` to represent the client's request."
params = ["op", "path", "expire"]
results = ["req"]

[mover]
description = "is the interface for Move."

Expand Down
10 changes: 5 additions & 5 deletions docs/rfcs/706-support-http-signer.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,14 +20,14 @@ A signed URL is a URL that provides limited permission and time to make a reques
I propose to add the following interface containing operations that support the generation of signed URL for RESTful services:

```go
type HttpSigner interface {
QuerySignHttp(op, path string, expire time.Duration, ps ...types.Pair) (signedReq *http.Request, err error)
type HTTPSigner interface {
QuerySignHTTP(op, path string, expire time.Duration, ps ...types.Pair) (signedReq *http.Request, err error)
}
```

`HttpSigner` is the interface for `Signer` related operations which support calculating request signature.
`HTTPSigner` is the interface for `Signer` related operations which support calculating request signature.

`QuerySignHttp` returns a "http.Request" with query string parameters containing signature in `URL` to represent the client's request for the specified operation.
`QuerySignHTTP` returns `*http.Request` with query string parameters containing signature in `URL` to represent the client's request for the specified operation.

**Parameters**

Expand Down Expand Up @@ -67,4 +67,4 @@ This proposal will deprecate `Reacher` interface.
- Add new interface and operations in definitions.
- Update docs in site.
- Implement integration test.
- Implement `HttpSigner` for services.
- Implement `HTTPSigner` for services.
2 changes: 2 additions & 0 deletions tests/generated.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit cf8c0ed

Please sign in to comment.