lib/uplink: expose restrict on api keys (#2189)
This commit is contained in:
parent
474d9e7492
commit
ff7a9030eb
@ -79,11 +79,7 @@ func shareMain(cmd *cobra.Command, args []string) (err error) {
|
||||
return err
|
||||
}
|
||||
|
||||
// TODO(jeff): we have to have the server side of things expecting macaroons
|
||||
// before we can change libuplink to use macaroons because of all the tests.
|
||||
// For now, just use the raw macaroon library.
|
||||
|
||||
key, err := macaroon.ParseAPIKey(cfg.Client.APIKey)
|
||||
key, err := libuplink.ParseAPIKey(cfg.Client.APIKey)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
@ -3,17 +3,34 @@
|
||||
|
||||
package uplink
|
||||
|
||||
import (
|
||||
"storj.io/storj/pkg/macaroon"
|
||||
)
|
||||
|
||||
// APIKey represents an access credential to certain resources
|
||||
type APIKey struct {
|
||||
key string
|
||||
key *macaroon.APIKey
|
||||
}
|
||||
|
||||
// Serialize serializes the API key to a string
|
||||
func (a APIKey) Serialize() string {
|
||||
return a.key
|
||||
return a.key.Serialize()
|
||||
}
|
||||
|
||||
// ParseAPIKey parses an API key
|
||||
func ParseAPIKey(val string) (APIKey, error) {
|
||||
return APIKey{key: val}, nil
|
||||
k, err := macaroon.ParseAPIKey(val)
|
||||
if err != nil {
|
||||
return APIKey{}, err
|
||||
}
|
||||
return APIKey{key: k}, nil
|
||||
}
|
||||
|
||||
// Restrict generates a new APIKey with the provided Caveat attached.
|
||||
func (a APIKey) Restrict(caveat macaroon.Caveat) (APIKey, error) {
|
||||
k, err := a.key.Restrict(caveat)
|
||||
if err != nil {
|
||||
return APIKey{}, err
|
||||
}
|
||||
return APIKey{key: k}, nil
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user