corso/src/internal/m365/export.go
ashmrtn 74cf0ab737
Create service specific handlers that know how to run an export (#4491)
First step in reducing the number of places we have to check the service type manually. Create a way to get a handle to a service specific handler and implement exports for those handlers

---

#### 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

- [ ] 🌻 Feature
- [ ] 🐛 Bugfix
- [ ] 🗺️ Documentation
- [ ] 🤖 Supportability/Tests
- [ ] 💻 CI/Deployment
- [x] 🧹 Tech Debt/Cleanup

#### Issue(s)

* #4254

#### Test Plan

- [ ] 💪 Manual
- [x]  Unit test
- [x] 💚 E2E
2023-11-01 15:55:30 +00:00

34 lines
981 B
Go

package m365
import (
"github.com/alcionai/clues"
"github.com/alcionai/corso/src/internal/m365/service/groups"
"github.com/alcionai/corso/src/internal/m365/service/onedrive"
"github.com/alcionai/corso/src/internal/m365/service/sharepoint"
"github.com/alcionai/corso/src/internal/operations/inject"
"github.com/alcionai/corso/src/pkg/control"
"github.com/alcionai/corso/src/pkg/path"
)
// NewServiceHandler returns an instance of a struct capable of running various
// operations for a given service.
func (ctrl *Controller) NewServiceHandler(
opts control.Options,
service path.ServiceType,
) (inject.ServiceHandler, error) {
switch service {
case path.OneDriveService:
return onedrive.NewOneDriveHandler(opts), nil
case path.SharePointService:
return sharepoint.NewSharePointHandler(opts), nil
case path.GroupsService:
return groups.NewGroupsHandler(opts), nil
}
return nil, clues.New("unrecognized service").
With("service_type", service.String())
}