Skip to content
This repository has been archived by the owner on Feb 16, 2023. It is now read-only.

Release v0.27.0 #180

Merged
merged 79 commits into from
Mar 26, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
79 commits
Select commit Hold shift + click to select a range
7d945ed
Add acl iterator
Marton6 Dec 19, 2019
2f74f23
Add acl access level iterator
Marton6 Dec 19, 2019
b6d8fc6
Add repo iterator to RepoService and MeService
Marton6 Dec 19, 2019
a2962ec
Add repo iterators for repo service and me service
Marton6 Dec 20, 2019
d8ba77f
Update access rule and access level iterators
Marton6 Dec 20, 2019
2371156
Add org iterator
Marton6 Dec 20, 2019
5886ec1
Add org member iterator
Marton6 Dec 20, 2019
6001aab
Add repo account iterator
Marton6 Dec 20, 2019
05c1ed4
Add repo service iterator and service iterator
Marton6 Dec 20, 2019
5ece0c0
Add repo user iterator
Marton6 Dec 20, 2019
6b73131
Add secret version iterator
Marton6 Dec 20, 2019
b584203
Update Fakes
Marton6 Dec 20, 2019
e08e263
Merge remote-tracking branch 'origin/develop' into feature/add-iterat…
SimonBarendse Dec 20, 2019
c199a7a
Add example for directory creation
Marton6 Dec 21, 2019
6b152cb
Fix typo
Marton6 Dec 21, 2019
d9e7d1e
Rephrase comment
Marton6 Dec 21, 2019
d61b326
Fix comment
Marton6 Dec 21, 2019
d66b45b
Fix typo
Marton6 Dec 23, 2019
bf60f28
Update AccessRule iterator to use paginator
Marton6 Dec 25, 2019
0b0f928
Rename PaginatorConstructorWithFetch to PaginatorFactory
Marton6 Jan 6, 2020
08298fe
Export parameters of access rule iterator
Marton6 Jan 6, 2020
3e47a5d
Run goimports
Marton6 Jan 6, 2020
74f2922
Add access level iterator
Marton6 Jan 6, 2020
c6986b1
Add repo iterator to me service and repo service
Marton6 Jan 6, 2020
aa1e6c8
Add org iterator to org service
Marton6 Jan 6, 2020
ac85391
Add org member iterator to org member service
Marton6 Jan 6, 2020
4d75f31
Add Account iterator to repo service
Marton6 Jan 6, 2020
8399ca2
Add service iterator to service service
Marton6 Jan 6, 2020
c40d08c
Add user iterator to repo user service
Marton6 Jan 6, 2020
057a0eb
Add secret version iterator to secret version service
Marton6 Jan 6, 2020
5c67732
Fix repo service iterator
Marton6 Jan 6, 2020
a702b58
Fix typos in godoc
Marton6 Jan 7, 2020
4608682
Undo unneeded change
Marton6 Jan 7, 2020
219af25
Simplify access rule iterator default parameter assignment
Marton6 Jan 7, 2020
ae91082
Update account iterator param names
Marton6 Jan 7, 2020
ed47f9c
Fix account iterator params
Marton6 Jan 7, 2020
917e7e0
Add org iterator params to org iterator
Marton6 Jan 7, 2020
c69ad65
Update iterators to use the http client
Marton6 Jan 7, 2020
3363a2a
Fix org service mock
Marton6 Jan 7, 2020
de541a8
Fix casting bug in most iterators
Marton6 Jan 7, 2020
1f2d5f7
Add namespace to repo iterator params and remove IteratorMine from re…
Marton6 Jan 7, 2020
1c20bed
Add default params for secret version iterator when nil is provided
Marton6 Jan 9, 2020
8553a8b
Fix error not checked
Marton6 Jan 9, 2020
75448fd
Simplify error handling in repo service iterator
Marton6 Jan 9, 2020
8049283
Simplify access level iterator default parameter assignment
Marton6 Jan 9, 2020
376d204
Improve secret version iterator godoc
Marton6 Jan 9, 2020
96f5848
Fix secret version iterator godoc
Marton6 Jan 9, 2020
d06192d
Improve godoc comment
Marton6 Jan 9, 2020
81a06d0
Improve secret version iterator godoc
Marton6 Jan 9, 2020
a2dc870
Merge pull request #170 from secrethub/release/v0.26.0
jpcoenen Jan 27, 2020
3a76eaf
Deprecate list functions
Marton6 Jan 28, 2020
c65034b
Remove 'deprecated' comment from SecretService ListEvents
Marton6 Jan 31, 2020
86a3081
Merge pull request #163 from secrethub/feature/add-iterator-functions
mackenbach Feb 11, 2020
c75e605
Trim all v prefixes in user agent
jpcoenen Feb 24, 2020
cb5f26c
Merge pull request #171 from secrethub/feature/user-agent-trim-v
jpcoenen Feb 25, 2020
f16c374
Update secret not found error message
Marton6 Feb 25, 2020
1dce0fb
Change secret not found error to a status error
Marton6 Feb 26, 2020
8a57efd
Update secret not found error wrapping
Marton6 Feb 26, 2020
ae32fec
Update api.IsErrNotFound to check for secret not found errors
Marton6 Mar 3, 2020
05d9382
Update fake SecretVersionService to have iterator function
Marton6 Mar 3, 2020
99713a1
Add human-readable charset
Marton6 Mar 3, 2020
886ad55
Add human readable charset as global variable
Marton6 Mar 4, 2020
95ab676
Merge pull request #174 from secrethub/feature/human-readable-charset
SimonBarendse Mar 4, 2020
026eda0
Merge pull request #173 from secrethub/feature/fix-fake-secret-versio…
SimonBarendse Mar 4, 2020
daea8df
Update SecretNotFoundError
Marton6 Mar 4, 2020
0cc8bde
goimports
SimonBarendse Mar 4, 2020
f0950a7
gofmt
SimonBarendse Mar 4, 2020
b6684c0
gofmt
SimonBarendse Mar 4, 2020
a55bae1
Refactor fakeclient to use functions
Marton6 Mar 5, 2020
06577e2
Run gofmt and goimports
Marton6 Mar 5, 2020
a6b707d
Update go version to 1.13
Marton6 Mar 17, 2020
ea45ce3
Update Repo Not Found error to include repo path
Marton6 Mar 17, 2020
92df224
Update repo not found error message
Marton6 Mar 17, 2020
34f204d
Merge pull request #178 from secrethub/feature/update-to-go1.13
SimonBarendse Mar 18, 2020
24b8472
Merge remote-tracking branch 'origin/develop' into feature/improved-s…
SimonBarendse Mar 18, 2020
340f69a
Merge pull request #172 from secrethub/feature/improved-secret-not-fo…
SimonBarendse Mar 18, 2020
a558dcf
Merge pull request #179 from secrethub/feature/repo-path-in-not-found…
SimonBarendse Mar 23, 2020
da077da
Merge pull request #176 from secrethub/feature/use-fake-client-funcs
SimonBarendse Mar 23, 2020
8d0dcaa
Bump version to v0.27.0
SimonBarendse Mar 23, 2020
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
4 changes: 2 additions & 2 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ version: 2
jobs:
test:
docker:
- image: circleci/golang:1.12
- image: circleci/golang:1.13
steps:
- checkout
- restore_cache:
Expand All @@ -16,7 +16,7 @@ jobs:
- run: make test
verify-version:
docker:
- image: circleci/golang:1.12
- image: circleci/golang:1.13
steps:
- checkout
- restore_cache:
Expand Down
8 changes: 5 additions & 3 deletions internals/api/server_errors.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package api

