[Feature] Move connector api module from internal -> pkg (#3166)
<!-- PR description--> This PR moves the `api` module from `src/internal/connector/discovery` to `src/pkg/services/m365/api` so that the Client can be reused. #### Does this PR need a docs update or release note? - [ ] ✅ Yes, it's included - [ ] 🕐 Yes, but in a later PR - [x] ⛔ No #### Type of change <!--- Please check the type of change your PR introduces: ---> - [x] 🌻 Feature - [ ] 🐛 Bugfix - [ ] 🗺️ Documentation - [ ] 🤖 Supportability/Tests - [ ] 💻 CI/Deployment - [ ] 🧹 Tech Debt/Cleanup #### Issue(s) <!-- Can reference multiple issues. Use one of the following "magic words" - "closes, fixes" to auto-close the Github issue. --> * #ALC-2214 #### Test Plan <!-- How will this be tested prior to merging.--> - [ ] 💪 Manual - [x] ⚡ Unit test - [ ] 💚 E2E --------- Co-authored-by: aviator-app[bot] <48659329+aviator-app[bot]@users.noreply.github.com>
This commit is contained in:
parent
a4ff93bd47
commit
5166e61115
@ -6,10 +6,10 @@ import (
|
|||||||
"github.com/alcionai/clues"
|
"github.com/alcionai/clues"
|
||||||
"github.com/microsoftgraph/msgraph-sdk-go/models"
|
"github.com/microsoftgraph/msgraph-sdk-go/models"
|
||||||
|
|
||||||
"github.com/alcionai/corso/src/internal/connector/discovery/api"
|
|
||||||
"github.com/alcionai/corso/src/internal/connector/graph"
|
"github.com/alcionai/corso/src/internal/connector/graph"
|
||||||
"github.com/alcionai/corso/src/pkg/account"
|
"github.com/alcionai/corso/src/pkg/account"
|
||||||
"github.com/alcionai/corso/src/pkg/fault"
|
"github.com/alcionai/corso/src/pkg/fault"
|
||||||
|
"github.com/alcionai/corso/src/pkg/services/m365/api"
|
||||||
)
|
)
|
||||||
|
|
||||||
// ---------------------------------------------------------------------------
|
// ---------------------------------------------------------------------------
|
||||||
|
|||||||
@ -10,12 +10,12 @@ import (
|
|||||||
"github.com/stretchr/testify/suite"
|
"github.com/stretchr/testify/suite"
|
||||||
|
|
||||||
"github.com/alcionai/corso/src/internal/connector/discovery"
|
"github.com/alcionai/corso/src/internal/connector/discovery"
|
||||||
"github.com/alcionai/corso/src/internal/connector/discovery/api"
|
|
||||||
"github.com/alcionai/corso/src/internal/tester"
|
"github.com/alcionai/corso/src/internal/tester"
|
||||||
"github.com/alcionai/corso/src/pkg/account"
|
"github.com/alcionai/corso/src/pkg/account"
|
||||||
"github.com/alcionai/corso/src/pkg/credentials"
|
"github.com/alcionai/corso/src/pkg/credentials"
|
||||||
"github.com/alcionai/corso/src/pkg/fault"
|
"github.com/alcionai/corso/src/pkg/fault"
|
||||||
"github.com/alcionai/corso/src/pkg/path"
|
"github.com/alcionai/corso/src/pkg/path"
|
||||||
|
"github.com/alcionai/corso/src/pkg/services/m365/api"
|
||||||
)
|
)
|
||||||
|
|
||||||
type DiscoveryIntegrationSuite struct {
|
type DiscoveryIntegrationSuite struct {
|
||||||
|
|||||||
@ -11,13 +11,13 @@ import (
|
|||||||
"github.com/alcionai/clues"
|
"github.com/alcionai/clues"
|
||||||
|
|
||||||
"github.com/alcionai/corso/src/internal/common"
|
"github.com/alcionai/corso/src/internal/common"
|
||||||
"github.com/alcionai/corso/src/internal/connector/discovery/api"
|
|
||||||
"github.com/alcionai/corso/src/internal/connector/graph"
|
"github.com/alcionai/corso/src/internal/connector/graph"
|
||||||
"github.com/alcionai/corso/src/internal/connector/support"
|
"github.com/alcionai/corso/src/internal/connector/support"
|
||||||
"github.com/alcionai/corso/src/internal/data"
|
"github.com/alcionai/corso/src/internal/data"
|
||||||
"github.com/alcionai/corso/src/internal/operations/inject"
|
"github.com/alcionai/corso/src/internal/operations/inject"
|
||||||
"github.com/alcionai/corso/src/pkg/account"
|
"github.com/alcionai/corso/src/pkg/account"
|
||||||
"github.com/alcionai/corso/src/pkg/fault"
|
"github.com/alcionai/corso/src/pkg/fault"
|
||||||
|
"github.com/alcionai/corso/src/pkg/services/m365/api"
|
||||||
)
|
)
|
||||||
|
|
||||||
// ---------------------------------------------------------------------------
|
// ---------------------------------------------------------------------------
|
||||||
|
|||||||
@ -6,17 +6,17 @@ import (
|
|||||||
"github.com/alcionai/clues"
|
"github.com/alcionai/clues"
|
||||||
"github.com/stretchr/testify/require"
|
"github.com/stretchr/testify/require"
|
||||||
|
|
||||||
discover "github.com/alcionai/corso/src/internal/connector/discovery/api"
|
|
||||||
"github.com/alcionai/corso/src/internal/connector/graph"
|
"github.com/alcionai/corso/src/internal/connector/graph"
|
||||||
"github.com/alcionai/corso/src/pkg/account"
|
"github.com/alcionai/corso/src/pkg/account"
|
||||||
|
"github.com/alcionai/corso/src/pkg/services/m365/api"
|
||||||
)
|
)
|
||||||
|
|
||||||
func createTestBetaService(t *testing.T, credentials account.M365Config) *discover.BetaService {
|
func createTestBetaService(t *testing.T, credentials account.M365Config) *api.BetaService {
|
||||||
adapter, err := graph.CreateAdapter(
|
adapter, err := graph.CreateAdapter(
|
||||||
credentials.AzureTenantID,
|
credentials.AzureTenantID,
|
||||||
credentials.AzureClientID,
|
credentials.AzureClientID,
|
||||||
credentials.AzureClientSecret)
|
credentials.AzureClientSecret)
|
||||||
require.NoError(t, err, clues.ToCore(err))
|
require.NoError(t, err, clues.ToCore(err))
|
||||||
|
|
||||||
return discover.NewBetaService(adapter)
|
return api.NewBetaService(adapter)
|
||||||
}
|
}
|
||||||
|
|||||||
@ -11,7 +11,6 @@ import (
|
|||||||
"github.com/microsoftgraph/msgraph-sdk-go/sites"
|
"github.com/microsoftgraph/msgraph-sdk-go/sites"
|
||||||
|
|
||||||
"github.com/alcionai/corso/src/internal/common/ptr"
|
"github.com/alcionai/corso/src/internal/common/ptr"
|
||||||
dapi "github.com/alcionai/corso/src/internal/connector/discovery/api"
|
|
||||||
"github.com/alcionai/corso/src/internal/connector/graph"
|
"github.com/alcionai/corso/src/internal/connector/graph"
|
||||||
betamodels "github.com/alcionai/corso/src/internal/connector/graph/betasdk/models"
|
betamodels "github.com/alcionai/corso/src/internal/connector/graph/betasdk/models"
|
||||||
betasites "github.com/alcionai/corso/src/internal/connector/graph/betasdk/sites"
|
betasites "github.com/alcionai/corso/src/internal/connector/graph/betasdk/sites"
|
||||||
@ -20,13 +19,14 @@ import (
|
|||||||
"github.com/alcionai/corso/src/internal/diagnostics"
|
"github.com/alcionai/corso/src/internal/diagnostics"
|
||||||
"github.com/alcionai/corso/src/pkg/backup/details"
|
"github.com/alcionai/corso/src/pkg/backup/details"
|
||||||
"github.com/alcionai/corso/src/pkg/fault"
|
"github.com/alcionai/corso/src/pkg/fault"
|
||||||
|
"github.com/alcionai/corso/src/pkg/services/m365/api"
|
||||||
)
|
)
|
||||||
|
|
||||||
// GetSitePages retrieves a collection of Pages related to the give Site.
|
// GetSitePages retrieves a collection of Pages related to the give Site.
|
||||||
// Returns error if error experienced during the call
|
// Returns error if error experienced during the call
|
||||||
func GetSitePages(
|
func GetSitePages(
|
||||||
ctx context.Context,
|
ctx context.Context,
|
||||||
serv *dapi.BetaService,
|
serv *api.BetaService,
|
||||||
siteID string,
|
siteID string,
|
||||||
pages []string,
|
pages []string,
|
||||||
errs *fault.Bus,
|
errs *fault.Bus,
|
||||||
@ -100,7 +100,7 @@ func GetSite(ctx context.Context, gs graph.Servicer, siteID string) (models.Site
|
|||||||
}
|
}
|
||||||
|
|
||||||
// fetchPages utility function to return the tuple of item
|
// fetchPages utility function to return the tuple of item
|
||||||
func FetchPages(ctx context.Context, bs *dapi.BetaService, siteID string) ([]NameID, error) {
|
func FetchPages(ctx context.Context, bs *api.BetaService, siteID string) ([]NameID, error) {
|
||||||
var (
|
var (
|
||||||
builder = bs.Client().SitesById(siteID).Pages()
|
builder = bs.Client().SitesById(siteID).Pages()
|
||||||
opts = fetchPageOptions()
|
opts = fetchPageOptions()
|
||||||
@ -159,7 +159,7 @@ func fetchPageOptions() *betasites.ItemPagesRequestBuilderGetRequestConfiguratio
|
|||||||
// https://github.com/alcionai/corso/issues/2707
|
// https://github.com/alcionai/corso/issues/2707
|
||||||
func DeleteSitePage(
|
func DeleteSitePage(
|
||||||
ctx context.Context,
|
ctx context.Context,
|
||||||
serv *dapi.BetaService,
|
serv *api.BetaService,
|
||||||
siteID, pageID string,
|
siteID, pageID string,
|
||||||
) error {
|
) error {
|
||||||
err := serv.Client().SitesById(siteID).PagesById(pageID).Delete(ctx, nil)
|
err := serv.Client().SitesById(siteID).PagesById(pageID).Delete(ctx, nil)
|
||||||
@ -184,7 +184,7 @@ func retrieveSitePageOptions() *betasites.ItemPagesSitePageItemRequestBuilderGet
|
|||||||
|
|
||||||
func RestoreSitePage(
|
func RestoreSitePage(
|
||||||
ctx context.Context,
|
ctx context.Context,
|
||||||
service *dapi.BetaService,
|
service *api.BetaService,
|
||||||
itemData data.Stream,
|
itemData data.Stream,
|
||||||
siteID, destName string,
|
siteID, destName string,
|
||||||
) (details.ItemInfo, error) {
|
) (details.ItemInfo, error) {
|
||||||
|
|||||||
@ -11,20 +11,20 @@ import (
|
|||||||
"github.com/stretchr/testify/suite"
|
"github.com/stretchr/testify/suite"
|
||||||
|
|
||||||
"github.com/alcionai/corso/src/internal/common"
|
"github.com/alcionai/corso/src/internal/common"
|
||||||
discover "github.com/alcionai/corso/src/internal/connector/discovery/api"
|
|
||||||
"github.com/alcionai/corso/src/internal/connector/sharepoint"
|
"github.com/alcionai/corso/src/internal/connector/sharepoint"
|
||||||
"github.com/alcionai/corso/src/internal/connector/sharepoint/api"
|
"github.com/alcionai/corso/src/internal/connector/sharepoint/api"
|
||||||
spMock "github.com/alcionai/corso/src/internal/connector/sharepoint/mock"
|
spMock "github.com/alcionai/corso/src/internal/connector/sharepoint/mock"
|
||||||
"github.com/alcionai/corso/src/internal/tester"
|
"github.com/alcionai/corso/src/internal/tester"
|
||||||
"github.com/alcionai/corso/src/pkg/account"
|
"github.com/alcionai/corso/src/pkg/account"
|
||||||
"github.com/alcionai/corso/src/pkg/fault"
|
"github.com/alcionai/corso/src/pkg/fault"
|
||||||
|
m365api "github.com/alcionai/corso/src/pkg/services/m365/api"
|
||||||
)
|
)
|
||||||
|
|
||||||
type SharePointPageSuite struct {
|
type SharePointPageSuite struct {
|
||||||
tester.Suite
|
tester.Suite
|
||||||
siteID string
|
siteID string
|
||||||
creds account.M365Config
|
creds account.M365Config
|
||||||
service *discover.BetaService
|
service *m365api.BetaService
|
||||||
}
|
}
|
||||||
|
|
||||||
func (suite *SharePointPageSuite) SetupSuite() {
|
func (suite *SharePointPageSuite) SetupSuite() {
|
||||||
|
|||||||
@ -11,7 +11,6 @@ import (
|
|||||||
kjson "github.com/microsoft/kiota-serialization-json-go"
|
kjson "github.com/microsoft/kiota-serialization-json-go"
|
||||||
|
|
||||||
"github.com/alcionai/corso/src/internal/common/ptr"
|
"github.com/alcionai/corso/src/internal/common/ptr"
|
||||||
dapi "github.com/alcionai/corso/src/internal/connector/discovery/api"
|
|
||||||
"github.com/alcionai/corso/src/internal/connector/graph"
|
"github.com/alcionai/corso/src/internal/connector/graph"
|
||||||
"github.com/alcionai/corso/src/internal/connector/sharepoint/api"
|
"github.com/alcionai/corso/src/internal/connector/sharepoint/api"
|
||||||
"github.com/alcionai/corso/src/internal/connector/support"
|
"github.com/alcionai/corso/src/internal/connector/support"
|
||||||
@ -22,6 +21,7 @@ import (
|
|||||||
"github.com/alcionai/corso/src/pkg/fault"
|
"github.com/alcionai/corso/src/pkg/fault"
|
||||||
"github.com/alcionai/corso/src/pkg/logger"
|
"github.com/alcionai/corso/src/pkg/logger"
|
||||||
"github.com/alcionai/corso/src/pkg/path"
|
"github.com/alcionai/corso/src/pkg/path"
|
||||||
|
m365api "github.com/alcionai/corso/src/pkg/services/m365/api"
|
||||||
)
|
)
|
||||||
|
|
||||||
type DataCategory int
|
type DataCategory int
|
||||||
@ -56,7 +56,7 @@ type Collection struct {
|
|||||||
category DataCategory
|
category DataCategory
|
||||||
service graph.Servicer
|
service graph.Servicer
|
||||||
ctrl control.Options
|
ctrl control.Options
|
||||||
betaService *dapi.BetaService
|
betaService *m365api.BetaService
|
||||||
statusUpdater support.StatusUpdater
|
statusUpdater support.StatusUpdater
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -6,7 +6,6 @@ import (
|
|||||||
|
|
||||||
"github.com/alcionai/clues"
|
"github.com/alcionai/clues"
|
||||||
|
|
||||||
dapi "github.com/alcionai/corso/src/internal/connector/discovery/api"
|
|
||||||
"github.com/alcionai/corso/src/internal/connector/graph"
|
"github.com/alcionai/corso/src/internal/connector/graph"
|
||||||
"github.com/alcionai/corso/src/internal/connector/onedrive"
|
"github.com/alcionai/corso/src/internal/connector/onedrive"
|
||||||
"github.com/alcionai/corso/src/internal/connector/sharepoint/api"
|
"github.com/alcionai/corso/src/internal/connector/sharepoint/api"
|
||||||
@ -19,6 +18,7 @@ import (
|
|||||||
"github.com/alcionai/corso/src/pkg/logger"
|
"github.com/alcionai/corso/src/pkg/logger"
|
||||||
"github.com/alcionai/corso/src/pkg/path"
|
"github.com/alcionai/corso/src/pkg/path"
|
||||||
"github.com/alcionai/corso/src/pkg/selectors"
|
"github.com/alcionai/corso/src/pkg/selectors"
|
||||||
|
m365api "github.com/alcionai/corso/src/pkg/services/m365/api"
|
||||||
)
|
)
|
||||||
|
|
||||||
type statusUpdater interface {
|
type statusUpdater interface {
|
||||||
@ -243,7 +243,7 @@ func collectPages(
|
|||||||
return nil, clues.Wrap(err, "creating azure client adapter")
|
return nil, clues.Wrap(err, "creating azure client adapter")
|
||||||
}
|
}
|
||||||
|
|
||||||
betaService := dapi.NewBetaService(adpt)
|
betaService := m365api.NewBetaService(adpt)
|
||||||
|
|
||||||
tuples, err := api.FetchPages(ctx, betaService, siteID)
|
tuples, err := api.FetchPages(ctx, betaService, siteID)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|||||||
@ -10,7 +10,6 @@ import (
|
|||||||
"github.com/microsoftgraph/msgraph-sdk-go/models"
|
"github.com/microsoftgraph/msgraph-sdk-go/models"
|
||||||
|
|
||||||
"github.com/alcionai/corso/src/internal/common/ptr"
|
"github.com/alcionai/corso/src/internal/common/ptr"
|
||||||
dapi "github.com/alcionai/corso/src/internal/connector/discovery/api"
|
|
||||||
"github.com/alcionai/corso/src/internal/connector/graph"
|
"github.com/alcionai/corso/src/internal/connector/graph"
|
||||||
"github.com/alcionai/corso/src/internal/connector/onedrive"
|
"github.com/alcionai/corso/src/internal/connector/onedrive"
|
||||||
"github.com/alcionai/corso/src/internal/connector/sharepoint/api"
|
"github.com/alcionai/corso/src/internal/connector/sharepoint/api"
|
||||||
@ -23,6 +22,7 @@ import (
|
|||||||
"github.com/alcionai/corso/src/pkg/fault"
|
"github.com/alcionai/corso/src/pkg/fault"
|
||||||
"github.com/alcionai/corso/src/pkg/logger"
|
"github.com/alcionai/corso/src/pkg/logger"
|
||||||
"github.com/alcionai/corso/src/pkg/path"
|
"github.com/alcionai/corso/src/pkg/path"
|
||||||
|
m365api "github.com/alcionai/corso/src/pkg/services/m365/api"
|
||||||
)
|
)
|
||||||
|
|
||||||
//----------------------------------------------------------------------------
|
//----------------------------------------------------------------------------
|
||||||
@ -315,7 +315,7 @@ func RestorePageCollection(
|
|||||||
|
|
||||||
var (
|
var (
|
||||||
el = errs.Local()
|
el = errs.Local()
|
||||||
service = dapi.NewBetaService(adpt)
|
service = m365api.NewBetaService(adpt)
|
||||||
items = dc.Items(ctx, errs)
|
items = dc.Items(ctx, errs)
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|||||||
@ -11,12 +11,11 @@ import (
|
|||||||
// interfaces
|
// interfaces
|
||||||
// ---------------------------------------------------------------------------
|
// ---------------------------------------------------------------------------
|
||||||
|
|
||||||
// Client is used to fulfill the interface for discovery
|
// Client is used to fulfill queries that are traditionally
|
||||||
// queries that are traditionally backed by GraphAPI. A
|
// backed by GraphAPI. A struct is used in this case, instead
|
||||||
// struct is used in this case, instead of deferring to
|
// of deferring to pure function wrappers, so that the boundary
|
||||||
// pure function wrappers, so that the boundary separates the
|
// separates the granular implementation of the graphAPI and
|
||||||
// granular implementation of the graphAPI and kiota away
|
// kiota away from the other packages.
|
||||||
// from the exchange package's broader intents.
|
|
||||||
type Client struct {
|
type Client struct {
|
||||||
Credentials account.M365Config
|
Credentials account.M365Config
|
||||||
|
|
||||||
@ -25,7 +24,7 @@ type Client struct {
|
|||||||
stable graph.Servicer
|
stable graph.Servicer
|
||||||
}
|
}
|
||||||
|
|
||||||
// NewClient produces a new exchange api client. Must be used in
|
// NewClient produces a new api client. Must be used in
|
||||||
// place of creating an ad-hoc client struct.
|
// place of creating an ad-hoc client struct.
|
||||||
func NewClient(creds account.M365Config) (Client, error) {
|
func NewClient(creds account.M365Config) (Client, error) {
|
||||||
s, err := newService(creds)
|
s, err := newService(creds)
|
||||||
@ -39,7 +38,7 @@ func NewClient(creds account.M365Config) (Client, error) {
|
|||||||
// service generates a new service. Used for paged and other long-running
|
// service generates a new service. Used for paged and other long-running
|
||||||
// requests instead of the client's stable service, so that in-flight state
|
// requests instead of the client's stable service, so that in-flight state
|
||||||
// within the adapter doesn't get clobbered
|
// within the adapter doesn't get clobbered
|
||||||
func (c Client) service() (*graph.Service, error) {
|
func (c Client) Service() (*graph.Service, error) {
|
||||||
return newService(c.Credentials)
|
return newService(c.Credentials)
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -37,7 +37,7 @@ type Sites struct {
|
|||||||
|
|
||||||
// GetAll retrieves all sites.
|
// GetAll retrieves all sites.
|
||||||
func (c Sites) GetAll(ctx context.Context, errs *fault.Bus) ([]models.Siteable, error) {
|
func (c Sites) GetAll(ctx context.Context, errs *fault.Bus) ([]models.Siteable, error) {
|
||||||
service, err := c.service()
|
service, err := c.Service()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
@ -100,7 +100,7 @@ func userOptions(fs *string) *users.UsersRequestBuilderGetRequestConfiguration {
|
|||||||
|
|
||||||
// GetAll retrieves all users.
|
// GetAll retrieves all users.
|
||||||
func (c Users) GetAll(ctx context.Context, errs *fault.Bus) ([]models.Userable, error) {
|
func (c Users) GetAll(ctx context.Context, errs *fault.Bus) ([]models.Userable, error) {
|
||||||
service, err := c.service()
|
service, err := c.Service()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
@ -10,10 +10,10 @@ import (
|
|||||||
"github.com/alcionai/corso/src/internal/common"
|
"github.com/alcionai/corso/src/internal/common"
|
||||||
"github.com/alcionai/corso/src/internal/common/ptr"
|
"github.com/alcionai/corso/src/internal/common/ptr"
|
||||||
"github.com/alcionai/corso/src/internal/connector/discovery"
|
"github.com/alcionai/corso/src/internal/connector/discovery"
|
||||||
"github.com/alcionai/corso/src/internal/connector/discovery/api"
|
|
||||||
"github.com/alcionai/corso/src/pkg/account"
|
"github.com/alcionai/corso/src/pkg/account"
|
||||||
"github.com/alcionai/corso/src/pkg/fault"
|
"github.com/alcionai/corso/src/pkg/fault"
|
||||||
"github.com/alcionai/corso/src/pkg/path"
|
"github.com/alcionai/corso/src/pkg/path"
|
||||||
|
"github.com/alcionai/corso/src/pkg/services/m365/api"
|
||||||
)
|
)
|
||||||
|
|
||||||
// ServiceAccess is true if a resource owner is capable of
|
// ServiceAccess is true if a resource owner is capable of
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user