-
Notifications
You must be signed in to change notification settings - Fork 24
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Allow configuration of S3 archiving on a repository (#160)
* Allow configuration of S3 archiving on a repository * Add --enable-s3-archiving and --edisable-s3-archiving flags to the command validation
- Loading branch information
Showing
4 changed files
with
180 additions
and
12 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
package humiographql | ||
|
||
import ( | ||
"fmt" | ||
"strings" | ||
) | ||
|
||
type S3Configuration struct { | ||
Bucket string `graphql:"bucket"` | ||
Region string `graphql:"region"` | ||
Disabled bool `graphql:"disabled"` | ||
Format S3ArchivingFormat `graphql:"format"` | ||
} | ||
|
||
// IsEnabled - determine if S3Configuration is enabled based on values and the Disabled field | ||
// to avoid a bool defaulting to false | ||
func (s *S3Configuration) IsEnabled() bool { | ||
if s.IsConfigured() == false { | ||
Check failure on line 18 in api/internal/humiographql/s3-configuration.go GitHub Actions / build
|
||
return false | ||
} | ||
return !s.Disabled | ||
} | ||
|
||
func (s *S3Configuration) IsConfigured() bool { | ||
if s.Bucket != "" && s.Region != "" && s.Format != "" { | ||
return true | ||
} | ||
return false | ||
} | ||
|
||
// S3ArchivingFormat - the format in which to store the archived data on S3, either RAW or NDJSON | ||
type S3ArchivingFormat string | ||
|
||
const DefaultS3ArchivingFormat = S3ArchivingFormat("NDSON") | ||
|
||
var ValidS3ArchivingFormats = []S3ArchivingFormat{"NDJSON", "RAW"} | ||
|
||
// NewS3ArchivingFormat - creates a S3ArchivingFormat and ensures the value is uppercase | ||
func NewS3ArchivingFormat(format string) (S3ArchivingFormat, error) { | ||
f := S3ArchivingFormat(strings.ToUpper(string(format))) | ||
err := f.Validate() | ||
if err != nil { | ||
return "", err | ||
} | ||
return f, nil | ||
} | ||
|
||
func (f *S3ArchivingFormat) Validate() error { | ||
for _, v := range ValidS3ArchivingFormats { | ||
if v == *f { | ||
return nil | ||
} | ||
} | ||
return fmt.Errorf("invalid S3 archiving format. Valid formats: %s", ValidS3ArchivingFormats) | ||
} |
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
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