-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: billingAddress to JSON, add subscriptionURL to orbSubscriptions…
… resolver (#371) * wip Signed-off-by: Sarah Funkhouser <[email protected]> * subcription url, billing fields Signed-off-by: Sarah Funkhouser <[email protected]> * missing migration, cleanup Signed-off-by: Sarah Funkhouser <[email protected]> * fix bug with org get cli Signed-off-by: Sarah Funkhouser <[email protected]> --------- Signed-off-by: Sarah Funkhouser <[email protected]>
- Loading branch information
1 parent
3bc27f9
commit fe5f729
Showing
75 changed files
with
897 additions
and
5,491 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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
// Package orgsubscription is our cobra cli for orgSubscription endpoints | ||
package orgsubscription |
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,52 @@ | ||
package orgsubscription | ||
|
||
import ( | ||
"context" | ||
|
||
"github.com/spf13/cobra" | ||
|
||
"github.com/theopenlane/core/cmd/cli/cmd" | ||
) | ||
|
||
var getCmd = &cobra.Command{ | ||
Use: "get", | ||
Short: "get an existing orgSubscription", | ||
Run: func(cmd *cobra.Command, args []string) { | ||
err := get(cmd.Context()) | ||
cobra.CheckErr(err) | ||
}, | ||
} | ||
|
||
func init() { | ||
command.AddCommand(getCmd) | ||
getCmd.Flags().StringP("id", "i", "", "orgSubscription id to query") | ||
|
||
} | ||
|
||
// get an existing orgSubscription in the platform | ||
func get(ctx context.Context) error { | ||
// attempt to setup with token, otherwise fall back to JWT with session | ||
client, err := cmd.TokenAuth(ctx, cmd.Config) | ||
if err != nil || client == nil { | ||
// setup http client | ||
client, err = cmd.SetupClientWithAuth(ctx) | ||
cobra.CheckErr(err) | ||
defer cmd.StoreSessionCookies(client) | ||
} | ||
// filter options | ||
id := cmd.Config.String("id") | ||
|
||
// if an orgSubscription ID is provided, filter on that orgSubscription, otherwise get all | ||
if id != "" { | ||
o, err := client.GetOrgSubscriptionByID(ctx, id) | ||
cobra.CheckErr(err) | ||
|
||
return consoleOutput(o) | ||
} | ||
|
||
// get all will be filtered for the authorized organization(s) | ||
o, err := client.GetAllOrgSubscriptions(ctx) | ||
cobra.CheckErr(err) | ||
|
||
return consoleOutput(o) | ||
} |
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,107 @@ | ||
package orgsubscription | ||
|
||
import ( | ||
"encoding/json" | ||
"strings" | ||
|
||
"github.com/spf13/cobra" | ||
|
||
"github.com/theopenlane/core/cmd/cli/cmd" | ||
"github.com/theopenlane/core/pkg/openlaneclient" | ||
"github.com/theopenlane/utils/cli/tables" | ||
) | ||
|
||
// command represents the base orgSubscription command when called without any subcommands | ||
var command = &cobra.Command{ | ||
Use: "org-subscription", | ||
Aliases: []string{"organization-subscription"}, | ||
Short: "the subcommands for working with orgSubscriptions", | ||
} | ||
|
||
func init() { | ||
cmd.RootCmd.AddCommand(command) | ||
} | ||
|
||
// consoleOutput prints the output in the console | ||
func consoleOutput(e any) error { | ||
// check if the output format is JSON and print the orgSubscriptions in JSON format | ||
if strings.EqualFold(cmd.OutputFormat, cmd.JSONOutput) { | ||
return jsonOutput(e) | ||
} | ||
|
||
// check the type of the orgSubscriptions and print them in a table format | ||
switch v := e.(type) { | ||
case *openlaneclient.GetAllOrgSubscriptions: | ||
var nodes []*openlaneclient.GetAllOrgSubscriptions_OrgSubscriptions_Edges_Node | ||
|
||
for _, i := range v.OrgSubscriptions.Edges { | ||
nodes = append(nodes, i.Node) | ||
} | ||
|
||
e = nodes | ||
case *openlaneclient.GetOrgSubscriptions: | ||
var nodes []*openlaneclient.GetOrgSubscriptions_OrgSubscriptions_Edges_Node | ||
|
||
for _, i := range v.OrgSubscriptions.Edges { | ||
nodes = append(nodes, i.Node) | ||
} | ||
|
||
e = nodes | ||
case *openlaneclient.GetOrgSubscriptionByID: | ||
e = v.OrgSubscription | ||
} | ||
|
||
s, err := json.Marshal(e) | ||
cobra.CheckErr(err) | ||
|
||
var list []openlaneclient.OrgSubscription | ||
|
||
err = json.Unmarshal(s, &list) | ||
if err != nil { | ||
var in openlaneclient.OrgSubscription | ||
err = json.Unmarshal(s, &in) | ||
cobra.CheckErr(err) | ||
|
||
list = append(list, in) | ||
} | ||
|
||
tableOutput(list) | ||
|
||
return nil | ||
} | ||
|
||
// jsonOutput prints the output in a JSON format | ||
func jsonOutput(out any) error { | ||
s, err := json.Marshal(out) | ||
cobra.CheckErr(err) | ||
|
||
return cmd.JSONPrint(s) | ||
} | ||
|
||
// tableOutput prints the output in a table format | ||
func tableOutput(out []openlaneclient.OrgSubscription) { | ||
// create a table writer | ||
// TODO: add additional columns to the table writer | ||
writer := tables.NewTableWriter(command.OutOrStdout(), "ID", "StripeCustomerID", "StripeSubscriptionStatus", "ProductTier", "Features", "ExpiresAt") | ||
for _, i := range out { | ||
features := []string{} | ||
if i.Features != nil { | ||
features = i.Features | ||
} | ||
|
||
exp := "" | ||
if i.ExpiresAt != nil { | ||
exp = i.ExpiresAt.String() | ||
} | ||
|
||
writer.AddRow(i.ID, | ||
*i.StripeCustomerID, | ||
*i.StripeSubscriptionStatus, | ||
*i.ProductTier, | ||
strings.Join(features, ", "), | ||
exp, | ||
) | ||
} | ||
|
||
writer.Render() | ||
} |
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
15 changes: 15 additions & 0 deletions
15
db/migrations-goose-postgres/20250109002850_billing_address.sql
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,15 @@ | ||
-- +goose Up | ||
-- modify "organization_setting_history" table | ||
ALTER TABLE "organization_setting_history" DROP COLUMN "billing_address"; | ||
ALTER TABLE "organization_setting_history" ADD COLUMN "billing_address" jsonb; | ||
-- modify "organization_settings" table | ||
ALTER TABLE "organization_settings" DROP COLUMN "billing_address"; | ||
ALTER TABLE "organization_settings" ADD COLUMN "billing_address" jsonb; | ||
|
||
-- +goose Down | ||
-- reverse: modify "organization_settings" table | ||
ALTER TABLE "organization_settings" DROP COLUMN "billing_address"; | ||
ALTER TABLE "organization_settings" ADD COLUMN "billing_address" character varying; | ||
-- reverse: modify "organization_setting_history" table | ||
ALTER TABLE "organization_setting_history" DROP COLUMN "billing_address"; | ||
ALTER TABLE "organization_setting_history" ADD COLUMN "billing_address" character varying; |
11 changes: 11 additions & 0 deletions
11
db/migrations-goose-postgres/20250109054654_remove_stripe_id.sql
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,11 @@ | ||
-- +goose Up | ||
-- modify "organization_setting_history" table | ||
ALTER TABLE "organization_setting_history" DROP COLUMN "stripe_id"; | ||
-- modify "organization_settings" table | ||
ALTER TABLE "organization_settings" DROP COLUMN "stripe_id"; | ||
|
||
-- +goose Down | ||
-- reverse: modify "organization_settings" table | ||
ALTER TABLE "organization_settings" ADD COLUMN "stripe_id" character varying NULL; | ||
-- reverse: modify "organization_setting_history" table | ||
ALTER TABLE "organization_setting_history" ADD COLUMN "stripe_id" character varying NULL; |
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 |
---|---|---|
@@ -1,3 +1,5 @@ | ||
h1:c4zR9ykTAtjU7Ms/SL9uYn+FgwKpfShruweuWapIs/g= | ||
h1:QXCrkYR4vxggy2Kk14xhgOkCom8B/+rl+I7Rgzroh0k= | ||
20241211231032_init.sql h1:Cj6GduEDECy6Y+8DfI6767WosqG2AKWybIyJJ6AgKqA= | ||
20241212223714_consistent_naming.sql h1:RvnNmsStlHkmAdSCnX1fFh/KYgfj1RMYYEc4iCN9JcQ= | ||
20250109002850_billing_address.sql h1:m0ek3WXqRgS3+ZbSa/DcIMB16vb8Tjm2MgNqyRll3rU= | ||
20250109054654_remove_stripe_id.sql h1:OfeshKT2+ydfx+36e4uBrdQ31tuurcJsKXyYDp1ZiZg= |
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,6 @@ | ||
-- Modify "organization_setting_history" table | ||
ALTER TABLE "organization_setting_history" DROP COLUMN "billing_address"; | ||
ALTER TABLE "organization_setting_history" ADD COLUMN "billing_address" jsonb; | ||
-- Modify "organization_settings" table | ||
ALTER TABLE "organization_settings" DROP COLUMN "billing_address"; | ||
ALTER TABLE "organization_settings" ADD COLUMN "billing_address" jsonb; |
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,4 @@ | ||
-- Modify "organization_setting_history" table | ||
ALTER TABLE "organization_setting_history" DROP COLUMN "stripe_id"; | ||
-- Modify "organization_settings" table | ||
ALTER TABLE "organization_settings" DROP COLUMN "stripe_id"; |
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 |
---|---|---|
@@ -1,3 +1,5 @@ | ||
h1:uIO0pS4MB2pqWUtAVoMnIGAJJGQ1PeXIo1UEOdi1z6g= | ||
h1:8AGIgzcKy+aGOwhLSJk/xgL6kfmXBArWQGmrkTdVur4= | ||
20241211231032_init.sql h1:TxjpHzKPB/5L2i7V2JfO1y+Cep/AyQN5wGjhY7saCeE= | ||
20241212223712_consistent_naming.sql h1:tbdYOtixhW66Jmvy3aCm+X6neI/SRVvItKM0Bdn26TA= | ||
20250109002849_billing_address.sql h1:mspCGbJ6HVmx3r4j+d/WvruzirJdJ8u5x18WF9R9ESE= | ||
20250109054653_remove_stripe_id.sql h1:dB086/w/Ws7ZK8OvbRWX7ejN4HfizCKxcE3q/+Jv4U8= |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Oops, something went wrong.