Skip to content

Commit

Permalink
feat: billingAddress to JSON, add subscriptionURL to orbSubscriptions…
Browse files Browse the repository at this point in the history
… 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
golanglemonade authored Jan 9, 2025
1 parent 3bc27f9 commit fe5f729
Show file tree
Hide file tree
Showing 75 changed files with 897 additions and 5,491 deletions.
8 changes: 7 additions & 1 deletion cmd/cli/Taskfile.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,12 @@ tasks:
cmds:
- go run main.go organization-setting get

orgsub:get:
desc: gets the org subscription
aliases: [getorgsub]
cmds:
- go run main.go org-subscription get

token:create:
desc: creates an api token against a running local instance of the server
aliases: [tokencreate]
Expand Down Expand Up @@ -96,7 +102,7 @@ tasks:
- task: program:create
- task: token:create
- task: pat:create
- task: getorgsetting
- task: orgsub:get


user:all:another:
Expand Down
9 changes: 9 additions & 0 deletions cmd/cli/cmd/organization/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,15 @@ func consoleOutput(e any) error {
nodes = append(nodes, i.Node)
}

e = nodes
e = nodes
case *openlaneclient.GetOrganizations:
var nodes []*openlaneclient.GetOrganizations_Organizations_Edges_Node

for _, i := range v.Organizations.Edges {
nodes = append(nodes, i.Node)
}

e = nodes
case *openlaneclient.GetOrganizationByID:
e = v.Organization
Expand Down
6 changes: 2 additions & 4 deletions cmd/cli/cmd/organizationsetting/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -94,20 +94,18 @@ func tableOutput(out []openlaneclient.OrganizationSetting) {
"TaxIdentifier",
"Tags",
"Domains",
"StripeID",
)
for _, i := range out {
writer.AddRow(i.ID,
i.Organization.Name,
*i.BillingContact,
*i.BillingAddress,
i.BillingAddress.String(),
*i.BillingEmail,
*i.BillingPhone,
*i.GeoLocation,
*i.TaxIdentifier,
strings.Join(i.Tags, ", "),
strings.Join(i.Domains, ", "),
*i.StripeID)
strings.Join(i.Domains, ", "))
}

writer.Render()
Expand Down
6 changes: 0 additions & 6 deletions cmd/cli/cmd/organizationsetting/update.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ func init() {
updateCmd.Flags().StringP("billing-contact", "c", "", "billing contact for the org")
updateCmd.Flags().StringP("billing-email", "e", "", "billing email for the org")
updateCmd.Flags().StringP("billing-phone", "p", "", "billing phone for the org")
updateCmd.Flags().StringP("billing-address", "a", "", "billing address for the org")
updateCmd.Flags().StringP("tax-identifier", "x", "", "tax identifier for the org")
updateCmd.Flags().StringSliceP("tags", "t", []string{}, "tags associated with the org")
}
Expand All @@ -53,11 +52,6 @@ func updateValidation() (id string, input openlaneclient.UpdateOrganizationSetti
input.BillingPhone = &billingPhone
}

billingAddress := cmd.Config.String("billing-address")
if billingAddress != "" {
input.BillingAddress = &billingAddress
}

taxIdentifier := cmd.Config.String("tax-identifier")
if taxIdentifier != "" {
input.TaxIdentifier = &taxIdentifier
Expand Down
2 changes: 2 additions & 0 deletions cmd/cli/cmd/orgsubscription/doc.go
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
52 changes: 52 additions & 0 deletions cmd/cli/cmd/orgsubscription/get.go
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)
}
107 changes: 107 additions & 0 deletions cmd/cli/cmd/orgsubscription/root.go
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()
}
1 change: 1 addition & 0 deletions cmd/cli/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import (
_ "github.com/theopenlane/core/cmd/cli/cmd/organization"
_ "github.com/theopenlane/core/cmd/cli/cmd/organizationsetting"
_ "github.com/theopenlane/core/cmd/cli/cmd/orgmembers"
_ "github.com/theopenlane/core/cmd/cli/cmd/orgsubscription"
_ "github.com/theopenlane/core/cmd/cli/cmd/personalaccesstokens"
_ "github.com/theopenlane/core/cmd/cli/cmd/procedure"
_ "github.com/theopenlane/core/cmd/cli/cmd/program"
Expand Down
2 changes: 1 addition & 1 deletion cmd/serve.go
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ func serve(ctx context.Context) error {
)

// Setup DB connection
log.Info().Interface("db", so.Config.Settings.DB).Msg("connecting to database")
log.Info().Interface("db", so.Config.Settings.DB.DatabaseName).Msg("connecting to database")

jobOpts := []riverqueue.Option{
riverqueue.WithConnectionURI(so.Config.Settings.JobQueue.ConnectionURI),
Expand Down
15 changes: 15 additions & 0 deletions db/migrations-goose-postgres/20250109002850_billing_address.sql
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 db/migrations-goose-postgres/20250109054654_remove_stripe_id.sql
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;
4 changes: 3 additions & 1 deletion db/migrations-goose-postgres/atlas.sum
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=
6 changes: 6 additions & 0 deletions db/migrations/20250109002849_billing_address.sql
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;
4 changes: 4 additions & 0 deletions db/migrations/20250109054653_remove_stripe_id.sql
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";
4 changes: 3 additions & 1 deletion db/migrations/atlas.sum
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=
3 changes: 0 additions & 3 deletions internal/ent/generated/auditing.go

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

24 changes: 6 additions & 18 deletions internal/ent/generated/entql.go

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

Loading

0 comments on commit fe5f729

Please sign in to comment.