Skip to content

Commit

Permalink
feat: enthistory perms for realz hopefully (#1156)
Browse files Browse the repository at this point in the history
* 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
golanglemonade authored Aug 1, 2024
1 parent 58070a0 commit c2dd8f0
Show file tree
Hide file tree
Showing 265 changed files with 14,169 additions and 7,781 deletions.
9 changes: 9 additions & 0 deletions cmd/cli/Taskfile.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,15 @@ tasks:
- for: {var: SCHEMAS, as: SCHEMA}
cmd: go run gencmd/generate/main.go generate --name={{ .SCHEMA }} --read-only

generate:all:history:force:
desc: regenerates the cli cmd for all history commands from the query/ directory, this will overwrite any changes made to the generated files
vars:
SCHEMAS:
sh: ls -d ../../query/* | cut -f1 |grep history | sed -e "s/query\///" |sed -e "s/.graphql//" | sed -e "s/history/History/" | sed -e "s/..\/..\///"
cmds:
- for: {var: SCHEMAS, as: SCHEMA}
cmd: go run gencmd/generate/main.go generate --name={{ .SCHEMA }} --read-only --force

generate:
desc: generates a new cli cmd
interactive: true
Expand Down
2 changes: 2 additions & 0 deletions cmd/cli/cmd/contacthistory/doc.go
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
49 changes: 49 additions & 0 deletions cmd/cli/cmd/contacthistory/get.go
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)
}
86 changes: 86 additions & 0 deletions cmd/cli/cmd/contacthistory/root.go
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()
}
15 changes: 13 additions & 2 deletions cmd/cli/cmd/documentdatahistory/get.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (
"github.com/spf13/cobra"

datum "github.com/datumforge/datum/cmd/cli/cmd"
"github.com/datumforge/datum/pkg/datumclient"
)

var getCmd = &cobra.Command{
Expand All @@ -19,8 +20,7 @@ var getCmd = &cobra.Command{

func init() {
cmd.AddCommand(getCmd)

getCmd.Flags().StringP("id", "i", "", "documentDataHistory id to query")
getCmd.Flags().StringP("id", "i", "", "id to query")
}

// get an existing documentDataHistory in the datum platform
Expand All @@ -30,6 +30,17 @@ func get(ctx context.Context) error {
cobra.CheckErr(err)
defer datum.StoreSessionCookies(client)

// filter options
id := datum.Config.String("id")
if id != "" {
o, err := client.GetDocumentDataHistories(ctx, &datumclient.DocumentDataHistoryWhereInput{
Ref: &id,
})
cobra.CheckErr(err)

return consoleOutput(o)
}

// get all will be filtered for the authorized organization(s)
o, err := client.GetAllDocumentDataHistories(ctx)
cobra.CheckErr(err)
Expand Down
15 changes: 13 additions & 2 deletions cmd/cli/cmd/entitlementhistory/get.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (
"github.com/spf13/cobra"

datum "github.com/datumforge/datum/cmd/cli/cmd"
"github.com/datumforge/datum/pkg/datumclient"
)

var getCmd = &cobra.Command{
Expand All @@ -19,8 +20,7 @@ var getCmd = &cobra.Command{

func init() {
cmd.AddCommand(getCmd)

getCmd.Flags().StringP("id", "i", "", "entitlementHistory id to query")
getCmd.Flags().StringP("id", "i", "", "id to query")
}

// get an existing entitlementHistory in the datum platform
Expand All @@ -30,6 +30,17 @@ func get(ctx context.Context) error {
cobra.CheckErr(err)
defer datum.StoreSessionCookies(client)

// filter options
id := datum.Config.String("id")
if id != "" {
o, err := client.GetEntitlementHistories(ctx, &datumclient.EntitlementHistoryWhereInput{
Ref: &id,
})
cobra.CheckErr(err)

return consoleOutput(o)
}

// get all will be filtered for the authorized organization(s)
o, err := client.GetAllEntitlementHistories(ctx)
cobra.CheckErr(err)
Expand Down
2 changes: 2 additions & 0 deletions cmd/cli/cmd/entitlementplanfeaturehistory/doc.go
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
49 changes: 49 additions & 0 deletions cmd/cli/cmd/entitlementplanfeaturehistory/get.go
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)
}
86 changes: 86 additions & 0 deletions cmd/cli/cmd/entitlementplanfeaturehistory/root.go
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()
}
2 changes: 2 additions & 0 deletions cmd/cli/cmd/entitlementplanhistory/doc.go
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
Loading

0 comments on commit c2dd8f0

Please sign in to comment.