Skip to content
This repository has been archived by the owner on Oct 14, 2021. It is now read-only.

RFC-3: Add protocol basic #3

Merged
merged 4 commits into from
Aug 4, 2021
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 23 additions & 0 deletions credential.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,10 @@ const (
// Storage service like gcs will take token files as input, we provide base64 protocol so that user
// can pass token binary data directly.
ProtocolBase64 = "base64"
// ProtocolBasic will hold user and password credential.
//
// value = [User, Password]
npofsi marked this conversation as resolved.
Show resolved Hide resolved
ProtocolBasic = "basic"
)

// Credential will provide credential protocol and values.
Expand Down Expand Up @@ -104,6 +108,18 @@ func (p Credential) Base64() (value string) {
return p.args[0]
}

func (p Credential) Basic() (user, password string) {
if p.protocol != ProtocolBasic {
panic(Error{
Op: "basic",
Err: ErrInvalidValue,
Protocol: p.protocol,
Values: p.args,
})
}
return p.args[0], p.args[1]
}

// Parse will parse config string to create a credential Credential.
func Parse(cfg string) (Credential, error) {
s := strings.Split(cfg, ":")
Expand All @@ -119,6 +135,8 @@ func Parse(cfg string) (Credential, error) {
return NewEnv(), nil
case ProtocolBase64:
return NewBase64(s[1]), nil
case ProtocolBasic:
npofsi marked this conversation as resolved.
Show resolved Hide resolved
return NewBasic(s[1], s[2]), nil
default:
return Credential{}, &Error{"parse", ErrUnsupportedProtocol, s[0], nil}
}
Expand Down Expand Up @@ -148,3 +166,8 @@ func NewEnv() Credential {
func NewBase64(value string) Credential {
return Credential{ProtocolBase64, []string{value}}
}

// NewBasic create a basic provider.
func NewBasic(user, password string) Credential {
return Credential{ProtocolBasic, []string{user, password}}
}
33 changes: 33 additions & 0 deletions docs/rfcs/1-add-protocol-basic.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
- Author: npofsi [[email protected]](mailto:[email protected])
npofsi marked this conversation as resolved.
Show resolved Hide resolved
- Start Date: 2021-08-02
- RFC PR: N/A
npofsi marked this conversation as resolved.
Show resolved Hide resolved
- Tracking Issue: [beyondstorage/go-credential#1](https://github.com/beyondstorage/go-credential/issues/1)

# RFC-1:
npofsi marked this conversation as resolved.
Show resolved Hide resolved


## Background

Some services don't support other credentials, but user or password.


## Proposal

Add protocol `basic`. Like `hmac`, `basic` have two parameters, corresponding to user and password of an account.

For example, go-service-ftp need a account to sign in, like

`ftp://xxx?credential=basic:user:password`

## Rationale

- Account is the only certification to some platform.
- Account is a basic method to identify quests.

## Compatibility

Will just add a choose to use protocol `basic`.

## Implementation

Just need to parse `basic` like `hmac`.