Skip to content

Commit 34c7a88

Browse files
committed
migrate to new helper file so task generate does not keep wiping off
1 parent 7060f28 commit 34c7a88

2 files changed

Lines changed: 44 additions & 39 deletions

File tree

internal/graphapi/internalpolicyextended.resolvers.go

Lines changed: 0 additions & 39 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
package graphapi
2+
3+
import (
4+
"context"
5+
6+
"github.com/theopenlane/core/common/enums"
7+
"github.com/theopenlane/core/internal/ent/generated"
8+
"github.com/theopenlane/core/internal/ent/generated/integration"
9+
"github.com/theopenlane/core/internal/integrations/definitions/googledrive"
10+
"github.com/theopenlane/core/pkg/jsonx"
11+
"github.com/theopenlane/core/pkg/logx"
12+
)
13+
14+
// findPrimaryDriveIntegration finds the Drive integration marked as primary for the given org
15+
func (r *internalPolicyResolver) findPrimaryDriveIntegration(ctx context.Context, ownerID string) (*generated.Integration, error) {
16+
integrations, err := withTransactionalMutation(ctx).Integration.Query().
17+
Where(
18+
integration.OwnerID(ownerID),
19+
integration.DefinitionID(googledrive.DefinitionID()),
20+
integration.StatusEQ(enums.IntegrationStatusConnected),
21+
).
22+
All(ctx)
23+
if err != nil {
24+
logx.FromContext(ctx).Error().Err(err).Msg("failed to query drive integrations")
25+
return nil, err
26+
}
27+
28+
for _, integ := range integrations {
29+
var input googledrive.UserInput
30+
if err := jsonx.UnmarshalIfPresent(integ.Config.ClientConfig, &input); err != nil {
31+
continue
32+
}
33+
34+
if input.Primary {
35+
return integ, nil
36+
}
37+
}
38+
39+
if len(integrations) > 0 {
40+
return integrations[0], nil
41+
}
42+
43+
return nil, nil
44+
}

0 commit comments

Comments
 (0)