Skip to content

Commit

Permalink
More lint fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
jirwin committed Nov 28, 2022
1 parent a6996b0 commit eb12d9e
Show file tree
Hide file tree
Showing 13 changed files with 45 additions and 43 deletions.
2 changes: 1 addition & 1 deletion cmd/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import (
)

// config defines the external configuration required for the connector to run.
// You can add additional fields here and have them automatically mapped to any additional command line flags
// You can add additional fields here and have them automatically mapped to any additional command line flags.
type config struct {
cli.BaseConfig `mapstructure:",squash"` // Puts the base config options in the same place as the connector options
}
Expand Down
4 changes: 1 addition & 3 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ module github.com/conductorone/baton-demo
go 1.19

require (
github.com/conductorone/baton-sdk v0.0.7
github.com/conductorone/baton-sdk v0.0.8
github.com/grpc-ecosystem/go-grpc-middleware v1.3.0
go.uber.org/zap v1.23.0
)
Expand Down Expand Up @@ -70,5 +70,3 @@ require (
modernc.org/memory v1.4.0 // indirect
modernc.org/sqlite v1.19.2 // indirect
)

replace github.com/conductorone/baton-sdk => /Users/jirwin/projects/baton-sdk
2 changes: 2 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,8 @@ github.com/client9/misspell v0.3.4/go.mod h1:qj6jICC3Q7zFZvVWo7KLAzC3yx5G7kyvSDk
github.com/cncf/udpa/go v0.0.0-20191209042840-269d4d468f6f/go.mod h1:M8M6+tZqaGXZJjfX53e64911xZQV5JYwmTeXPW+k8Sc=
github.com/cncf/udpa/go v0.0.0-20200629203442-efcf912fb354/go.mod h1:WmhPx2Nbnhtbo57+VJT5O0JRkEi1Wbu0z5j0R8u5Hbk=
github.com/cncf/udpa/go v0.0.0-20201120205902-5459f2c99403/go.mod h1:WmhPx2Nbnhtbo57+VJT5O0JRkEi1Wbu0z5j0R8u5Hbk=
github.com/conductorone/baton-sdk v0.0.8 h1:uZmX91T2BT7eOKOB13b4FrEKhJnKCkh4MM49dgjSLcI=
github.com/conductorone/baton-sdk v0.0.8/go.mod h1:jPdcy08LmTIPzgZcSOo7mviSAG0NUbjavg/1LpCTeOI=
github.com/cpuguy83/go-md2man/v2 v2.0.2/go.mod h1:tgQtvFlXSQOSOSIRvRPT7W67SCa46tRHOmNcaadrF8o=
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
Expand Down
37 changes: 23 additions & 14 deletions pkg/client/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,17 +41,26 @@ type Project struct {
GroupAssignments []string
}

// This is a simple example client. While this client would normally be responsible for communicating with an upstream
// Client is a simple example client. While this client would normally be responsible for communicating with an upstream.
// API, for this demo the client is only working with in-memory data.
type Client struct{}
type Client struct {
db *database
}

func NewClient() *Client {
c := &Client{}
c.db = generateDB()

return c
}

// ListUsers returns all the users from the database
// ListUsers returns all the users from the database.
func (c *Client) ListUsers(ctx context.Context) ([]*User, error) {
log := ctxzap.Extract(ctx)

log.Info("listing users", zap.Int("user_count", len(db.Users)))
log.Info("listing users", zap.Int("user_count", len(c.db.Users)))

return db.Users, nil
return c.db.Users, nil
}

// GetUser returns the user requested if it exists, else returns an error.
Expand All @@ -70,13 +79,13 @@ func (c *Client) GetUser(ctx context.Context, userID string) (*User, error) {
return nil, fmt.Errorf("user not found")
}

// ListGroups returns all the groups from the database
// ListGroups returns all the groups from the database.
func (c *Client) ListGroups(ctx context.Context) ([]*Group, error) {
log := ctxzap.Extract(ctx)

log.Info("listing groups", zap.Int("group_count", len(db.Groups)))
log.Info("listing groups", zap.Int("group_count", len(c.db.Groups)))

return db.Groups, nil
return c.db.Groups, nil
}

