whatever
This commit is contained in:
parent
4515d3a4b2
commit
ebf377d5e3
@ -43,3 +43,11 @@ func OrNow(t *time.Time) time.Time {
|
|||||||
|
|
||||||
return *t
|
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
|
||||||
|
}
|
||||||
|
|||||||
@ -10,6 +10,7 @@ import (
|
|||||||
"github.com/microsoftgraph/msgraph-sdk-go/users"
|
"github.com/microsoftgraph/msgraph-sdk-go/users"
|
||||||
"github.com/pkg/errors"
|
"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/internal/connector/graph"
|
||||||
"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"
|
||||||
@ -68,9 +69,6 @@ const (
|
|||||||
//nolint:lll
|
//nolint:lll
|
||||||
var userFilterNoGuests = "onPremisesSyncEnabled eq true OR userType ne 'Guest'"
|
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 {
|
func userOptions(fs *string) *users.UsersRequestBuilderGetRequestConfiguration {
|
||||||
headers := absser.NewRequestHeaders()
|
headers := absser.NewRequestHeaders()
|
||||||
headers.Add("ConsistencyLevel", "eventual")
|
headers.Add("ConsistencyLevel", "eventual")
|
||||||
@ -80,7 +78,7 @@ func userOptions(fs *string) *users.UsersRequestBuilderGetRequestConfiguration {
|
|||||||
QueryParameters: &users.UsersRequestBuilderGetQueryParameters{
|
QueryParameters: &users.UsersRequestBuilderGetQueryParameters{
|
||||||
Select: []string{userSelectID, userSelectPrincipalName, userSelectDisplayName},
|
Select: []string{userSelectID, userSelectPrincipalName, userSelectDisplayName},
|
||||||
Filter: fs,
|
Filter: fs,
|
||||||
Count: &t,
|
Count: ptr.To(true),
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -1,6 +1,7 @@
|
|||||||
package graph
|
package graph
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"fmt"
|
||||||
"net/http"
|
"net/http"
|
||||||
"net/http/httputil"
|
"net/http/httputil"
|
||||||
"os"
|
"os"
|
||||||
@ -274,6 +275,8 @@ func (handler *LoggingMiddleware) Intercept(
|
|||||||
return resp, err
|
return resp, err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fmt.Printf("\n-----\nURL %v\nSTATUS %v\n-----\n", req.URL, resp.StatusCode)
|
||||||
|
|
||||||
// Return immediately if the response is good (2xx).
|
// Return immediately if the response is good (2xx).
|
||||||
// If api logging is toggled, log a body-less dump of the request/resp.
|
// If api logging is toggled, log a body-less dump of the request/resp.
|
||||||
if (resp.StatusCode / 100) == 2 {
|
if (resp.StatusCode / 100) == 2 {
|
||||||
@ -302,6 +305,8 @@ func (handler *LoggingMiddleware) Intercept(
|
|||||||
if logger.DebugAPI || os.Getenv(logGraphRequestsEnvKey) != "" {
|
if logger.DebugAPI || os.Getenv(logGraphRequestsEnvKey) != "" {
|
||||||
respDump, _ := httputil.DumpResponse(resp, true)
|
respDump, _ := httputil.DumpResponse(resp, true)
|
||||||
|
|
||||||
|
fmt.Printf("\n-----\nBODY %v\n-----\n", string(respDump))
|
||||||
|
|
||||||
metadata := []any{
|
metadata := []any{
|
||||||
"method", req.Method,
|
"method", req.Method,
|
||||||
"status", resp.Status,
|
"status", resp.Status,
|
||||||
@ -323,6 +328,8 @@ func (handler *LoggingMiddleware) Intercept(
|
|||||||
"reset", resp.Header.Get(rateResetHeader))
|
"reset", resp.Header.Get(rateResetHeader))
|
||||||
} else if resp.StatusCode == http.StatusBadRequest {
|
} else if resp.StatusCode == http.StatusBadRequest {
|
||||||
respDump, _ := httputil.DumpResponse(resp, true)
|
respDump, _ := httputil.DumpResponse(resp, true)
|
||||||
|
|
||||||
|
fmt.Printf("\n-----\nBODY %v\n-----\n", string(respDump))
|
||||||
logger.Ctx(ctx).Infow(
|
logger.Ctx(ctx).Infow(
|
||||||
"graph api error",
|
"graph api error",
|
||||||
"status", resp.Status,
|
"status", resp.Status,
|
||||||
|
|||||||
@ -105,8 +105,7 @@ func (gc *GraphConnector) createService() (*graph.Service, error) {
|
|||||||
adapter, err := graph.CreateAdapter(
|
adapter, err := graph.CreateAdapter(
|
||||||
gc.credentials.AzureTenantID,
|
gc.credentials.AzureTenantID,
|
||||||
gc.credentials.AzureClientID,
|
gc.credentials.AzureClientID,
|
||||||
gc.credentials.AzureClientSecret,
|
gc.credentials.AzureClientSecret)
|
||||||
)
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return &graph.Service{}, err
|
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)
|
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.
|
// personal (ie: oneDrive) sites have to be filtered out server-side.
|
||||||
if ok && strings.Contains(url, personalSitePath) {
|
if ok && strings.Contains(url, personalSitePath) {
|
||||||
return "", "", clues.Stack(errKnownSkippableCase).With("site_id", id)
|
return "", "", clues.Stack(errKnownSkippableCase).With("site_id", id)
|
||||||
@ -318,5 +319,5 @@ func getResources(
|
|||||||
return nil, graph.Stack(ctx, err)
|
return nil, graph.Stack(ctx, err)
|
||||||
}
|
}
|
||||||
|
|
||||||
return resources, el.Failure()
|
return resources, clues.New("fake") // el.Failure()
|
||||||
}
|
}
|
||||||
|
|||||||
@ -3,26 +3,36 @@ package sharepoint
|
|||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
|
|
||||||
absser "github.com/microsoft/kiota-abstractions-go/serialization"
|
"github.com/microsoft/kiota-abstractions-go/serialization"
|
||||||
mssite "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/connector/graph"
|
"github.com/alcionai/corso/src/internal/connector/graph"
|
||||||
)
|
)
|
||||||
|
|
||||||
// GetAllSitesForTenant makes a GraphQuery request retrieving all sites in the tenant.
|
// GetAllSitesForTenant makes a GraphQuery request retrieving all sites in the tenant.
|
||||||
// Due to restrictions in filter capabilities for site queries, the returned iterable
|
// Due to restrictions in filter capabilities for site queries, the returned iterable
|
||||||
// will contain all personal sites for all users in the org.
|
// will contain all personal sites for all users in the org.
|
||||||
func GetAllSitesForTenant(ctx context.Context, gs graph.Servicer) (absser.Parsable, error) {
|
func GetAllSitesForTenant(ctx context.Context, gs graph.Servicer) (serialization.Parsable, error) {
|
||||||
options := &mssite.SitesRequestBuilderGetRequestConfiguration{
|
// url := "https://graph.microsoft.com/beta/sites" +
|
||||||
QueryParameters: &mssite.SitesRequestBuilderGetQueryParameters{
|
// "?$top=1000" +
|
||||||
Select: []string{"id", "name", "weburl"},
|
// "&$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 {
|
if err != nil {
|
||||||
return nil, graph.Wrap(ctx, err, "getting sites")
|
return nil, graph.Wrap(ctx, err, "getting sites")
|
||||||
}
|
}
|
||||||
|
|
||||||
return sites, nil
|
return s, nil
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user