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

fix: delete bucket #820

Merged
merged 4 commits into from
May 23, 2024
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
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
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...")
maxwelbm marked this conversation as resolved.
Show resolved Hide resolved
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
Loading