Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: [PC-13433]: add get Adjustment Events #228

Draft
wants to merge 47 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from 10 commits
Commits
Show all changes
47 commits
Select commit Hold shift + click to select a range
826f51e
feature: [PC-13433]: add get Adjustment Events
piotrkazulak Oct 7, 2024
4769205
remove unused filepath property
piotrkazulak Oct 8, 2024
98505f6
add some better error handling
piotrkazulak Oct 8, 2024
a16bfe7
brek long line into two shorter
piotrkazulak Oct 8, 2024
82ae285
Merge branch 'main' into PC-13433-sloctl-new-command-for-getdeleteupd…
piotrkazulak Oct 8, 2024
5eea234
Merge branch 'main' into PC-13433-sloctl-new-command-for-getdeleteupd…
piotrkazulak Oct 10, 2024
5ad4ac1
chore: Fix e2e tests (#229)
dawidwisn Oct 10, 2024
86b7b17
chore: Update dependency cspell to v8.15.1 (#230)
renovate[bot] Oct 11, 2024
a4ca1a4
chore: Update dependency yaml to v2.6.0 (#231)
renovate[bot] Oct 13, 2024
c9258ff
refactor
piotrkazulak Oct 14, 2024
4bba482
fix commands that do not need sdk clint setup (verriosn and context)
piotrkazulak Oct 14, 2024
53be1a2
[wip] handle errors
piotrkazulak Oct 14, 2024
392d76e
Merge remote-tracking branch 'origin/main' into PC-13433-sloctl-new-c…
piotrkazulak Oct 15, 2024
734ceea
managEment
piotrkazulak Oct 15, 2024
d604dbb
errors Errorf -> New
piotrkazulak Oct 15, 2024
8ea256d
error hangling for sdk errors
piotrkazulak Oct 15, 2024
91661a9
Add some better desciption for adjustments commands
piotrkazulak Oct 16, 2024
323c864
set nobl9-go version to RC
piotrkazulak Oct 16, 2024
8f92d04
brake down long desciption into shorter lines
piotrkazulak Oct 16, 2024
e878069
remove comment and add break line before return
piotrkazulak Oct 17, 2024
50caf10
Merge branch 'main' into PC-13433-sloctl-new-command-for-getdeleteupd…
piotrkazulak Oct 18, 2024
3f4657a
project -> sloProject
piotrkazulak Oct 18, 2024
ec8dcaf
DoRequest with body
piotrkazulak Oct 18, 2024
8841763
CR suggestion and refactor
piotrkazulak Oct 25, 2024
89107a7
CR suggestion and refactor part #2
piotrkazulak Oct 25, 2024
b761f94
one more
piotrkazulak Oct 25, 2024
a0feb14
chore: switch to new error structure (APIErrors)
piotrkazulak Oct 29, 2024
33041d1
Merge branch 'main' into PC-13433-sloctl-new-command-for-getdeleteupd…
piotrkazulak Oct 29, 2024
fa861b6
remove unnecessary embed import
piotrkazulak Nov 4, 2024
366cd23
wip: add adjustments bat
piotrkazulak Nov 5, 2024
6d28125
Merge branch 'main' into PC-13433-sloctl-new-command-for-getdeleteupd…
piotrkazulak Nov 5, 2024
6dcff0a
add delete
piotrkazulak Nov 8, 2024
3d13b32
add update
piotrkazulak Nov 8, 2024
0e30e1d
add e2e tests for update and delete
piotrkazulak Nov 8, 2024
d278e6c
cr changes
piotrkazulak Nov 13, 2024
b59ec5d
gopkg.in/yaml.v3 -> goccy/go-yaml
piotrkazulak Nov 13, 2024
ad22a73
go mod update
piotrkazulak Nov 13, 2024
682fe71
Update internal/budgetadjustments/events/inputreader.go
piotrkazulak Nov 13, 2024
dabd834
fix the replay confilct
piotrkazulak Nov 13, 2024
5901742
clean the filepath
piotrkazulak Nov 13, 2024
780daf4
fix the makefile
piotrkazulak Nov 13, 2024
9e6e977
clean up after removing dry run
piotrkazulak Nov 13, 2024
bd231c1
goccy -> nobl9/go-yaml
piotrkazulak Nov 13, 2024
eca1a90
rearange events update/delete examples
piotrkazulak Nov 13, 2024
3dd0b37
use yaml.YAMLToJSON for inputs
piotrkazulak Nov 13, 2024
714adfa
reuse file for stdin examples
piotrkazulak Nov 13, 2024
16e71de
chore: [PC-14714] - specify api version after api group name in path
piotrkazulak Nov 14, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 10 additions & 10 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -6,23 +6,22 @@ require (
github.com/go-playground/validator/v10 v10.22.1
github.com/mitchellh/colorstring v0.0.0-20190213212951-d06e56a500db
github.com/nobl9/go-yaml v1.0.1
github.com/nobl9/nobl9-go v0.89.0-rc5
github.com/nobl9/nobl9-go v0.89.0-rc9
github.com/pkg/errors v0.9.1
github.com/schollz/progressbar/v3 v3.17.1
github.com/spf13/cobra v1.8.1
nieomylnieja marked this conversation as resolved.
Show resolved Hide resolved
github.com/stretchr/testify v1.9.0
golang.org/x/sync v0.8.0
gopkg.in/yaml.v3 v3.0.1
golang.org/x/sync v0.9.0
)

require (
github.com/BurntSushi/toml v1.4.0 // indirect
github.com/MicahParks/jwkset v0.5.20 // indirect
github.com/MicahParks/keyfunc/v3 v3.3.5 // indirect
github.com/aws/aws-sdk-go v1.55.5 // indirect
github.com/bmatcuk/doublestar/v4 v4.6.1 // indirect
github.com/bmatcuk/doublestar/v4 v4.7.1 // indirect
github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc // indirect
github.com/fatih/color v1.17.0 // indirect
github.com/fatih/color v1.18.0 // indirect
github.com/gabriel-vasile/mimetype v1.4.3 // indirect
github.com/go-playground/locales v0.14.1 // indirect
github.com/go-playground/universal-translator v0.18.1 // indirect
Expand All @@ -34,20 +33,21 @@ require (
github.com/leodido/go-urn v1.4.0 // indirect
github.com/mattn/go-colorable v0.1.13 // indirect
github.com/mattn/go-isatty v0.0.20 // indirect
github.com/nobl9/govy v0.3.0 // indirect
github.com/nobl9/govy v0.6.0 // indirect
github.com/pmezard/go-difflib v1.0.1-0.20181226105442-5d4384ee4fb2 // indirect
github.com/rivo/uniseg v0.4.7 // indirect
github.com/spf13/pflag v1.0.5 // indirect
github.com/teambition/rrule-go v1.8.2 // indirect
golang.org/x/crypto v0.26.0 // indirect
golang.org/x/crypto v0.28.0 // indirect
golang.org/x/exp v0.0.0-20240808152545-0cdaa3abc0fa // indirect
golang.org/x/mod v0.20.0 // indirect
golang.org/x/net v0.28.0 // indirect
golang.org/x/net v0.30.0 // indirect
golang.org/x/sys v0.27.0 // indirect
golang.org/x/term v0.26.0 // indirect
golang.org/x/text v0.18.0 // indirect
golang.org/x/time v0.6.0 // indirect
golang.org/x/text v0.19.0 // indirect
golang.org/x/time v0.7.0 // indirect
golang.org/x/tools v0.24.0 // indirect
golang.org/x/xerrors v0.0.0-20231012003039-104605ab7028 // indirect
gopkg.in/yaml.v2 v2.4.0 // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect
)
32 changes: 16 additions & 16 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,16 @@ github.com/MicahParks/keyfunc/v3 v3.3.5 h1:7ceAJLUAldnoueHDNzF8Bx06oVcQ5CfJnYwNt
github.com/MicahParks/keyfunc/v3 v3.3.5/go.mod h1:SdCCyMJn/bYqWDvARspC6nCT8Sk74MjuAY22C7dCST8=
github.com/aws/aws-sdk-go v1.55.5 h1:KKUZBfBoyqy5d3swXyiC7Q76ic40rYcbqH7qjh59kzU=
github.com/aws/aws-sdk-go v1.55.5/go.mod h1:eRwEWoyTWFMVYVQzKMNHWP5/RV4xIUGMQfXQHfHkpNU=
github.com/bmatcuk/doublestar/v4 v4.6.1 h1:FH9SifrbvJhnlQpztAx++wlkk70QBf0iBWDwNy7PA4I=
github.com/bmatcuk/doublestar/v4 v4.6.1/go.mod h1:xBQ8jztBU6kakFMg+8WGxn0c6z1fTSPVIjEY1Wr7jzc=
github.com/bmatcuk/doublestar/v4 v4.7.1 h1:fdDeAqgT47acgwd9bd9HxJRDmc9UAmPpc+2m0CXv75Q=
github.com/bmatcuk/doublestar/v4 v4.7.1/go.mod h1:xBQ8jztBU6kakFMg+8WGxn0c6z1fTSPVIjEY1Wr7jzc=
github.com/chengxilo/virtualterm v1.0.4 h1:Z6IpERbRVlfB8WkOmtbHiDbBANU7cimRIof7mk9/PwM=
github.com/chengxilo/virtualterm v1.0.4/go.mod h1:DyxxBZz/x1iqJjFxTFcr6/x+jSpqN0iwWCOK1q10rlY=
github.com/cpuguy83/go-md2man/v2 v2.0.4/go.mod h1:tgQtvFlXSQOSOSIRvRPT7W67SCa46tRHOmNcaadrF8o=
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc h1:U9qPSI2PIWSS1VwoXQT9A3Wy9MM3WgvqSxFWenqJduM=
github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/fatih/color v1.17.0 h1:GlRw1BRJxkpqUCBKzKOw098ed57fEsKeNjpTe3cSjK4=
github.com/fatih/color v1.17.0/go.mod h1:YZ7TlrGPkiz6ku9fK3TLD/pl3CpsiFyu8N92HLgmosI=
github.com/fatih/color v1.18.0 h1:S8gINlzdQ840/4pfAwic/ZE0djQEH3wM94VfqLTZcOM=
github.com/fatih/color v1.18.0/go.mod h1:4FelSpRwEGDpQ12mAdzqdOukCy4u8WUtOY6lkT/6HfU=
github.com/gabriel-vasile/mimetype v1.4.3 h1:in2uUcidCuFcDKtdcBxlR0rJ1+fsokWf+uqxgUFjbI0=
github.com/gabriel-vasile/mimetype v1.4.3/go.mod h1:d8uq/6HKRL6CGdk+aubisF/M5GcPfT7nKyLpA0lbSSk=
github.com/go-playground/assert/v2 v2.2.0 h1:JvknZsQTYeFEAhQwI4qEt9cyV5ONwRHC+lYKSsYSR8s=
Expand Down Expand Up @@ -55,10 +55,10 @@ github.com/mitchellh/colorstring v0.0.0-20190213212951-d06e56a500db h1:62I3jR2Em
github.com/mitchellh/colorstring v0.0.0-20190213212951-d06e56a500db/go.mod h1:l0dey0ia/Uv7NcFFVbCLtqEBQbrT4OCwCSKTEv6enCw=
github.com/nobl9/go-yaml v1.0.1 h1:Aj1kSaYdRQTKlvS6ihvXzQJhCpoHhtf9nfA95zqWH4Q=
github.com/nobl9/go-yaml v1.0.1/go.mod h1:t7vCO8ctYdBweZxU5lUgxzAw31+ZcqJYeqRtrv+5RHI=
github.com/nobl9/govy v0.3.0 h1:OokgZ9PHfFNt2TkX8h/9rF0Y3doj/nnr0BlPo1BsasY=
github.com/nobl9/govy v0.3.0/go.mod h1:O+xSiKwZ6gs/orRvH5qLkfkgyT7CkuXprRIq3C5uNXQ=
github.com/nobl9/nobl9-go v0.89.0-rc5 h1:0jTuMHnCPiwSe3SIuwQy0creIzw8qxnaZRh7fq5A9Ow=
github.com/nobl9/nobl9-go v0.89.0-rc5/go.mod h1:jICYB6/RFcKs/Mqm3ltGbsD2Ign64/uy8JMaHxpYQ5o=
github.com/nobl9/govy v0.6.0 h1:8L3H4zeqA7sUCBg1tuyyudLpOi7vHz6WYTRfu/VyKeg=
github.com/nobl9/govy v0.6.0/go.mod h1:O+xSiKwZ6gs/orRvH5qLkfkgyT7CkuXprRIq3C5uNXQ=
github.com/nobl9/nobl9-go v0.89.0-rc9 h1:NaBRW1M5SJ6lU+rthnFprxtAM//qq7OkYR5DizdyjZs=
github.com/nobl9/nobl9-go v0.89.0-rc9/go.mod h1:sRq/wy0F/nSCylW1x26syiCVDG3K4jbJaZWobKNHOQs=
github.com/pkg/errors v0.9.1 h1:FEBLx1zS214owpjy7qsBeixbURkuhQAwrK5UwLGTwt4=
github.com/pkg/errors v0.9.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
Expand All @@ -78,14 +78,14 @@ github.com/stretchr/testify v1.9.0 h1:HtqpIVDClZ4nwg75+f6Lvsy/wHu+3BoSGCbBAcpTsT
github.com/stretchr/testify v1.9.0/go.mod h1:r2ic/lqez/lEtzL7wO/rwa5dbSLXVDPFyf8C91i36aY=
github.com/teambition/rrule-go v1.8.2 h1:lIjpjvWTj9fFUZCmuoVDrKVOtdiyzbzc93qTmRVe/J8=
github.com/teambition/rrule-go v1.8.2/go.mod h1:Ieq5AbrKGciP1V//Wq8ktsTXwSwJHDD5mD/wLBGl3p4=
golang.org/x/crypto v0.26.0 h1:RrRspgV4mU+YwB4FYnuBoKsUapNIL5cohGAmSH3azsw=
golang.org/x/crypto v0.26.0/go.mod h1:GY7jblb9wI+FOo5y8/S2oY4zWP07AkOJ4+jxCqdqn54=
golang.org/x/crypto v0.28.0 h1:GBDwsMXVQi34v5CCYUm2jkJvu4cbtru2U4TN2PSyQnw=
golang.org/x/crypto v0.28.0/go.mod h1:rmgy+3RHxRZMyY0jjAJShp2zgEdOqj2AO7U0pYmeQ7U=
golang.org/x/exp v0.0.0-20240808152545-0cdaa3abc0fa h1:ELnwvuAXPNtPk1TJRuGkI9fDTwym6AYBu0qzT8AcHdI=
golang.org/x/exp v0.0.0-20240808152545-0cdaa3abc0fa/go.mod h1:akd2r19cwCdwSwWeIdzYQGa/EZZyqcOdwWiwj5L5eKQ=
golang.org/x/mod v0.20.0 h1:utOm6MM3R3dnawAiJgn0y+xvuYRsm1RKM/4giyfDgV0=
golang.org/x/mod v0.20.0/go.mod h1:hTbmBsO62+eylJbnUtE2MGJUyE7QWk4xUqPFrRgJ+7c=
golang.org/x/net v0.28.0 h1:a9JDOJc5GMUJ0+UDqmLT86WiEy7iWyIhz8gz8E4e5hE=
golang.org/x/net v0.28.0/go.mod h1:yqtgsTWOOnlGLG9GFRrK3++bGOUEkNBoHZc8MEDWPNg=
golang.org/x/net v0.30.0 h1:AcW1SDZMkb8IpzCdQUaIq2sP4sZ4zw+55h6ynffypl4=
golang.org/x/net v0.30.0/go.mod h1:2wGyMJ5iFasEhkwi13ChkO/t1ECNC4X4eBKkVFyYFlU=
golang.org/x/sync v0.9.0 h1:fEo0HyrW1GIgZdpbhCRO0PkJajUS5H9IFUztCgEo2jQ=
golang.org/x/sync v0.9.0/go.mod h1:Czt+wKu1gCyEFDUtn0jG5QVvpJ6rzVqr5aXyt9drQfk=
golang.org/x/sys v0.0.0-20220811171246-fbc7d0a398ab/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
Expand All @@ -94,10 +94,10 @@ golang.org/x/sys v0.27.0 h1:wBqf8DvsY9Y/2P8gAfPDEYNuS30J4lPHJxXSb/nJZ+s=
golang.org/x/sys v0.27.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
golang.org/x/term v0.26.0 h1:WEQa6V3Gja/BhNxg540hBip/kkaYtRg3cxg4oXSw4AU=
golang.org/x/term v0.26.0/go.mod h1:Si5m1o57C5nBNQo5z1iq+XDijt21BDBDp2bK0QI8e3E=
golang.org/x/text v0.18.0 h1:XvMDiNzPAl0jr17s6W9lcaIhGUfUORdGCNsuLmPG224=
golang.org/x/text v0.18.0/go.mod h1:BuEKDfySbSR4drPmRPG/7iBdf8hvFMuRexcpahXilzY=
golang.org/x/time v0.6.0 h1:eTDhh4ZXt5Qf0augr54TN6suAUudPcawVZeIAPU7D4U=
golang.org/x/time v0.6.0/go.mod h1:3BpzKBy/shNhVucY/MWOyx10tF3SFh9QdLuxbVysPQM=
golang.org/x/text v0.19.0 h1:kTxAhCbGbxhK0IwgSKiMO5awPoDQ0RpfiVYBfK860YM=
golang.org/x/text v0.19.0/go.mod h1:BuEKDfySbSR4drPmRPG/7iBdf8hvFMuRexcpahXilzY=
golang.org/x/time v0.7.0 h1:ntUhktv3OPE6TgYxXWv9vKvUSJyIFJlyohwbkEwPrKQ=
golang.org/x/time v0.7.0/go.mod h1:3BpzKBy/shNhVucY/MWOyx10tF3SFh9QdLuxbVysPQM=
golang.org/x/tools v0.24.0 h1:J1shsA93PJUEVaUSaay7UXAyE8aimq3GW0pjlolpa24=
golang.org/x/tools v0.24.0/go.mod h1:YhNqVBIfWHdzvTLs0d8LCuMhkKUgSUKldakyV7W/WDQ=
golang.org/x/xerrors v0.0.0-20231012003039-104605ab7028 h1:+cNy6SZtPcJQH3LJVLOSmiC7MMxXNOb3PU/VUEz+EhU=
Expand Down
4 changes: 2 additions & 2 deletions internal/apply.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,14 +45,14 @@ func (r *RootCmd) NewApplyCmd() *cobra.Command {
apply.client.Config.Project = apply.project
}
if apply.dryRun {
flags.NotifyDryRunFlag()
notifyDryRunFlag()
}
},
RunE: func(cmd *cobra.Command, args []string) error { return apply.Run(cmd) },
}

registerFileFlag(cmd, true, &apply.definitionPaths)
flags.RegisterDryRunFlag(cmd, &apply.dryRun)
registerDryRunFlag(cmd, &apply.dryRun)
registerAutoConfirmationFlag(cmd, &apply.autoConfirm)
cmd.Flags().StringVarP(&apply.project, "project", "p", "",
`Assigns the provided Project to the resources if no Project is defined in the object's definition.`)
Expand Down
34 changes: 9 additions & 25 deletions internal/budgetadjustments/events/delete.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,58 +5,46 @@ import (
_ "embed"
"encoding/json"
"fmt"
"io"
"net/http"
"os"

"github.com/nobl9/go-yaml"
"github.com/nobl9/nobl9-go/sdk"
"github.com/pkg/errors"
"github.com/spf13/cobra"
"gopkg.in/yaml.v3"

"github.com/nobl9/sloctl/internal/budgetadjustments/sdkclient"
"github.com/nobl9/sloctl/internal/flags"
)

type DeleteCmd struct {
client *sdk.Client
filepath string
dryRun bool
outputFormat string
fieldSeparator string
recordSeparator string
out io.Writer
adjustment string
client *sdk.Client
filepath string
adjustment string
}

//go:embed examples/delete_example.sh
var deleteExample string

func NewDeleteCmd(clientProvider sdkclient.SdkClientProvider) *cobra.Command {
deleteCmd := &DeleteCmd{out: os.Stdout}
deleteCmd := &DeleteCmd{}

cmd := &cobra.Command{
Use: "delete",
Short: "Delete existing events with new values. Values for eventStart and eventEnd are required.",
Short: "Delete existing events.",

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
Short: "Delete existing events.",
Short: "Delete past existing events.",

Example: deleteExample,
PersistentPreRun: func(cmd *cobra.Command, args []string) {
deleteCmd.client = clientProvider.GetClient()
if deleteCmd.dryRun {
flags.NotifyDryRunFlag()
}
},
RunE: func(cmd *cobra.Command, args []string) error { return deleteCmd.run(cmd) },
}

MustRegisterFileFlag(cmd, &deleteCmd.filepath)
flags.RegisterDryRunFlag(cmd, &deleteCmd.dryRun)
MustRegisterAdjustmentFlag(cmd, &deleteCmd.adjustment)
mustRegisterFileFlag(cmd, &deleteCmd.filepath)
mustRegisterAdjustmentFlag(cmd, &deleteCmd.adjustment)

return cmd
}

func (g *DeleteCmd) run(cmd *cobra.Command) error {
data, err := read(g.filepath)
data, err := readFile(g.filepath)
if err != nil {
return errors.Wrap(err, "failed to read input data")
}
Expand All @@ -69,10 +57,6 @@ func (g *DeleteCmd) run(cmd *cobra.Command) error {
return errors.Wrap(err, "failed to convert input data to JSON")
}

if g.dryRun {
return nil
}

if _, err = DoRequest(
g.client,
cmd.Context(),
Expand Down
21 changes: 18 additions & 3 deletions internal/budgetadjustments/events/examples/delete_example.sh
Original file line number Diff line number Diff line change
@@ -1,11 +1,26 @@
# Delete Adjustment Evens using a file
sloctl budgetadjustments events delete --adjustment-name=sample-adjustment-name -f /path/to/file/with/events
# Delete Adjustment Events using a file
sloctl budgetadjustments events delete --adjustment-name=sample-adjustment-name -f /path/to/file/with/events/yaml

nieomylnieja marked this conversation as resolved.
Show resolved Hide resolved
# Delete Adjustment Event using stdin:
# Delete Adjustment Events using stdin:
echo '
- eventStart: 2024-10-25T04:07:04Z
nieomylnieja marked this conversation as resolved.
Show resolved Hide resolved
eventEnd: 2024-10-25T05:27:04Z
slos:
- project: test-project
name: sample-slo-10
' | sloctl budgetadjustments events delete --adjustment-name=sample-adjustment-name -f -

# Delete Adjustment Events using a file:
cat <<EOF > ./events.yaml
- eventStart: 2024-10-24T04:07:04Z
eventEnd: 2024-10-24T05:27:04Z
slos:
- project: test-project
name: sample-slo-1
- eventStart: 2024-10-25T04:07:04Z
eventEnd: 2024-10-25T05:27:04Z
slos:
- project: test-project
name: sample-slo-2
EOF
sloctl budgetadjustments events delete --adjustment-name=sample-adjustment-name -f ./events.yaml
26 changes: 24 additions & 2 deletions internal/budgetadjustments/events/examples/update_example.sh
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# Update Adjustment Evens using a file
# Update Adjustment Events using a file
sloctl budgetadjustments events update --adjustment-name=sample-adjustment-name -f /path/to/file/with/events
nieomylnieja marked this conversation as resolved.
Show resolved Hide resolved

# Update Adjustment Event using stdin:
# Update Adjustment Events using stdin:
echo '
- eventStart: 2024-10-25T04:07:04Z
eventEnd: 2024-10-25T05:27:04Z
Expand All @@ -12,3 +12,25 @@ echo '
eventStart: 2024-10-25T03:07:04Z
eventEnd: 2024-10-25T04:27:04Z
' | sloctl budgetadjustments events update --adjustment-name=sample-adjustment-name -f -


# Update Adjustment Events using a file:
cat <<EOF > ./events.yaml
- eventStart: 2024-10-24T04:07:04Z
eventEnd: 2024-10-24T05:27:04Z
slos:
- project: test-project
name: sample-slo-1
update:
eventStart: 2024-10-24T03:07:04Z
eventEnd: 2024-10-24T04:27:04Z
- eventStart: 2024-10-25T04:07:04Z
eventEnd: 2024-10-25T05:27:04Z
slos:
- project: test-project
name: sample-slo-2
update:
eventStart: 2024-10-25T03:07:04Z
eventEnd: 2024-10-25T04:27:04Z
EOF
sloctl budgetadjustments events update --adjustment-name=sample-adjustment-name -f ./events.yaml
12 changes: 6 additions & 6 deletions internal/budgetadjustments/events/flags.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,32 +15,32 @@ const (
FlagSloName = "slo-name"
)

func MustRegisterFileFlag(cmd *cobra.Command, storeIn *string) {
func mustRegisterFileFlag(cmd *cobra.Command, storeIn *string) {
cmd.Flags().StringVarP(storeIn, FlagFile, "f", "",
"File path to events definitions in YAML.")
if err := cmd.MarkFlagRequired(FlagFile); err != nil {
panic(err)
}
}

func MustRegisterAdjustmentFlag(cmd *cobra.Command, storeIn *string) {
func mustRegisterAdjustmentFlag(cmd *cobra.Command, storeIn *string) {
cmd.Flags().StringVar(storeIn, FlagAdjustment, "", "Name of the Adjustment.")
if err := cmd.MarkFlagRequired(FlagAdjustment); err != nil {
panic(err)
}
}

func RegisterProjectFlag(cmd *cobra.Command, storeIn *string) {
func registerProjectFlag(cmd *cobra.Command, storeIn *string) {
cmd.Flags().StringVarP(storeIn, FlagSloProject, "", "",
"Name of the project. Required when sloName is defined.")
}

func RegisterSloNameFlag(cmd *cobra.Command, storeIn *string) {
func registerSloNameFlag(cmd *cobra.Command, storeIn *string) {
cmd.Flags().StringVarP(storeIn, FlagSloName, "", "",
"Name of the SLO. Required when sloName is defined.")
}

func MustRegisterFromFlag(
func mustRegisterFromFlag(
cmd *cobra.Command,
storeIn *flags.TimeValue,
) {
Expand All @@ -51,7 +51,7 @@ func MustRegisterFromFlag(
}
}

func MustRegisterToFlag(
func mustRegisterToFlag(
cmd *cobra.Command,
storeIn *flags.TimeValue,
) {
Expand Down
10 changes: 5 additions & 5 deletions internal/budgetadjustments/events/get.go
Original file line number Diff line number Diff line change
Expand Up @@ -70,11 +70,11 @@ func NewGetCmd(clientProvider sdkclient.SdkClientProvider) *cobra.Command {
&get.fieldSeparator,
&get.recordSeparator,
)
MustRegisterAdjustmentFlag(cmd, &get.adjustment)
RegisterProjectFlag(cmd, &get.project)
RegisterSloNameFlag(cmd, &get.sloName)
MustRegisterFromFlag(cmd, &get.from)
MustRegisterToFlag(cmd, &get.to)
mustRegisterAdjustmentFlag(cmd, &get.adjustment)
registerProjectFlag(cmd, &get.project)
registerSloNameFlag(cmd, &get.sloName)
mustRegisterFromFlag(cmd, &get.from)
mustRegisterToFlag(cmd, &get.to)

return cmd
}
Expand Down
4 changes: 3 additions & 1 deletion internal/budgetadjustments/events/inputreader.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,13 @@ package events
import (
"io"
"os"
"path/filepath"
)

func read(path string) (data []byte, err error) {
func readFile(path string) (data []byte, err error) {
if path == "" || path == "-" {
return io.ReadAll(os.Stdin)
}
path = filepath.Clean(path)
return os.ReadFile(path) // #nosec G304
}
Loading
Loading