generated from matoszz/mitbgo-template
-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: enthistory perms for realz hopefully (#1156)
* audit logs with permissions, history cli commands Signed-off-by: Sarah Funkhouser <[email protected]> * enthistory version Signed-off-by: Sarah Funkhouser <[email protected]> --------- Signed-off-by: Sarah Funkhouser <[email protected]>
- Loading branch information
1 parent
58070a0
commit c2dd8f0
Showing
265 changed files
with
14,169 additions
and
7,781 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,2 @@ | ||
// Package datumcontacthistory is our cobra cli for contactHistory endpoints | ||
package datumcontacthistory |
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,49 @@ | ||
package datumcontacthistory | ||
|
||
import ( | ||
"context" | ||
|
||
"github.com/spf13/cobra" | ||
|
||
datum "github.com/datumforge/datum/cmd/cli/cmd" | ||
"github.com/datumforge/datum/pkg/datumclient" | ||
) | ||
|
||
var getCmd = &cobra.Command{ | ||
Use: "get", | ||
Short: "get an existing datum contactHistory", | ||
Run: func(cmd *cobra.Command, args []string) { | ||
err := get(cmd.Context()) | ||
cobra.CheckErr(err) | ||
}, | ||
} | ||
|
||
func init() { | ||
cmd.AddCommand(getCmd) | ||
getCmd.Flags().StringP("id", "i", "", "id to query") | ||
} | ||
|
||
// get an existing contactHistory in the datum platform | ||
func get(ctx context.Context) error { | ||
// setup datum http client | ||
client, err := datum.SetupClientWithAuth(ctx) | ||
cobra.CheckErr(err) | ||
defer datum.StoreSessionCookies(client) | ||
|
||
// filter options | ||
id := datum.Config.String("id") | ||
if id != "" { | ||
o, err := client.GetContactHistories(ctx, &datumclient.ContactHistoryWhereInput{ | ||
Ref: &id, | ||
}) | ||
cobra.CheckErr(err) | ||
|
||
return consoleOutput(o) | ||
} | ||
|
||
// get all will be filtered for the authorized organization(s) | ||
o, err := client.GetAllContactHistories(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,86 @@ | ||
package datumcontacthistory | ||
|
||
import ( | ||
"encoding/json" | ||
|
||
"github.com/spf13/cobra" | ||
|
||
datum "github.com/datumforge/datum/cmd/cli/cmd" | ||
"github.com/datumforge/datum/pkg/datumclient" | ||
"github.com/datumforge/datum/pkg/utils/cli/tables" | ||
) | ||
|
||
// cmd represents the base contactHistory command when called without any subcommands | ||
var cmd = &cobra.Command{ | ||
Use: "contact-history", | ||
Short: "the subcommands for working with datum contactHistories", | ||
} | ||
|
||
func init() { | ||
datum.RootCmd.AddCommand(cmd) | ||
} | ||
|
||
// consoleOutput prints the output in the console | ||
func consoleOutput(e any) error { | ||
// check if the output format is JSON and print the contactHistories in JSON format | ||
if datum.OutputFormat == datum.JSONOutput { | ||
return jsonOutput(e) | ||
} | ||
|
||
// check the type of the contactHistories and print them in a table format | ||
switch v := e.(type) { | ||
case *datumclient.GetAllContactHistories: | ||
var nodes []*datumclient.GetAllContactHistories_ContactHistories_Edges_Node | ||
|
||
for _, i := range v.ContactHistories.Edges { | ||
nodes = append(nodes, i.Node) | ||
} | ||
|
||
e = nodes | ||
case *datumclient.GetContactHistories: | ||
var nodes []*datumclient.GetContactHistories_ContactHistories_Edges_Node | ||
|
||
for _, i := range v.ContactHistories.Edges { | ||
nodes = append(nodes, i.Node) | ||
} | ||
|
||
e = nodes | ||
} | ||
|
||
s, err := json.Marshal(e) | ||
cobra.CheckErr(err) | ||
|
||
var list []datumclient.ContactHistory | ||
|
||
err = json.Unmarshal(s, &list) | ||
if err != nil { | ||
var in datumclient.ContactHistory | ||
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 datum.JSONPrint(s) | ||
} | ||
|
||
// tableOutput prints the output in a table format | ||
func tableOutput(out []datumclient.ContactHistory) { | ||
// create a table writer | ||
writer := tables.NewTableWriter(cmd.OutOrStdout(), "ID", "Ref", "Operation", "UpdatedAt", "UpdatedBy") | ||
for _, i := range out { | ||
writer.AddRow(i.ID, *i.Ref, i.Operation, *i.UpdatedAt, *i.UpdatedBy) | ||
} | ||
|
||
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
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 datumentitlementplanfeaturehistory is our cobra cli for entitlementPlanFeatureHistory endpoints | ||
package datumentitlementplanfeaturehistory |
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,49 @@ | ||
package datumentitlementplanfeaturehistory | ||
|
||
import ( | ||
"context" | ||
|
||
"github.com/spf13/cobra" | ||
|
||
datum "github.com/datumforge/datum/cmd/cli/cmd" | ||
"github.com/datumforge/datum/pkg/datumclient" | ||
) | ||
|
||
var getCmd = &cobra.Command{ | ||
Use: "get", | ||
Short: "get an existing datum entitlementPlanFeatureHistory", | ||
Run: func(cmd *cobra.Command, args []string) { | ||
err := get(cmd.Context()) | ||
cobra.CheckErr(err) | ||
}, | ||
} | ||
|
||
func init() { | ||
cmd.AddCommand(getCmd) | ||
getCmd.Flags().StringP("id", "i", "", "id to query") | ||
} | ||
|
||
// get an existing entitlementPlanFeatureHistory in the datum platform | ||
func get(ctx context.Context) error { | ||
// setup datum http client | ||
client, err := datum.SetupClientWithAuth(ctx) | ||
cobra.CheckErr(err) | ||
defer datum.StoreSessionCookies(client) | ||
|
||
// filter options | ||
id := datum.Config.String("id") | ||
if id != "" { | ||
o, err := client.GetEntitlementPlanFeatureHistories(ctx, &datumclient.EntitlementPlanFeatureHistoryWhereInput{ | ||
Ref: &id, | ||
}) | ||
cobra.CheckErr(err) | ||
|
||
return consoleOutput(o) | ||
} | ||
|
||
// get all will be filtered for the authorized organization(s) | ||
o, err := client.GetAllEntitlementPlanFeatureHistories(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,86 @@ | ||
package datumentitlementplanfeaturehistory | ||
|
||
import ( | ||
"encoding/json" | ||
|
||
"github.com/spf13/cobra" | ||
|
||
datum "github.com/datumforge/datum/cmd/cli/cmd" | ||
"github.com/datumforge/datum/pkg/datumclient" | ||
"github.com/datumforge/datum/pkg/utils/cli/tables" | ||
) | ||
|
||
// cmd represents the base entitlementPlanFeatureHistory command when called without any subcommands | ||
var cmd = &cobra.Command{ | ||
Use: "entitlement-plan-feature-history", | ||
Short: "the subcommands for working with datum entitlementPlanFeatureHistories", | ||
} | ||
|
||
func init() { | ||
datum.RootCmd.AddCommand(cmd) | ||
} | ||
|
||
// consoleOutput prints the output in the console | ||
func consoleOutput(e any) error { | ||
// check if the output format is JSON and print the entitlementPlanFeatureHistories in JSON format | ||
if datum.OutputFormat == datum.JSONOutput { | ||
return jsonOutput(e) | ||
} | ||
|
||
// check the type of the entitlementPlanFeatureHistories and print them in a table format | ||
switch v := e.(type) { | ||
case *datumclient.GetAllEntitlementPlanFeatureHistories: | ||
var nodes []*datumclient.GetAllEntitlementPlanFeatureHistories_EntitlementPlanFeatureHistories_Edges_Node | ||
|
||
for _, i := range v.EntitlementPlanFeatureHistories.Edges { | ||
nodes = append(nodes, i.Node) | ||
} | ||
|
||
e = nodes | ||
case *datumclient.GetEntitlementPlanFeatureHistories: | ||
var nodes []*datumclient.GetEntitlementPlanFeatureHistories_EntitlementPlanFeatureHistories_Edges_Node | ||
|
||
for _, i := range v.EntitlementPlanFeatureHistories.Edges { | ||
nodes = append(nodes, i.Node) | ||
} | ||
|
||
e = nodes | ||
} | ||
|
||
s, err := json.Marshal(e) | ||
cobra.CheckErr(err) | ||
|
||
var list []datumclient.EntitlementPlanFeatureHistory | ||
|
||
err = json.Unmarshal(s, &list) | ||
if err != nil { | ||
var in datumclient.EntitlementPlanFeatureHistory | ||
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 datum.JSONPrint(s) | ||
} | ||
|
||
// tableOutput prints the output in a table format | ||
func tableOutput(out []datumclient.EntitlementPlanFeatureHistory) { | ||
// create a table writer | ||
writer := tables.NewTableWriter(cmd.OutOrStdout(), "ID", "Ref", "Operation", "UpdatedAt", "UpdatedBy") | ||
for _, i := range out { | ||
writer.AddRow(i.ID, *i.Ref, i.Operation, *i.UpdatedAt, *i.UpdatedBy) | ||
} | ||
|
||
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
// Package datumentitlementplanhistory is our cobra cli for entitlementPlanHistory endpoints | ||
package datumentitlementplanhistory |
Oops, something went wrong.