mirror of
https://github.com/Luzifer/ots.git
synced 2024-12-17 19:44:36 -05:00
[#154] Improve UX for rejected / allowed files
Signed-off-by: Knut Ahlers <knut@ahlers.me>
This commit is contained in:
parent
dc47bf0861
commit
3ebc896169
@ -45,6 +45,8 @@ func init() {
|
||||
}
|
||||
|
||||
func createRunE(cmd *cobra.Command, _ []string) (err error) {
|
||||
cmd.SilenceUsage = true
|
||||
|
||||
var secret client.Secret
|
||||
|
||||
if client.HTTPClient, err = constructHTTPClient(cmd); err != nil {
|
||||
|
@ -16,7 +16,7 @@ import (
|
||||
const storeFileMode = 0o600 // We assume the attached file to be a secret
|
||||
|
||||
var fetchCmd = &cobra.Command{
|
||||
Use: "fetch url",
|
||||
Use: "fetch <url>",
|
||||
Short: "Retrieves a secret from the instance by its URL",
|
||||
Long: "",
|
||||
Args: cobra.ExactArgs(1),
|
||||
@ -39,6 +39,8 @@ func checkDirWritable(dir string) error {
|
||||
}
|
||||
|
||||
func fetchRunE(cmd *cobra.Command, args []string) error {
|
||||
cmd.SilenceUsage = true
|
||||
|
||||
fileDir, err := cmd.Flags().GetString("file-dir")
|
||||
if err != nil {
|
||||
return fmt.Errorf("getting file-dir parameter: %w", err)
|
||||
|
@ -73,12 +73,15 @@ func SanityCheck(instanceURL string, secret Secret) error {
|
||||
|
||||
func attachmentAllowed(file SecretAttachment, allowed []string) bool {
|
||||
mimeType, _, _ := strings.Cut(file.Type, ";")
|
||||
logger := Logger.WithField("content-type", mimeType)
|
||||
|
||||
for _, a := range allowed {
|
||||
switch {
|
||||
case mimeRegex.MatchString(a):
|
||||
// That's a mime type
|
||||
if glob.Glob(a, mimeType) {
|
||||
// The mime "glob" matches the file type
|
||||
logger.WithField("allowed_by", a).Debug("attachment allowed")
|
||||
return true
|
||||
}
|
||||
|
||||
@ -86,12 +89,13 @@ func attachmentAllowed(file SecretAttachment, allowed []string) bool {
|
||||
// That's a file extension
|
||||
if strings.HasSuffix(file.Name, a) {
|
||||
// The filename has the right extension
|
||||
logger.WithField("allowed_by", a).Debug("attachment allowed")
|
||||
return true
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Logger.WithField("content-type", mimeType).Debug("attachment type not allowed")
|
||||
logger.Debug("attachment type not allowed")
|
||||
return false
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user