-
Notifications
You must be signed in to change notification settings - Fork 218
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add a new command to provision a Sentry project for an app
- Loading branch information
Showing
9 changed files
with
133 additions
and
15 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
// Package logs implements the logs command chain. | ||
package extensions | ||
|
||
import ( | ||
"github.com/spf13/cobra" | ||
|
||
"github.com/superfly/flyctl/internal/command" | ||
) | ||
|
||
func New() (cmd *cobra.Command) { | ||
const ( | ||
long = `Extensions are additional functionality that can be added to your Fly apps` | ||
) | ||
|
||
cmd = command.New("extensions", long, long, nil) | ||
cmd.Aliases = []string{"extensions", "ext"} | ||
|
||
cmd.Args = cobra.NoArgs | ||
|
||
cmd.AddCommand(newSentry()) | ||
return | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,87 @@ | ||
package extensions | ||
|
||
import ( | ||
"context" | ||
"fmt" | ||
|
||
"github.com/spf13/cobra" | ||
"github.com/superfly/flyctl/client" | ||
"github.com/superfly/flyctl/gql" | ||
"github.com/superfly/flyctl/internal/appconfig" | ||
"github.com/superfly/flyctl/internal/command" | ||
"github.com/superfly/flyctl/internal/command/secrets" | ||
"github.com/superfly/flyctl/internal/flag" | ||
"github.com/superfly/flyctl/iostreams" | ||
) | ||
|
||
func newSentry() (cmd *cobra.Command) { | ||
|
||
const ( | ||
short = "Setup a Sentry project for this app" | ||
long = short + "\n" | ||
) | ||
|
||
cmd = command.New("sentry", short, long, runSentry, command.RequireSession, command.RequireAppName) | ||
flag.Add(cmd, | ||
flag.App(), | ||
flag.AppConfig(), | ||
) | ||
return cmd | ||
} | ||
|
||
func runSentry(ctx context.Context) (err error) { | ||
client := client.FromContext(ctx).API().GenqClient | ||
io := iostreams.FromContext(ctx) | ||
appName := appconfig.NameFromContext(ctx) | ||
|
||
if err != nil { | ||
return err | ||
} | ||
|
||
// Fetch the target organization from the app | ||
appResponse, err := gql.GetApp(ctx, client, appName) | ||
|
||
if err != nil { | ||
return err | ||
} | ||
|
||
targetApp := appResponse.App.AppData | ||
targetOrg := targetApp.Organization | ||
|
||
if err != nil { | ||
return err | ||
} | ||
|
||
// Fetch or create the Logtail integration for the app | ||
|
||
_, err = gql.GetAddOn(ctx, client, appName) | ||
|
||
if err != nil { | ||
|
||
input := gql.CreateAddOnInput{ | ||
OrganizationId: targetOrg.Id, | ||
Name: appName, | ||
AppId: targetApp.Id, | ||
Type: "sentry", | ||
} | ||
|
||
createAddOnResponse, err := gql.CreateAddOn(ctx, client, input) | ||
|
||
if err != nil { | ||
return err | ||
} | ||
|
||
dsn := createAddOnResponse.CreateAddOn.AddOn.Token | ||
|
||
fmt.Fprintln(io.Out, "A Sentry project was created. Now setting the SENTRY_DSN secret and deploying.") | ||
secrets.SetSecretsAndDeploy(ctx, gql.ToAppCompact(targetApp), map[string]string{ | ||
"SENTRY_DSN": dsn, | ||
}, false, false) | ||
|
||
return nil | ||
} else { | ||
fmt.Fprintln(io.Out, "A Sentry project already exists for this app") | ||
} | ||
|
||
return | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters