Skip to content
Open
Show file tree
Hide file tree
Changes from 8 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
45 changes: 44 additions & 1 deletion providers/goTo.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,17 @@
package providers

const GoTo Provider = "goTo"
import "github.com/amp-labs/connectors/common"

const (
GoTo Provider = "goTo"
// ModuleGoTo covers the api.getgo.com base URL, which serves multiple GoTo
// products (admin, meetings, webinars, etc). We name it just "goTo" so users
// don't have to guess which specific product it maps to.
ModuleGoTo common.ModuleID = "goTo"
ModuleGoToConnect common.ModuleID = "goToConnect"
)

// nolint: funlen
func init() {
SetInfo(GoTo, ProviderInfo{
DisplayName: "GoTo",
Expand Down Expand Up @@ -39,5 +49,38 @@ func init() {
Subscribe: false,
Write: false,
},
PostAuthInfoNeeded: true,
Metadata: &ProviderMetadata{
PostAuthentication: []MetadataItemPostAuthentication{
{
Name: "accountKey",
ModuleDependencies: &ModuleDependencies{
ModuleGoTo: ModuleDependency{},
ModuleGoToConnect: ModuleDependency{},
},
},
},
},
DefaultModule: ModuleGoTo,
Modules: &Modules{
ModuleGoTo: {
BaseURL: "https://api.getgo.com",
DisplayName: "GoTo",
Support: Support{
Read: false,
Subscribe: false,
Write: false,
},
},
ModuleGoToConnect: {
BaseURL: "https://api.goto.com",
DisplayName: "GoTo Connect",
Support: Support{
Read: false,
Subscribe: false,
Write: false,
},
},
},
})
}
78 changes: 78 additions & 0 deletions providers/goto/authmetadata.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
package gotoconn

import (
"context"
"strconv"

"github.com/amp-labs/connectors/common"
"github.com/amp-labs/connectors/common/urlbuilder"
"github.com/amp-labs/connectors/providers"
)

func (c *Connector) GetPostAuthInfo(ctx context.Context) (*common.PostAuthInfo, error) {
accountKey, err := c.retrieveAccountKey(ctx)
if err != nil {
return nil, err
}

if accountKey == "" {
return nil, common.ErrMissingExpectedValues
}

c.accountKey = accountKey
if c.gotoCore != nil {
c.gotoCore.SetAccountKey(accountKey)
}
Comment thread
immdipu marked this conversation as resolved.
Outdated

catalogVars := map[string]string{
"accountKey": accountKey,
}

return &common.PostAuthInfo{
CatalogVars: &catalogVars,
}, nil
}

func (c *Connector) retrieveAccountKey(ctx context.Context) (string, error) {
url, err := c.getMeURL()
if err != nil {
return "", err
}

resp, err := c.JSONHTTPClient().Get(ctx, url.String())
if err != nil {
return "", err
}

data, err := common.UnmarshalJSON[map[string]any](resp)
if err != nil {
return "", common.ErrFailedToUnmarshalBody
}

if data == nil {
return "", common.ErrMissingExpectedValues
}

rawAccountKey, ok := (*data)["accountKey"]
if !ok {
return "", common.ErrMissingExpectedValues
}

switch v := rawAccountKey.(type) {
case string:
return v, nil
case float64:
return strconv.FormatInt(int64(v), 10), nil
default:
return "", common.ErrMissingExpectedValues
}
}

func (c *Connector) getMeURL() (*urlbuilder.URL, error) {
// /me lives on the goTo (api.getgo.com) module, so we resolve that
// module's BaseURL explicitly — even when the connector was created
// with the goToConnect module selected.
baseURL := c.ProviderInfo().ReadModuleInfo(providers.ModuleGoTo).BaseURL

return urlbuilder.New(baseURL, "/admin/rest/v1/me")
}
18 changes: 18 additions & 0 deletions providers/goto/authmetamodel.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
package gotoconn

type AuthMetadataVars struct {
AccountKey string
}

// NewAuthMetadataVars parses map into the model.
func NewAuthMetadataVars(dictionary map[string]string) *AuthMetadataVars {
return &AuthMetadataVars{
AccountKey: dictionary["accountKey"],
}
}

