Skip to content

Commit

Permalink
adding config to client.go; removing from table.go, setting up for fu…
Browse files Browse the repository at this point in the history
…ture tables
  • Loading branch information
virtualbeck committed Jun 22, 2023
1 parent e3bd42f commit c1f894d
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 20 deletions.
22 changes: 19 additions & 3 deletions client/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,18 @@ package client
import (
"context"
"fmt"
"os"

"github.com/TheJumpCloud/jcapi"
"github.com/cloudquery/plugin-pb-go/specs"
"github.com/cloudquery/plugin-sdk/v3/plugins/source"
"github.com/cloudquery/plugin-sdk/v3/schema"
"github.com/rs/zerolog"
)

type Client struct {
Logger zerolog.Logger
Logger zerolog.Logger
JumpCloud *jcapi.JCAPI
}

func (c *Client) ID() string {
Expand All @@ -25,9 +28,22 @@ func New(ctx context.Context, logger zerolog.Logger, s specs.Source, opts source
if err := s.UnmarshalSpec(&pluginSpec); err != nil {
return nil, fmt.Errorf("failed to unmarshal plugin spec: %w", err)
}
// TODO: Add your client initialization here
var (
apiURL = config("JUMPCLOUD_API_URL", "https://console.jumpcloud.com/api")
apiKey = config("JUMPCLOUD_API_KEY", "")
apiClientV1 = jcapi.NewJCAPI(apiKey, apiURL)
)

return &Client{
Logger: logger,
Logger: logger,
JumpCloud: &apiClientV1,
}, nil
}

func config(s, e string) string {
envVar := os.Getenv(s)
if envVar != "" {
return envVar
}
return e
}
20 changes: 3 additions & 17 deletions resources/table.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,18 +3,11 @@ package resources
import (
"context"
"fmt"
"os"

"github.com/TheJumpCloud/jcapi"
"github.com/cloudquery/plugin-sdk/v3/schema"
"github.com/cloudquery/plugin-sdk/v3/transformers"
)

var (
apiURL = config("JUMPCLOUD_API_URL", "https://console.jumpcloud.com/api")
apiKey = config("JUMPCLOUD_API_KEY", "")
apiClientV1 = jcapi.NewJCAPI(apiKey, apiURL)
isGroups = true //IDK What this is
"github.com/virtualbeck/cq-source-jumpcloud/client"
)

func UsersTable() *schema.Table {
Expand All @@ -26,7 +19,8 @@ func UsersTable() *schema.Table {
}

func fetchUsers(ctx context.Context, meta schema.ClientMeta, parent *schema.Resource, res chan<- any) error {
userList, err := apiClientV1.GetSystemUsers(!isGroups)
c := meta.(*client.Client)
userList, err := c.JumpCloud.GetSystemUsers(false)
if err != nil {
return fmt.Errorf("Could not read system users, err='%s'\n", err)
}
Expand All @@ -37,11 +31,3 @@ func fetchUsers(ctx context.Context, meta schema.ClientMeta, parent *schema.Reso

return nil
}

func config(s, e string) string {
envVar := os.Getenv(s)
if envVar != "" {
return envVar
}
return e
}

0 comments on commit c1f894d

Please sign in to comment.