Skip to content

Commit

Permalink
Merge pull request #820 from aziontech/chore/delete_bucket
Browse files Browse the repository at this point in the history
fix: delete bucket
  • Loading branch information
maxwelbm authored May 23, 2024
2 parents c6f550e + 04c9d7f commit e6f3c47
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 5 deletions.
1 change: 1 addition & 0 deletions pkg/cmd/delete/edge_storage/bucket.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ func (b *bucket) runE(cmd *cobra.Command, _ []string) error {
}
}
logger.FInfo(b.factory.IOStreams.Out, "Delete all objects from bucket\n")
logger.FInfo(b.factory.IOStreams.Out, "Deleting objects...")
if err := deleteAllObjects(client, ctx, b.name, ""); err != nil {
return err
}
Expand Down
11 changes: 8 additions & 3 deletions pkg/cmd/root/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -79,11 +79,16 @@ func NewCobraCmd(rootCmd *RootCmd, f *cmdutil.Factory) *cobra.Command {
if strings.HasPrefix(configFlag, PREFIX_FLAG) {
return msg.ErrorPrefix
}
schedule.ExecSchedules(f)
return doPreCommandCheck(cmd, f, PreCmd{

if err := doPreCommandCheck(cmd, f, PreCmd{
config: configFlag,
token: tokenFlag,
})
}); err != nil {
return err
}

schedule.ExecSchedules(f)
return nil
},
Example: heredoc.Doc(`
$ azion
Expand Down
2 changes: 1 addition & 1 deletion pkg/schedule/bucket.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import (
api "github.com/aziontech/azion-cli/pkg/api/storage"
)

const DELETE_BUCKET = "DeleteBucket"
const DELETE_BUCKET = "DeleteBucket"

func TriggerDeleteBucket(f *cmdutil.Factory, name string) error {
client := api.NewClient(
Expand Down
9 changes: 8 additions & 1 deletion pkg/schedule/schedule.go
Original file line number Diff line number Diff line change
Expand Up @@ -93,21 +93,28 @@ func readFileSchedule() ([]Schedule, error) {
}

func ExecSchedules(factory *cmdutil.Factory) {
logger.Debug("Exec Schedules")
schedules, err := readFileSchedule()
if err != nil {
logger.Debug("Error while reading the schedule", zap.Error(err))
return
}
}

scheds := []Schedule{}
for _, s := range schedules {
if CheckIf24HoursPassed(s.Time) {
if s.Kind == DELETE_BUCKET {
if err := TriggerDeleteBucket(factory, s.Name); err != nil {
logger.Debug("Event execution error", zap.Error(err))
scheds = append(scheds, s)
}
}
}
}

if err := createFileSchedule(scheds); err != nil {
logger.Debug("Scheduling error", zap.Error(err))
}
}

// CheckIf24HoursPassed Checks if the current time is before 24 hours after the time 's'.
Expand Down

0 comments on commit e6f3c47

Please sign in to comment.