Skip to content

Commit

Permalink
Add more comments
Browse files Browse the repository at this point in the history
  • Loading branch information
jirwin committed Nov 28, 2022
1 parent ae641da commit a6996b0
Show file tree
Hide file tree
Showing 9 changed files with 21 additions and 2 deletions.
1 change: 1 addition & 0 deletions cmd/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +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
type config struct {
cli.BaseConfig `mapstructure:",squash"` // Puts the base config options in the same place as the connector options
}
Expand Down
4 changes: 4 additions & 0 deletions cmd/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,10 @@ import (

var version = "dev"

// This is the primary entrypoint for the connector. It uses the SDK to standardize command line flags.
// By using `cli.NewCmd()` from the SDK allows the SDK to be in charge of the lifecycle of your connector logic.
// You are able to add additional flags and update the configuration in case your connector needs more input from the user
// in order to run.
func main() {
ctx := context.Background()

Expand Down
2 changes: 2 additions & 0 deletions pkg/client/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,8 @@ type Project struct {
GroupAssignments []string
}

// This 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{}

// ListUsers returns all the users from the database
Expand Down
1 change: 1 addition & 0 deletions pkg/connector/connector.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ type Demo struct {
client *client.Client
}

// ResourceSyncers returns a ResourceSyncer for each resource type that should be synced from the upstream service.
func (d *Demo) ResourceSyncers(ctx context.Context) []connectorbuilder.ResourceSyncer {
return []connectorbuilder.ResourceSyncer{
newUserBuilder(d.client),
Expand Down
2 changes: 2 additions & 0 deletions pkg/connector/groups.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +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
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
2 changes: 2 additions & 0 deletions pkg/connector/projects.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ func (o *projectBuilder) ResourceType(ctx context.Context) *v2.ResourceType {
return projectResourceType
}

// List returns all the projects from the database as resource objects
// Projects don't include any traits because they don't match the 'shape' of any well known types.
func (o *projectBuilder) List(ctx context.Context, parentResourceID *v2.ResourceId, pToken *pagination.Token) ([]*v2.Resource, string, annotations.Annotations, error) {
projects, err := o.client.ListProjects(ctx)
if err != nil {
Expand Down
6 changes: 5 additions & 1 deletion pkg/connector/resource_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,25 +4,29 @@ import (
v2 "github.com/conductorone/baton-sdk/pb/c1/connector/v2"
)

// 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
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
var roleResourceType = &v2.ResourceType{
Id: "role",
DisplayName: "Role",
Traits: []v2.ResourceType_Trait{v2.ResourceType_TRAIT_ROLE},
}

// Projects don't match any of the well-known resource traits
// The project resource type is for all project objects from the database
// Projects don't match any of the well-known resource traits.
var projectResourceType = &v2.ResourceType{
Id: "project",
DisplayName: "Project",
Expand Down
3 changes: 2 additions & 1 deletion pkg/connector/roles.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,8 @@ func (o *roleBuilder) ResourceType(ctx context.Context) *v2.ResourceType {
return roleResourceType
}

// List returns a slice of resources, one for each role returned by the client
// 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
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
2 changes: 2 additions & 0 deletions pkg/connector/users.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ func (o *userBuilder) ResourceType(ctx context.Context) *v2.ResourceType {
return userResourceType
}

// List returns all the users from the database as resource objects.
// 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

0 comments on commit a6996b0

Please sign in to comment.