-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add s3 and gcs connection structs
- Loading branch information
1 parent
6d0a932
commit f09491a
Showing
6 changed files
with
138 additions
and
13 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 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,44 @@ | ||
package connection | ||
|
||
import ( | ||
"github.com/flanksource/duty/types" | ||
) | ||
|
||
// +kubebuilder:object:generate=true | ||
type GCSConnection struct { | ||
GCPConnection `json:",inline"` | ||
Bucket string `yaml:"bucket,omitempty" json:"bucket,omitempty"` | ||
} | ||
|
||
func (g *GCSConnection) Validate() *GCSConnection { | ||
if g == nil { | ||
return &GCSConnection{} | ||
} | ||
|
||
return g | ||
} | ||
|
||
// HydrateConnection attempts to find the connection by name | ||
// and populate the endpoint and credentials. | ||
func (g *GCSConnection) HydrateConnection(ctx ConnectionContext) error { | ||
connection, err := ctx.HydrateConnectionByURL(g.ConnectionName) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
if connection != nil { | ||
g.Credentials = &types.EnvVar{ValueStatic: connection.Certificate} | ||
g.Endpoint = connection.URL | ||
if val, ok := connection.Properties["bucket"]; ok { | ||
g.Bucket = val | ||
} | ||
} | ||
|
||
return nil | ||
} | ||
|
||
func (t *GCSConnection) GetProperties() map[string]string { | ||
return map[string]string{ | ||
"bucket": t.Bucket, | ||
} | ||
} |
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,60 @@ | ||
package connection | ||
|
||
import ( | ||
"fmt" | ||
"strconv" | ||
|
||
"github.com/flanksource/commons/collections" | ||
) | ||
|
||
// +kubebuilder:object:generate=true | ||
type S3Connection struct { | ||
AWSConnection `yaml:",inline"` | ||
Bucket string `yaml:"bucket,omitempty" json:"bucket,omitempty"` | ||
// glob path to restrict matches to a subset | ||
ObjectPath string `yaml:"objectPath,omitempty" json:"objectPath,omitempty"` | ||
// Use path style path: http://s3.amazonaws.com/BUCKET/KEY instead of http://BUCKET.s3.amazonaws.com/KEY | ||
UsePathStyle bool `yaml:"usePathStyle,omitempty" json:"usePathStyle,omitempty"` | ||
} | ||
|
||
func (t *S3Connection) GetProperties() map[string]string { | ||
return collections.MergeMap( | ||
t.AWSConnection.GetProperties(), | ||
map[string]string{ | ||
"bucket": t.Bucket, | ||
"objectPath": t.ObjectPath, | ||
"usePathStyle": strconv.FormatBool(t.UsePathStyle), | ||
}) | ||
} | ||
|
||
// Populate populates an AWSConnection with credentials and other information. | ||
// If a connection name is specified, it'll be used to populate the endpoint, accessKey and secretKey. | ||
func (t *S3Connection) Populate(ctx ConnectionContext) error { | ||
if err := t.AWSConnection.Populate(ctx); err != nil { | ||
return err | ||
} | ||
|
||
if t.ConnectionName != "" { | ||
connection, err := ctx.HydrateConnectionByURL(t.ConnectionName) | ||
if err != nil { | ||
return fmt.Errorf("could not parse EC2 access key: %v", err) | ||
} | ||
|
||
if region, ok := connection.Properties["bucket"]; ok { | ||
t.Bucket = region | ||
} | ||
|
||
if objectPath, ok := connection.Properties["objectPath"]; ok { | ||
t.ObjectPath = objectPath | ||
} | ||
|
||
if usePathStyle, ok := connection.Properties["usePathStyle"]; ok { | ||
if val, err := strconv.ParseBool(usePathStyle); err == nil { | ||
t.UsePathStyle = val | ||
} | ||
} | ||
|
||
} | ||
|
||
return nil | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
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