Skip to content
Draft
Show file tree
Hide file tree
Changes from all 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
15 changes: 11 additions & 4 deletions cmd/storage.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,15 +60,19 @@ func init() {
return []cobra.Completion{http.MethodGet, http.MethodPut, http.MethodDelete}, cobra.ShellCompDirectiveDefault
})

runner.RegisterHook("auto-content-type", guessContentType)
storageCmd.PersistentFlags().Bool("no-auto-content-type", false, "Disable automatic content-type detection")
}

func callOOS(cmd *cobra.Command, args []string) {
debug.Println(cmd.Name() + " called")
p := loadProfile(cmd)
cl, err := oos.NewClient(cmd.Context(), p, awsOptions(cmd)...)
if err == nil {
err = runner.Run[*oos.Client, oos.Error](cmd, args, cl, config.For("storage"))
var hooks []runner.Hook
if noAuto, _ := cmd.Flags().GetBool("no-auto-content-type"); !noAuto {
hooks = []runner.Hook{guessContentType}
}
err = runner.Run[*oos.Client, oos.Error](cmd, args, cl, config.For("storage"), hooks...)
}
if err != nil {
_ = flags.CloseAll(cmd.Flags())
Expand Down Expand Up @@ -123,6 +127,8 @@ func presign(cmd *cobra.Command, args []string) {
_, _ = fmt.Fprint(os.Stdout, req.URL)
}

const detectionBufferSize = 32 * 1024

func guessContentType(arg reflect.Value) {
if !arg.CanInterface() {
return
Expand All @@ -136,7 +142,7 @@ func guessContentType(arg reflect.Value) {
messages.Info("cannot compute content-type")
return
}
body, err := io.ReadAll(io.LimitReader(seeker, 200))
body, err := io.ReadAll(io.LimitReader(seeker, detectionBufferSize))
if err != nil {
_, _ = seeker.Seek(0, io.SeekStart) // in case something was read...
messages.Info("cannot compute content-type: %v", err)
Expand All @@ -147,8 +153,9 @@ func guessContentType(arg reflect.Value) {
messages.ExitErr(fmt.Errorf("cannot compute content-type: %w", err))
return
}
mimetype.SetLimit(detectionBufferSize)
mime := mimetype.Detect(body)
messages.Info("detected mime-type: %s", mime.String())
messages.Info("Detected mime-type: %s", mime.String())
po.ContentType = new(mime.String())
}
}
3 changes: 2 additions & 1 deletion docs/reference/octl_storage.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@ OUTSCALE Object Storage (OOS) management
### Options

```
-h, --help help for storage
-h, --help help for storage
--no-auto-content-type Disable automatic content-type detection
```

### Options inherited from parent commands
Expand Down
1 change: 1 addition & 0 deletions docs/reference/octl_storage_api.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ storage api calls
--interval duration interval between two watch/waitfor iterations (default 5s)
--jq string jq filter
--max-pages int maximum number of pages a command can fetch (default 20)
--no-auto-content-type Disable automatic content-type detection
--no-upgrade do not check for new versions
-O, --out-file string redirect output to file
-o, --output string output format (raw, json, yaml, table, csv, none, base64, text)
Expand Down
1 change: 1 addition & 0 deletions docs/reference/octl_storage_api_AbortMultipartUpload.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ octl storage api AbortMultipartUpload [flags]
--interval duration interval between two watch/waitfor iterations (default 5s)
--jq string jq filter
--max-pages int maximum number of pages a command can fetch (default 20)
--no-auto-content-type Disable automatic content-type detection
--no-upgrade do not check for new versions
-O, --out-file string redirect output to file
-o, --output string output format (raw, json, yaml, table, csv, none, base64, text)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ octl storage api CompleteMultipartUpload [flags]
--interval duration interval between two watch/waitfor iterations (default 5s)
--jq string jq filter
--max-pages int maximum number of pages a command can fetch (default 20)
--no-auto-content-type Disable automatic content-type detection
--no-upgrade do not check for new versions
-O, --out-file string redirect output to file
-o, --output string output format (raw, json, yaml, table, csv, none, base64, text)
Expand Down
1 change: 1 addition & 0 deletions docs/reference/octl_storage_api_CopyObject.md
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ octl storage api CopyObject [flags]
--interval duration interval between two watch/waitfor iterations (default 5s)
--jq string jq filter
--max-pages int maximum number of pages a command can fetch (default 20)
--no-auto-content-type Disable automatic content-type detection
--no-upgrade do not check for new versions
-O, --out-file string redirect output to file
-o, --output string output format (raw, json, yaml, table, csv, none, base64, text)
Expand Down
1 change: 1 addition & 0 deletions docs/reference/octl_storage_api_CreateBucket.md
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ octl storage api CreateBucket [flags]
--interval duration interval between two watch/waitfor iterations (default 5s)
--jq string jq filter
--max-pages int maximum number of pages a command can fetch (default 20)
--no-auto-content-type Disable automatic content-type detection
--no-upgrade do not check for new versions
-O, --out-file string redirect output to file
-o, --output string output format (raw, json, yaml, table, csv, none, base64, text)
Expand Down
1 change: 1 addition & 0 deletions docs/reference/octl_storage_api_CreateMultipartUpload.md
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ octl storage api CreateMultipartUpload [flags]
--interval duration interval between two watch/waitfor iterations (default 5s)
--jq string jq filter
--max-pages int maximum number of pages a command can fetch (default 20)
--no-auto-content-type Disable automatic content-type detection
--no-upgrade do not check for new versions
-O, --out-file string redirect output to file
-o, --output string output format (raw, json, yaml, table, csv, none, base64, text)
Expand Down
1 change: 1 addition & 0 deletions docs/reference/octl_storage_api_DeleteBucket.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ octl storage api DeleteBucket [flags]
--interval duration interval between two watch/waitfor iterations (default 5s)
--jq string jq filter
--max-pages int maximum number of pages a command can fetch (default 20)
--no-auto-content-type Disable automatic content-type detection
--no-upgrade do not check for new versions
-O, --out-file string redirect output to file
-o, --output string output format (raw, json, yaml, table, csv, none, base64, text)
Expand Down
1 change: 1 addition & 0 deletions docs/reference/octl_storage_api_DeleteBucketCors.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ octl storage api DeleteBucketCors [flags]
--interval duration interval between two watch/waitfor iterations (default 5s)
--jq string jq filter
--max-pages int maximum number of pages a command can fetch (default 20)
--no-auto-content-type Disable automatic content-type detection
--no-upgrade do not check for new versions
-O, --out-file string redirect output to file
-o, --output string output format (raw, json, yaml, table, csv, none, base64, text)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ octl storage api DeleteBucketEncryption [flags]
--interval duration interval between two watch/waitfor iterations (default 5s)
--jq string jq filter
--max-pages int maximum number of pages a command can fetch (default 20)
--no-auto-content-type Disable automatic content-type detection
--no-upgrade do not check for new versions
-O, --out-file string redirect output to file
-o, --output string output format (raw, json, yaml, table, csv, none, base64, text)
Expand Down
1 change: 1 addition & 0 deletions docs/reference/octl_storage_api_DeleteBucketLifecycle.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ octl storage api DeleteBucketLifecycle [flags]
--interval duration interval between two watch/waitfor iterations (default 5s)
--jq string jq filter
--max-pages int maximum number of pages a command can fetch (default 20)
--no-auto-content-type Disable automatic content-type detection
--no-upgrade do not check for new versions
-O, --out-file string redirect output to file
-o, --output string output format (raw, json, yaml, table, csv, none, base64, text)
Expand Down
1 change: 1 addition & 0 deletions docs/reference/octl_storage_api_DeleteBucketPolicy.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ octl storage api DeleteBucketPolicy [flags]
--interval duration interval between two watch/waitfor iterations (default 5s)
--jq string jq filter
--max-pages int maximum number of pages a command can fetch (default 20)
--no-auto-content-type Disable automatic content-type detection
--no-upgrade do not check for new versions
-O, --out-file string redirect output to file
-o, --output string output format (raw, json, yaml, table, csv, none, base64, text)
Expand Down
1 change: 1 addition & 0 deletions docs/reference/octl_storage_api_DeleteBucketWebsite.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ octl storage api DeleteBucketWebsite [flags]
--interval duration interval between two watch/waitfor iterations (default 5s)
--jq string jq filter
--max-pages int maximum number of pages a command can fetch (default 20)
--no-auto-content-type Disable automatic content-type detection
--no-upgrade do not check for new versions
-O, --out-file string redirect output to file
-o, --output string output format (raw, json, yaml, table, csv, none, base64, text)
Expand Down
1 change: 1 addition & 0 deletions docs/reference/octl_storage_api_DeleteObject.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ octl storage api DeleteObject [flags]
--interval duration interval between two watch/waitfor iterations (default 5s)
--jq string jq filter
--max-pages int maximum number of pages a command can fetch (default 20)
--no-auto-content-type Disable automatic content-type detection
--no-upgrade do not check for new versions
-O, --out-file string redirect output to file
-o, --output string output format (raw, json, yaml, table, csv, none, base64, text)
Expand Down
1 change: 1 addition & 0 deletions docs/reference/octl_storage_api_DeleteObjectTagging.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ octl storage api DeleteObjectTagging [flags]
--interval duration interval between two watch/waitfor iterations (default 5s)
--jq string jq filter
--max-pages int maximum number of pages a command can fetch (default 20)
--no-auto-content-type Disable automatic content-type detection
--no-upgrade do not check for new versions
-O, --out-file string redirect output to file
-o, --output string output format (raw, json, yaml, table, csv, none, base64, text)
Expand Down
1 change: 1 addition & 0 deletions docs/reference/octl_storage_api_GetBucketAcl.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ octl storage api GetBucketAcl [flags]
--interval duration interval between two watch/waitfor iterations (default 5s)
--jq string jq filter
--max-pages int maximum number of pages a command can fetch (default 20)
--no-auto-content-type Disable automatic content-type detection
--no-upgrade do not check for new versions
-O, --out-file string redirect output to file
-o, --output string output format (raw, json, yaml, table, csv, none, base64, text)
Expand Down
1 change: 1 addition & 0 deletions docs/reference/octl_storage_api_GetBucketCors.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ octl storage api GetBucketCors [flags]
--interval duration interval between two watch/waitfor iterations (default 5s)
--jq string jq filter
--max-pages int maximum number of pages a command can fetch (default 20)
--no-auto-content-type Disable automatic content-type detection
--no-upgrade do not check for new versions
-O, --out-file string redirect output to file
-o, --output string output format (raw, json, yaml, table, csv, none, base64, text)
Expand Down
1 change: 1 addition & 0 deletions docs/reference/octl_storage_api_GetBucketEncryption.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ octl storage api GetBucketEncryption [flags]
--interval duration interval between two watch/waitfor iterations (default 5s)
--jq string jq filter
--max-pages int maximum number of pages a command can fetch (default 20)
--no-auto-content-type Disable automatic content-type detection
--no-upgrade do not check for new versions
-O, --out-file string redirect output to file
-o, --output string output format (raw, json, yaml, table, csv, none, base64, text)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ octl storage api GetBucketLifecycleConfiguration [flags]
--interval duration interval between two watch/waitfor iterations (default 5s)
--jq string jq filter
--max-pages int maximum number of pages a command can fetch (default 20)
--no-auto-content-type Disable automatic content-type detection
--no-upgrade do not check for new versions
-O, --out-file string redirect output to file
-o, --output string output format (raw, json, yaml, table, csv, none, base64, text)
Expand Down
1 change: 1 addition & 0 deletions docs/reference/octl_storage_api_GetBucketLocation.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ octl storage api GetBucketLocation [flags]
--interval duration interval between two watch/waitfor iterations (default 5s)
--jq string jq filter
--max-pages int maximum number of pages a command can fetch (default 20)
--no-auto-content-type Disable automatic content-type detection
--no-upgrade do not check for new versions
-O, --out-file string redirect output to file
-o, --output string output format (raw, json, yaml, table, csv, none, base64, text)
Expand Down
1 change: 1 addition & 0 deletions docs/reference/octl_storage_api_GetBucketPolicy.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ octl storage api GetBucketPolicy [flags]
--interval duration interval between two watch/waitfor iterations (default 5s)
--jq string jq filter
--max-pages int maximum number of pages a command can fetch (default 20)
--no-auto-content-type Disable automatic content-type detection
--no-upgrade do not check for new versions
-O, --out-file string redirect output to file
-o, --output string output format (raw, json, yaml, table, csv, none, base64, text)
Expand Down
1 change: 1 addition & 0 deletions docs/reference/octl_storage_api_GetBucketVersioning.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ octl storage api GetBucketVersioning [flags]
--interval duration interval between two watch/waitfor iterations (default 5s)
--jq string jq filter
--max-pages int maximum number of pages a command can fetch (default 20)
--no-auto-content-type Disable automatic content-type detection
--no-upgrade do not check for new versions
-O, --out-file string redirect output to file
-o, --output string output format (raw, json, yaml, table, csv, none, base64, text)
Expand Down
1 change: 1 addition & 0 deletions docs/reference/octl_storage_api_GetBucketWebsite.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ octl storage api GetBucketWebsite [flags]
--interval duration interval between two watch/waitfor iterations (default 5s)
--jq string jq filter
--max-pages int maximum number of pages a command can fetch (default 20)
--no-auto-content-type Disable automatic content-type detection
--no-upgrade do not check for new versions
-O, --out-file string redirect output to file
-o, --output string output format (raw, json, yaml, table, csv, none, base64, text)
Expand Down
1 change: 1 addition & 0 deletions docs/reference/octl_storage_api_GetObject.md
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ octl storage api GetObject [flags]
--interval duration interval between two watch/waitfor iterations (default 5s)
--jq string jq filter
--max-pages int maximum number of pages a command can fetch (default 20)
--no-auto-content-type Disable automatic content-type detection
--no-upgrade do not check for new versions
-O, --out-file string redirect output to file
-o, --output string output format (raw, json, yaml, table, csv, none, base64, text)
Expand Down
1 change: 1 addition & 0 deletions docs/reference/octl_storage_api_GetObjectAcl.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ octl storage api GetObjectAcl [flags]
--interval duration interval between two watch/waitfor iterations (default 5s)
--jq string jq filter
--max-pages int maximum number of pages a command can fetch (default 20)
--no-auto-content-type Disable automatic content-type detection
--no-upgrade do not check for new versions
-O, --out-file string redirect output to file
-o, --output string output format (raw, json, yaml, table, csv, none, base64, text)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ octl storage api GetObjectLockConfiguration [flags]
--interval duration interval between two watch/waitfor iterations (default 5s)
--jq string jq filter
--max-pages int maximum number of pages a command can fetch (default 20)
--no-auto-content-type Disable automatic content-type detection
--no-upgrade do not check for new versions
-O, --out-file string redirect output to file
-o, --output string output format (raw, json, yaml, table, csv, none, base64, text)
Expand Down
1 change: 1 addition & 0 deletions docs/reference/octl_storage_api_GetObjectRetention.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ octl storage api GetObjectRetention [flags]
--interval duration interval between two watch/waitfor iterations (default 5s)
--jq string jq filter
--max-pages int maximum number of pages a command can fetch (default 20)
--no-auto-content-type Disable automatic content-type detection
--no-upgrade do not check for new versions
-O, --out-file string redirect output to file
-o, --output string output format (raw, json, yaml, table, csv, none, base64, text)
Expand Down
1 change: 1 addition & 0 deletions docs/reference/octl_storage_api_GetObjectTagging.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ octl storage api GetObjectTagging [flags]
--interval duration interval between two watch/waitfor iterations (default 5s)
--jq string jq filter
--max-pages int maximum number of pages a command can fetch (default 20)
--no-auto-content-type Disable automatic content-type detection
--no-upgrade do not check for new versions
-O, --out-file string redirect output to file
-o, --output string output format (raw, json, yaml, table, csv, none, base64, text)
Expand Down
1 change: 1 addition & 0 deletions docs/reference/octl_storage_api_HeadBucket.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ octl storage api HeadBucket [flags]
--interval duration interval between two watch/waitfor iterations (default 5s)
--jq string jq filter
--max-pages int maximum number of pages a command can fetch (default 20)
--no-auto-content-type Disable automatic content-type detection
--no-upgrade do not check for new versions
-O, --out-file string redirect output to file
-o, --output string output format (raw, json, yaml, table, csv, none, base64, text)
Expand Down
1 change: 1 addition & 0 deletions docs/reference/octl_storage_api_HeadObject.md
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ octl storage api HeadObject [flags]
--interval duration interval between two watch/waitfor iterations (default 5s)
--jq string jq filter
--max-pages int maximum number of pages a command can fetch (default 20)
--no-auto-content-type Disable automatic content-type detection
--no-upgrade do not check for new versions
-O, --out-file string redirect output to file
-o, --output string output format (raw, json, yaml, table, csv, none, base64, text)
Expand Down
1 change: 1 addition & 0 deletions docs/reference/octl_storage_api_ListBuckets.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ octl storage api ListBuckets [flags]
--interval duration interval between two watch/waitfor iterations (default 5s)
--jq string jq filter
--max-pages int maximum number of pages a command can fetch (default 20)
--no-auto-content-type Disable automatic content-type detection
--no-upgrade do not check for new versions
-O, --out-file string redirect output to file
-o, --output string output format (raw, json, yaml, table, csv, none, base64, text)
Expand Down
Loading