// GetGroup returns the group requested if it exists, else returns an error.
Expand All @@ -95,13 +104,13 @@ func (c *Client) GetGroup(ctx context.Context, groupID string) (*Group, error) {
return nil, fmt.Errorf("group not found")
}

// ListRoles returns all the roles from the database
// ListRoles returns all the roles from the database.
func (c *Client) ListRoles(ctx context.Context) ([]*Role, error) {
log := ctxzap.Extract(ctx)

log.Info("listing roles", zap.Int("role_count", len(db.Roles)))
log.Info("listing roles", zap.Int("role_count", len(c.db.Roles)))

return db.Roles, nil
return c.db.Roles, nil
}

// GetRole returns the role requested if it exists, else returns an error.
Expand All @@ -120,13 +129,13 @@ func (c *Client) GetRole(ctx context.Context, roleID string) (*Role, error) {
return nil, fmt.Errorf("role not found")
}

// ListProjects returns all the projects from the database
// ListProjects returns all the projects from the database.
func (c *Client) ListProjects(ctx context.Context) ([]*Project, error) {
log := ctxzap.Extract(ctx)

log.Info("listing projects", zap.Int("project_count", len(db.Roles)))
log.Info("listing projects", zap.Int("project_count", len(c.db.Roles)))

return db.Projects, nil
return c.db.Projects, nil
}

// GetProject returns the project requested if it exists, else returns an error.
Expand Down
8 changes: 4 additions & 4 deletions pkg/client/data.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,8 @@ type database struct {
Projects []*Project
}

var db *database

