Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
201 changes: 201 additions & 0 deletions gql/generated.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

24 changes: 24 additions & 0 deletions gql/genqclient.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -265,6 +265,30 @@ query ListAddOns($addOnType: AddOnType) {
}
}

query ListOrganizationAddOns($orgSlug: String!, $addOnType: AddOnType) {
organization(slug: $orgSlug) {
addOns(type: $addOnType) {
nodes {
id
name
addOnPlan {
displayName
description
}
privateIp
primaryRegion
readRegions
options
metadata
organization {
id
slug
}
}
}
}
}

mutation UpdateAddOn($addOnId: ID!, $planId: ID!, $readRegions: [String!]!, $options: JSON!, $metadata: JSON!) {
updateAddOn(input: {addOnId: $addOnId, planId: $planId, readRegions: $readRegions, options: $options, metadata: $metadata}) {
addOn {
Expand Down
20 changes: 14 additions & 6 deletions internal/command/deploy/statics/addon.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,28 +19,36 @@ import (
"github.com/superfly/tokenizer"
)

// Bucket is a tigris statics add-on as returned by FindBucket. It is an alias
// for the generated type of the ListOrganizationAddOns query's node fields so
// callers don't have to deal with the unwieldy generated name directly.
type Bucket = gql.ListOrganizationAddOnsOrganizationAddOnsAddOnConnectionNodesAddOn

// FindBucket finds the tigris statics bucket for the given app and org.
// Returns nil, nil if no bucket is found.
func FindBucket(ctx context.Context, app *fly.App, org *fly.Organization) (*gql.ListAddOnsAddOnsAddOnConnectionNodesAddOn, error) {
//
// The query is scoped to the app's organization so accounts with many tigris
// add-ons don't have to transfer (and filter client-side) every tigris add-on
// visible to the caller. Once new statics buckets are created with an app_id
// link (see ensureBucketCreated), this can be tightened further to an
// app-scoped query; until then we still match by the metadata pointer.
func FindBucket(ctx context.Context, app *fly.App, org *fly.Organization) (*Bucket, error) {

client := flyutil.ClientFromContext(ctx)
gqlClient := client.GenqClient()

response, err := gql.ListAddOns(ctx, gqlClient, "tigris")
response, err := gql.ListOrganizationAddOns(ctx, gqlClient, org.Slug, "tigris")
if err != nil {
return nil, err
}

// Using string comparison here because we might want to use BigInt app IDs in the future.
internalAppIdStr := strconv.FormatUint(uint64(app.InternalNumericID), 10)

for _, extension := range response.AddOns.Nodes {
for _, extension := range response.Organization.AddOns.Nodes {
if extension.Metadata == nil {
continue
}
if extension.Organization.Slug != org.Slug {
continue
}
if extension.Metadata.(map[string]any)[staticsMetaKeyAppId] == internalAppIdStr {
return &extension, nil
}
Expand Down
2 changes: 1 addition & 1 deletion internal/command/deploy/statics/move.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ import (
// all the files from the old bucket to the new bucket - then deletes the old bucket.
func MoveBucket(
ctx context.Context,
prevBucket *gql.ListAddOnsAddOnsAddOnConnectionNodesAddOn,
prevBucket *Bucket,
prevOrg *fly.Organization,
app *fly.App,
targetOrg *fly.Organization,
Expand Down