-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #13 from MGTheTrain/feature/secure-file-storage
Feature/secure file storage
- Loading branch information
Showing
18 changed files
with
403 additions
and
248 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
package services | ||
|
||
type BlobUploadService struct { | ||
} | ||
type BlobMetadataService struct { | ||
} | ||
type BlobDownloadService struct { | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
package services | ||
|
||
type CryptKeyUploadService struct { | ||
} | ||
type CryptoKeyMetadataService struct { | ||
} | ||
type CryptoKeyDownloadService struct { | ||
} | ||
type CryptoKeyOperationService struct { | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,28 +1,30 @@ | ||
package blobs | ||
|
||
// BlobManagement defines methods for managing blob operations. | ||
type BlobManagement interface { | ||
// Upload handles the upload of blobs from file paths. | ||
// Returns the created Blobs metadata and any error encountered. | ||
Upload(filePath []string) ([]*Blob, error) | ||
// BlobUploadService defines methods for uploading blobs. | ||
type BlobUploadService interface { | ||
// Upload handles the upload of blobs from the specified file paths. | ||
// It returns a slice of Blob for the uploaded blobs and any error encountered during the upload process. | ||
Upload(filePaths []string) ([]*BlobMeta, error) | ||
} | ||
|
||
// Download retrieves a blob by its ID and name, returning the metadata and file data. | ||
// Returns the Blob metadata, file data as a byte slice, and any error. | ||
Download(blobId, blobName string) (*Blob, []byte, error) | ||
// BlobMetadataService defines methods for retrieving Blob and deleting a blob along with its metadata. | ||
type BlobMetadataService interface { | ||
// List retrieves all blobs' metadata considering a query filter when set. | ||
// It returns a slice of Blob and any error encountered during the retrieval. | ||
List(query *BlobMetaQuery) ([]*BlobMeta, error) | ||
|
||
// DeleteByID removes a blob by its ID. | ||
// Returns any error encountered. | ||
DeleteByID(blobId string) error | ||
} | ||
// GetByID retrieves the metadata of a blob by its unique ID. | ||
// It returns the Blob and any error encountered during the retrieval process. | ||
GetByID(blobID string) (*BlobMeta, error) | ||
|
||
// BlobMetadataManagement defines the methods for managing Blob metadata | ||
type BlobMetadataManagement interface { | ||
// Create creates a new blob | ||
Create(blob *Blob) (*Blob, error) | ||
// GetByID retrieves blob by ID | ||
GetByID(blobID string) (*Blob, error) | ||
// UpdateByID updates a blob's metadata | ||
UpdateByID(blobID string, updates *Blob) (*Blob, error) | ||
// DeleteByID deletes a blob by ID | ||
// DeleteByID deletes a blob and its associated metadata by ID. | ||
// It returns any error encountered during the deletion process. | ||
DeleteByID(blobID string) error | ||
} | ||
|
||
// BlobDownloadService defines methods for downloading blobs. | ||
type BlobDownloadService interface { | ||
// Download retrieves a blob by its ID and name. | ||
// It returns the Blob, the file data as a byte slice, and any error encountered during the download process. | ||
Download(blobID, blobName string) (*BlobMeta, []byte, error) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
package blobs | ||
|
||
import ( | ||
"fmt" | ||
"time" | ||
|
||
"github.com/go-playground/validator/v10" | ||
) | ||
|
||
// BlobMetaQuery represents metadata on the actual blob being stored. | ||
type BlobMetaQuery struct { | ||
UploadTime time.Time `validate:"required"` // UploadTime is required | ||
Name string `validate:"required,min=1,max=255"` // Name is required and its length must be between 1 and 255 characters | ||
Size int64 `validate:"required,min=1"` // Size must be greater than 0 | ||
Type string `validate:"required,min=1,max=50"` // Type is required, and its length must be between 1 and 50 characters | ||
|
||
// Pagination properties | ||
Limit int `validate:"omitempty,min=1"` // Limit is optional but if provided, should be at least 1 | ||
Offset int `validate:"omitempty,min=0"` // Offset is optional but should be 0 or greater for pagination | ||
|
||
// Sorting properties | ||
SortBy string `validate:"omitempty,oneof=ID Type CreatedAt ExpiresAt"` // SortBy is optional but can be one of the fields to sort by | ||
SortOrder string `validate:"omitempty,oneof=asc desc"` // SortOrder is optional, default is ascending ('asc'), can also be 'desc' | ||
} | ||
|
||
// NewBlobMetaQuery creates a BlobMetaQuery with default values. | ||
func NewBlobMetaQuery() *BlobMetaQuery { | ||
return &BlobMetaQuery{ | ||
Limit: 10, // Default limit to 10 results per page | ||
Offset: 0, // Default offset to 0 for pagination | ||
SortBy: "CreatedAt", // Default sort by CreatedAt | ||
SortOrder: "asc", // Default sort order ascending | ||
} | ||
} | ||
|
||
// Validate validates the BlobMetaQuery struct based on the defined rules. | ||
func (b *BlobMetaQuery) Validate() error { | ||
// Initialize the validator | ||
validate := validator.New() | ||
|
||
// Validate the struct fields | ||
err := validate.Struct(b) | ||
if err != nil { | ||
// Collect all validation errors | ||
var validationErrors []string | ||
for _, err := range err.(validator.ValidationErrors) { | ||
validationErrors = append(validationErrors, fmt.Sprintf("Field: %s, Tag: %s", err.Field(), err.Tag())) | ||
} | ||
return fmt.Errorf("Validation failed: %v", validationErrors) | ||
} | ||
|
||
// Custom validation logic: Check that ExpiresAt (if exists) is after CreatedAt | ||
if !b.UploadTime.IsZero() && b.UploadTime.After(time.Now()) { | ||
return fmt.Errorf("UploadTime cannot be in the future") | ||
} | ||
|
||
// Return nil if no validation errors are found | ||
return nil | ||
} |
Oops, something went wrong.