func init() {
db = &database{}
func generateDB() *database {
db := &database{}

db.Users = []*User{
{
Expand Down Expand Up @@ -105,4 +103,6 @@ func init() {
},
},
}

return db
}
4 changes: 2 additions & 2 deletions pkg/connector/connector.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,10 +43,10 @@ func (d *Demo) Validate(ctx context.Context) (annotations.Annotations, error) {
return nil, nil
}

// New returns a new instance of the Demo connector
// New returns a new instance of the Demo connector.
func New(ctx context.Context) (*Demo, error) {
demo := &Demo{
client: &client.Client{},
client: client.NewClient(),
}

return demo, nil
Expand Down
8 changes: 4 additions & 4 deletions pkg/connector/groups.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@ func (o *groupBuilder) ResourceType(ctx context.Context) *v2.ResourceType {
return groupResourceType
}

// List returns all the groups from the database as resource objects
// Groups include the GroupTrait because they have the 'shape' of the well known Group type
// List returns all the groups from the database as resource objects.
// Groups include the GroupTrait because they have the 'shape' of the well known Group type.
func (o *groupBuilder) List(ctx context.Context, parentResourceID *v2.ResourceId, pToken *pagination.Token) ([]*v2.Resource, string, annotations.Annotations, error) {
groups, err := o.client.ListGroups(ctx)
if err != nil {
Expand Down Expand Up @@ -56,7 +56,7 @@ func (o *groupBuilder) List(ctx context.Context, parentResourceID *v2.ResourceId
return ret, "", nil, nil
}

// Entitlements returns a membership and admin entitlement
// Entitlements returns a membership and admin entitlement.
func (o *groupBuilder) Entitlements(ctx context.Context, resource *v2.Resource, _ *pagination.Token) ([]*v2.Entitlement, string, annotations.Annotations, error) {
var ret []*v2.Entitlement

Expand All @@ -83,7 +83,7 @@ func (o *groupBuilder) Entitlements(ctx context.Context, resource *v2.Resource,
return ret, "", nil, nil
}

// Grants returns grant information for group administrators and members
// Grants returns grant information for group administrators and members.
func (o *groupBuilder) Grants(ctx context.Context, resource *v2.Resource, pToken *pagination.Token) ([]*v2.Grant, string, annotations.Annotations, error) {
grp, err := o.client.GetGroup(ctx, resource.Id.Resource)
if err != nil {
Expand Down
1 change: 0 additions & 1 deletion pkg/connector/projects.go
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,6 @@ func (o *projectBuilder) Grants(ctx context.Context, resource *v2.Resource, pTok
Principal: memberPrincipal,
})
}

}

return ret, "", nil, nil
Expand Down
6 changes: 3 additions & 3 deletions pkg/connector/resource_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,21 +4,21 @@ import (
v2 "github.com/conductorone/baton-sdk/pb/c1/connector/v2"
)

// The user resource type is for all user objects from the database
// The user resource type is for all user objects from the database.
var userResourceType = &v2.ResourceType{
Id: "user",
DisplayName: "User",
Traits: []v2.ResourceType_Trait{v2.ResourceType_TRAIT_USER},
}

// The group resource type is for all group objects from the database
// The group resource type is for all group objects from the database.
var groupResourceType = &v2.ResourceType{
Id: "group",
DisplayName: "Group",
Traits: []v2.ResourceType_Trait{v2.ResourceType_TRAIT_GROUP},
}

// The role resource type is for all role objects from the database
// The role resource type is for all role objects from the database.
var roleResourceType = &v2.ResourceType{
Id: "role",
DisplayName: "Role",
Expand Down
5 changes: 2 additions & 3 deletions pkg/connector/roles.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ func (o *roleBuilder) ResourceType(ctx context.Context) *v2.ResourceType {
}

// List returns all the roles from the database as resource objects
// Roles include the role trait because they have the 'shape' of the well known Role type
// Roles include the role trait because they have the 'shape' of the well known Role type.
func (o *roleBuilder) List(ctx context.Context, parentResourceID *v2.ResourceId, pToken *pagination.Token) ([]*v2.Resource, string, annotations.Annotations, error) {
roles, err := o.client.ListRoles(ctx)
if err != nil {
Expand Down Expand Up @@ -52,7 +52,7 @@ func (o *roleBuilder) List(ctx context.Context, parentResourceID *v2.ResourceId,
return ret, "", nil, nil
}

// Entitlements returns an assignment entitlement
// Entitlements returns an assignment entitlement.
func (o *roleBuilder) Entitlements(_ context.Context, resource *v2.Resource, _ *pagination.Token) ([]*v2.Entitlement, string, annotations.Annotations, error) {
var ret []*v2.Entitlement

Expand Down Expand Up @@ -158,7 +158,6 @@ func (o *roleBuilder) Grants(ctx context.Context, resource *v2.Resource, pToken
Principal: memberPrincipal,
})
}

}

return ret, "", nil, nil
Expand Down
4 changes: 2 additions & 2 deletions pkg/connector/users.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ func (o *userBuilder) ResourceType(ctx context.Context) *v2.ResourceType {
}

// List returns all the users from the database as resource objects.
// Users include a UserTrait because they are the 'shape' of a standard user
// Users include a UserTrait because they are the 'shape' of a standard user.
func (o *userBuilder) List(ctx context.Context, parentResourceID *v2.ResourceId, pToken *pagination.Token) ([]*v2.Resource, string, annotations.Annotations, error) {
users, err := o.client.ListUsers(ctx)
if err != nil {
Expand Down Expand Up @@ -56,7 +56,7 @@ func (o *userBuilder) Entitlements(_ context.Context, resource *v2.Resource, _ *
return nil, "", nil, nil
}

// Grants always returns an empty slice for users since they don't have any entitlements
// Grants always returns an empty slice for users since they don't have any entitlements.
func (o *userBuilder) Grants(ctx context.Context, resource *v2.Resource, pToken *pagination.Token) ([]*v2.Grant, string, annotations.Annotations, error) {
return nil, "", nil, nil
}
Expand Down

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

3 changes: 1 addition & 2 deletions vendor/modules.txt
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ github.com/aws/smithy-go/time
github.com/aws/smithy-go/transport/http
github.com/aws/smithy-go/transport/http/internal/io
github.com/aws/smithy-go/waiter
# github.com/conductorone/baton-sdk v0.0.7 => /Users/jirwin/projects/baton-sdk
# github.com/conductorone/baton-sdk v0.0.8
## explicit; go 1.19
github.com/conductorone/baton-sdk/internal/connector
github.com/conductorone/baton-sdk/internal/dotc1z
Expand Down Expand Up @@ -438,4 +438,3 @@ modernc.org/memory
# modernc.org/sqlite v1.19.2
## explicit; go 1.17
modernc.org/sqlite/lib
# github.com/conductorone/baton-sdk => /Users/jirwin/projects/baton-sdk

0 comments on commit eb12d9e

Please sign in to comment.