func (v AuthMetadataVars) AsMap() *map[string]string {
return &map[string]string{
"accountKey": v.AccountKey,
}
}
99 changes: 99 additions & 0 deletions providers/goto/connector.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,99 @@
// Package gotoconn implements the GoTo connector.
//
// The package is named "gotoconn" instead of "goto" because "goto" is a
// reserved keyword in Go and cannot be used as a package identifier. The
// "conn" suffix is short for "connector".
package gotoconn

import (
"context"

"github.com/amp-labs/connectors"
"github.com/amp-labs/connectors/common"
"github.com/amp-labs/connectors/internal/components"
"github.com/amp-labs/connectors/providers"
"github.com/amp-labs/connectors/providers/goto/internal/gotocore"
)

type Connector struct {
// Basic connector
*components.Connector

// Require authenticated client & account
common.RequireAuthenticatedClient
common.PostAuthInfo

// gotoCore handles api.getgo.com endpoints (Webinar, etc).
gotoCore *gotocore.Adapter
gotoConnect *gotocore.Adapter

accountKey string
}

func NewConnector(params common.ConnectorParams) (*Connector, error) {
if params.Module == "" {
params.Module = providers.ModuleGoTo
}

conn, err := components.Initialize(providers.GoTo, params,
func(base *components.Connector) (*Connector, error) {
return &Connector{Connector: base}, nil
},
)
if err != nil {
return nil, err
}

authMetadata := NewAuthMetadataVars(params.Metadata)
conn.accountKey = authMetadata.AccountKey

if err := initModuleAdapters(conn, params); err != nil {
return nil, err
}

return conn, nil
}

func initModuleAdapters(conn *Connector, params common.ConnectorParams) error {
switch conn.Module() { //nolint:exhaustive
case providers.ModuleGoTo:
adapter, err := gotocore.NewAdapter(params, conn.accountKey)
if err != nil {
return err
}

conn.gotoCore = adapter
case providers.ModuleGoToConnect:
adapter, err := gotocore.NewAdapter(params, conn.accountKey)
if err != nil {
return err
}

conn.gotoConnect = adapter
default:
return common.ErrUnsupportedModule
}

return nil
}

// SetBaseURL fans the override out to any active module adapter so that
// unit tests pointing at a mock server reach the same host the top-level
// connector now uses.
func (c *Connector) SetBaseURL(newURL string) {
c.Connector.SetBaseURL(newURL)

if c.gotoCore != nil {
c.gotoCore.SetBaseURL(newURL)
}
Comment thread
immdipu marked this conversation as resolved.
}

func (c *Connector) ListObjectMetadata(
ctx context.Context, objectNames []string,
) (*connectors.ListObjectMetadataResult, error) {
if c.gotoCore != nil {
return c.gotoCore.ListObjectMetadata(ctx, objectNames)
Comment thread
immdipu marked this conversation as resolved.
}

return nil, common.ErrNotImplemented
}
50 changes: 50 additions & 0 deletions providers/goto/internal/gotocore/adapter.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
// Package gotocore handles GoTo's core API functionality.
// This includes endpoints for managing webinars and other products.
// The package name "gotocore" is internal shorthand —
// it does not imply core-only access.
package gotocore

import (
"github.com/amp-labs/connectors/common"
"github.com/amp-labs/connectors/internal/components"
"github.com/amp-labs/connectors/internal/components/operations"
"github.com/amp-labs/connectors/internal/components/schema"
"github.com/amp-labs/connectors/providers"
)

type Adapter struct {
*components.Connector
components.SchemaProvider

accountKey string
}

func NewAdapter(params common.ConnectorParams, accountKey string) (*Adapter, error) {
adapter, err := components.Initialize(providers.GoTo, params, constructor)
if err != nil {
return nil, err
}

adapter.accountKey = accountKey

return adapter, nil
}

func (a *Adapter) SetAccountKey(accountKey string) {
a.accountKey = accountKey
}

func constructor(base *components.Connector) (*Adapter, error) {
adapter := &Adapter{Connector: base}

adapter.SchemaProvider = schema.NewObjectSchemaProvider(
adapter.HTTPClient().Client,
schema.FetchModeParallel,
operations.SingleObjectMetadataHandlers{
BuildRequest: adapter.buildSingleObjectMetadataRequest,
ParseResponse: adapter.parseSingleObjectMetadataResponse,
},
)

return adapter, nil
}
Loading
Loading