Compare commits

...

1 Commits

Author SHA1 Message Date
ryanfkeepers
ebf377d5e3 whatever 2023-03-16 14:36:57 -06:00
5 changed files with 39 additions and 15 deletions

View File

@ -43,3 +43,11 @@ func OrNow(t *time.Time) time.Time {
return *t
}
// To returns a pointer to the provided value.
// Useful for getting pointers to ad-hoc primitives
// strings without needing to store them as
// individual variables.
func To[T any](t T) *T {
return &t
}

View File

@ -10,6 +10,7 @@ import (
"github.com/microsoftgraph/msgraph-sdk-go/users"
"github.com/pkg/errors"
"github.com/alcionai/corso/src/internal/common/ptr"
"github.com/alcionai/corso/src/internal/connector/graph"
"github.com/alcionai/corso/src/pkg/fault"
"github.com/alcionai/corso/src/pkg/path"
@ -68,9 +69,6 @@ const (
//nolint:lll
var userFilterNoGuests = "onPremisesSyncEnabled eq true OR userType ne 'Guest'"
// I can't believe I have to do this.
var t = true
func userOptions(fs *string) *users.UsersRequestBuilderGetRequestConfiguration {
headers := absser.NewRequestHeaders()
headers.Add("ConsistencyLevel", "eventual")
@ -80,7 +78,7 @@ func userOptions(fs *string) *users.UsersRequestBuilderGetRequestConfiguration {
QueryParameters: &users.UsersRequestBuilderGetQueryParameters{
Select: []string{userSelectID, userSelectPrincipalName, userSelectDisplayName},
Filter: fs,
Count: &t,
Count: ptr.To(true),
},
}
}

View File

@ -1,6 +1,7 @@
package graph
import (
"fmt"
"net/http"
"net/http/httputil"
"os"
@ -274,6 +275,8 @@ func (handler *LoggingMiddleware) Intercept(
return resp, err
}
fmt.Printf("\n-----\nURL %v\nSTATUS %v\n-----\n", req.URL, resp.StatusCode)
// Return immediately if the response is good (2xx).
// If api logging is toggled, log a body-less dump of the request/resp.
if (resp.StatusCode / 100) == 2 {
@ -302,6 +305,8 @@ func (handler *LoggingMiddleware) Intercept(
if logger.DebugAPI || os.Getenv(logGraphRequestsEnvKey) != "" {
respDump, _ := httputil.DumpResponse(resp, true)
fmt.Printf("\n-----\nBODY %v\n-----\n", string(respDump))
metadata := []any{
"method", req.Method,
"status", resp.Status,
@ -323,6 +328,8 @@ func (handler *LoggingMiddleware) Intercept(
"reset", resp.Header.Get(rateResetHeader))
} else if resp.StatusCode == http.StatusBadRequest {
respDump, _ := httputil.DumpResponse(resp, true)
fmt.Printf("\n-----\nBODY %v\n-----\n", string(respDump))
logger.Ctx(ctx).Infow(
"graph api error",
"status", resp.Status,

View File

@ -105,8 +105,7 @@ func (gc *GraphConnector) createService() (*graph.Service, error) {
adapter, err := graph.CreateAdapter(
gc.credentials.AzureTenantID,
gc.credentials.AzureClientID,
gc.credentials.AzureClientSecret,
)
gc.credentials.AzureClientSecret)
if err != nil {
return &graph.Service{}, err
}
@ -165,6 +164,8 @@ func identifySite(item any) (string, string, error) {
return "", "", clues.New("site has no name").With("site_id", id)
}
fmt.Printf("\n-----\nsite %v\n-----\n", url)
// personal (ie: oneDrive) sites have to be filtered out server-side.
if ok && strings.Contains(url, personalSitePath) {
return "", "", clues.Stack(errKnownSkippableCase).With("site_id", id)
@ -318,5 +319,5 @@ func getResources(
return nil, graph.Stack(ctx, err)
}
return resources, el.Failure()
return resources, clues.New("fake") // el.Failure()
}

View File

@ -3,26 +3,36 @@ package sharepoint
import (
"context"
absser "github.com/microsoft/kiota-abstractions-go/serialization"
mssite "github.com/microsoftgraph/msgraph-sdk-go/sites"
"github.com/microsoft/kiota-abstractions-go/serialization"
"github.com/microsoftgraph/msgraph-sdk-go/sites"
"github.com/alcionai/corso/src/internal/common/ptr"
"github.com/alcionai/corso/src/internal/connector/graph"
)
// GetAllSitesForTenant makes a GraphQuery request retrieving all sites in the tenant.
// Due to restrictions in filter capabilities for site queries, the returned iterable
// will contain all personal sites for all users in the org.
func GetAllSitesForTenant(ctx context.Context, gs graph.Servicer) (absser.Parsable, error) {
options := &mssite.SitesRequestBuilderGetRequestConfiguration{
QueryParameters: &mssite.SitesRequestBuilderGetQueryParameters{
Select: []string{"id", "name", "weburl"},
func GetAllSitesForTenant(ctx context.Context, gs graph.Servicer) (serialization.Parsable, error) {
// url := "https://graph.microsoft.com/beta/sites" +
// "?$top=1000" +
// "&$filter=displayname ne null AND NOT(contains(weburl, 'sharepoint.com/personal/'))"
// s, err := sites.NewItemSitesRequestBuilder(url, gs.Adapter()).Get(ctx, nil)
// if err != nil {
// return nil, graph.Wrap(ctx, err, "getting sites")
// }
options := &sites.SitesRequestBuilderGetRequestConfiguration{
QueryParameters: &sites.SitesRequestBuilderGetQueryParameters{
// Select: []string{"id", "name", "weburl"},
Filter: ptr.To("NOT(contains(webUrl,'sharepoint.com/personal/'))"),
},
}
sites, err := gs.Client().Sites().Get(ctx, options)
s, err := gs.Client().Sites().Get(ctx, options)
if err != nil {
return nil, graph.Wrap(ctx, err, "getting sites")
}
return sites, nil
return s, nil
}