import (
"errors"
"net/http"

"fmt"
Expand Down Expand Up @@ -40,7 +41,7 @@ var (
ErrSignatureNotVerified = errHub.Code("invalid_signature").StatusError("request was not signed by a valid credential", http.StatusUnauthorized)

// Repos
ErrRepoNotFound = errHub.Code("repo_not_found").StatusError("Repo not found", http.StatusNotFound)
ErrRepoNotFound = errHub.Code("repo_not_found").StatusErrorPref("Repo '%s' not found", http.StatusNotFound)
ErrRepoAlreadyExists = errHub.Code("repo_already_exists").StatusError("Repo already exists, please create a different repo", http.StatusConflict)

// Dirs
Expand Down Expand Up @@ -104,9 +105,10 @@ var (

// IsErrNotFound returns whether the given error is caused by a un-existing resource.
func IsErrNotFound(err error) bool {
statusError, ok := err.(errio.PublicStatusError)
var publicStatusError errio.PublicStatusError
ok := errors.As(err, &publicStatusError)
if !ok {
return false
}
return statusError.StatusCode == 404
return publicStatusError.StatusCode == 404
}
4 changes: 4 additions & 0 deletions pkg/randchar/generator.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@ var (
All = Alphanumeric.Add(Symbols)
// Similar defines a character set containing similar looking characters.
Similar = NewCharset("iIlL1oO0")
// HumanReadable defines a character set containing all alphanumeric characters except the similar ones.
HumanReadable = Alphanumeric.Subtract(Similar)

// DefaultRand defines the default random generator to use. You can create
// your own generators using NewRand.
Expand Down Expand Up @@ -263,6 +265,8 @@ func CharsetByName(charsetName string) (Charset, bool) {
return All, true
case "similar":
return Similar, true
case "human-readable":
return HumanReadable, true
default:
return Charset{}, false
}
Expand Down
166 changes: 164 additions & 2 deletions pkg/secrethub/acl.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"github.com/secrethub/secrethub-go/internals/api"
"github.com/secrethub/secrethub-go/internals/api/uuid"
"github.com/secrethub/secrethub-go/internals/errio"
"github.com/secrethub/secrethub-go/pkg/secrethub/iterator"
)

// AccessRuleService handles operations on access rules from SecretHub.
Expand All @@ -14,13 +15,20 @@ type AccessRuleService interface {
Set(path string, permission string, accountName string) (*api.AccessRule, error)
// Delete removes the accessrule for the given directory and account.
Delete(path string, accountName string) error
// List etrieves all access rules that apply to a directory, including
// List retrieves all access rules that apply to a directory, including
// rules that apply to its children up to a specified depth. When ancestors is set
// to true, it also includes rules for any parent directories. When the depth is
// set to -1, all children are retrieved without limit.
// Deprecated: Use iterator function instead.
List(path string, depth int, ancestors bool) ([]*api.AccessRule, error)
// Iterator returns an iterator that retrieves all access rules that apply to a
// directory.
Iterator(path string, _ *AccessRuleIteratorParams) AccessRuleIterator
// ListLevels lists the access levels on the given directory.
// Deprecated: Use iterator function instead.
ListLevels(path string) ([]*api.AccessLevel, error)
// LevelIterator returns an iterator that retrieves all access levels on the given directory.
LevelIterator(path string, _ *AccessLevelIteratorParams) AccessLevelIterator
}

func newAccessRuleService(client *Client) AccessRuleService {
Expand Down Expand Up @@ -87,7 +95,7 @@ func (s accessRuleService) Get(path string, accountName string) (*api.AccessRule
return accessRule, nil
}

// List etrieves all access rules that apply to a directory, including
// List retrieves all access rules that apply to a directory, including
// rules that apply to its children up to a specified depth. When ancestors is set
// to true, it also includes rules for any parent directories. When the depth is
// set to -1, all children are retrieved without limit.
Expand Down Expand Up @@ -286,3 +294,157 @@ func (c *Client) getAccessLevel(path api.BlindNamePath, accountName api.AccountN

return accessLevel, nil
}

// Iterator returns an iterator that retrieves all access rules that apply to a
// directory.
func (s accessRuleService) Iterator(path string, params *AccessRuleIteratorParams) AccessRuleIterator {
if params == nil {
params = &AccessRuleIteratorParams{}
}

depth := -1
if params.Depth != nil {
depth = int(*params.Depth)
}
ancestors := params.Ancestors

return &accessRuleIterator{
iterator: iterator.New(
iterator.PaginatorFactory(
func() ([]interface{}, error) {
p, err := api.NewDirPath(path)
if err != nil {
return nil, errio.Error(err)
}

blindName, err := s.client.convertPathToBlindName(p)
if err != nil {
return nil, errio.Error(err)
}

accessRules, err := s.client.httpClient.ListAccessRules(blindName, depth, ancestors)
if err != nil {
return nil, errio.Error(err)
}

res := make([]interface{}, len(accessRules))
for i, element := range accessRules {
res[i] = element
}
return res, nil
},
),
),
}
}

// LevelIterator returns an iterator that retrieves all access levels on the given directory.
func (s accessRuleService) LevelIterator(path string, _ *AccessLevelIteratorParams) AccessLevelIterator {
return &accessLevelIterator{
iterator: iterator.New(
iterator.PaginatorFactory(
func() ([]interface{}, error) {
p, err := api.NewDirPath(path)
if err != nil {
return nil, errio.Error(err)
}

blindName, err := s.client.convertPathToBlindName(p)
if err != nil {
return nil, errio.Error(err)
}

rules, err := s.client.httpClient.ListAccessRules(blindName, 0, true)
if err != nil {
return nil, errio.Error(err)
}

dir, err := s.dirService.GetTree(path, 0, false)
if err != nil {
return nil, errio.Error(err)
}

rights := make(map[uuid.UUID][]*api.AccessRule)
for _, rule := range rules {
list := rights[rule.AccountID]
rights[rule.AccountID] = append(list, rule)
}

accessLevels := make([]*api.AccessLevel, len(rights))
i := 0
for _, list := range rights {
first := list[0]
maxPerm := first.Permission
for _, rule := range list {
if maxPerm < rule.Permission {
maxPerm = rule.Permission
}
}

accessLevels[i] = &api.AccessLevel{
Account: first.Account,
AccountID: first.AccountID,
DirID: dir.RootDir.DirID, // add this for completeness
Permission: maxPerm,
}

i++
}

res := make([]interface{}, len(accessLevels))
for i, element := range accessLevels {
res[i] = element
}
return res, nil
},
),
),
}
}

// AccessLevelIterator iterates over access rules.
type AccessRuleIterator interface {
Next() (api.AccessRule, error)
}

type accessRuleIterator struct {
iterator iterator.Iterator
}

// Next returns the next access rule or iterator.Done if all of them have been returned.
func (it *accessRuleIterator) Next() (api.AccessRule, error) {
item, err := it.iterator.Next()
if err != nil {
return api.AccessRule{}, err
}

return *item.(*api.AccessRule), nil
}

// AccessRuleIteratorParams specify parameters used when listing access rules.
type AccessRuleIteratorParams struct {
Depth *uint // Depth defines the depth of traversal for the iterator, nil means listing all subdirectories.
Ancestors bool // Ancestors defines whether the iterator should also list access rules of parent directories.
}

// AccessLevelIteratorParams defines the parameters used when listing access levels.
type AccessLevelIteratorParams struct{}

// AccessLevelIterator iterates over access levels.
type AccessLevelIterator interface {
Next() (api.AccessLevel, error)
}

type accessLevelIterator struct {
iterator iterator.Iterator
}

// Next returns the next access level or iterator.Done if all of them have been returned.
func (it *accessLevelIterator) Next() (api.AccessLevel, error) {
item, err := it.iterator.Next()
if err != nil {
return api.AccessLevel{}, err
}

return *item.(*api.AccessLevel), nil
}
6 changes: 3 additions & 3 deletions pkg/secrethub/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@ import (
"github.com/secrethub/secrethub-go/pkg/secrethub/internals/http"
)

const (
userAgentPrefix = "SecretHub/v1 secrethub-go/" + ClientVersion
var (
userAgentPrefix = "SecretHub/1.0 secrethub-go/" + strings.TrimPrefix(ClientVersion, "v")
)

// Errors
Expand Down Expand Up @@ -86,7 +86,7 @@ type AppInfo struct {
func (i AppInfo) userAgentSuffix() string {
res := i.Name
if i.Version != "" {
res += "/" + i.Version
res += "/" + strings.TrimPrefix(i.Version, "v")
}
return res
}
Expand Down
2 changes: 1 addition & 1 deletion pkg/secrethub/client_version.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@ package secrethub

// ClientVersion is the current version of the client
// Do not edit this unless you know what you're doing.
const ClientVersion = "v0.26.0"
const ClientVersion = "v0.27.0"
Loading