-
Notifications
You must be signed in to change notification settings - Fork 194
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by: Bird <aflybird0@gmail.com>
- Loading branch information
Showing
15 changed files
with
190 additions
and
139 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
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
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,13 @@ | ||
package s3_test | ||
|
||
import ( | ||
"testing" | ||
|
||
. "github.com/onsi/ginkgo/v2" | ||
. "github.com/onsi/gomega" | ||
) | ||
|
||
func TestS3(t *testing.T) { | ||
RegisterFailHandler(Fail) | ||
RunSpecs(t, "S3 Suite") | ||
} |
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,30 @@ | ||
package s3 | ||
|
||
import ( | ||
"fmt" | ||
|
||
"github.com/devstream-io/devstream/internal/pkg/backend/types" | ||
"github.com/devstream-io/devstream/pkg/util/log" | ||
) | ||
|
||
func validate(bucket, region, key string) error { | ||
var errs []error | ||
if bucket == "" { | ||
errs = append(errs, fmt.Errorf("state s3 Bucket is empty")) | ||
} | ||
if region == "" { | ||
errs = append(errs, fmt.Errorf("state s3 Region is empty")) | ||
} | ||
if key == "" { | ||
errs = append(errs, fmt.Errorf("state s3 Key is empty")) | ||
} | ||
|
||
if len(errs) > 0 { | ||
for _, err := range errs { | ||
log.Error(err) | ||
} | ||
return types.NewBackendOptionErr(types.S3) | ||
} | ||
|
||
return nil | ||
} |
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,25 @@ | ||
package s3 | ||
|
||
import ( | ||
. "github.com/onsi/ginkgo/v2" | ||
. "github.com/onsi/gomega" | ||
) | ||
|
||
var _ = Describe("Validate", func() { | ||
It("should return error s3 option not config", func() { | ||
err := validate("", "", "") | ||
Expect(err).Error().Should(HaveOccurred()) | ||
Expect(err.Error()).Should( | ||
ContainSubstring("invaid s3 sate config"), | ||
) | ||
}) | ||
|
||
It("should return true if config s3 valid", func() { | ||
bucket := "test_bucket" | ||
region := "test_region" | ||
key := "test_key" | ||
|
||
err := validate(bucket, region, key) | ||
Expect(err).Error().ShouldNot(HaveOccurred()) | ||
}) | ||
}) |
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,38 @@ | ||
package types | ||
|
||
import ( | ||
"errors" | ||
"fmt" | ||
) | ||
|
||
type backendOptionErr struct { | ||
backendType Type | ||
} | ||
|
||
func NewBackendOptionErr(typ Type) error { | ||
return backendOptionErr{backendType: typ} | ||
} | ||
|
||
func (err backendOptionErr) Error() string { | ||
return fmt.Sprintf("invaid %s sate config", err.backendType) | ||
} | ||
|
||
func IsBackendOptionErr(err error) bool { | ||
return errors.As(err, &backendOptionErr{}) | ||
} | ||
|
||
type invalidBackendErr struct { | ||
backendType string | ||
} | ||
|
||
func NewInvalidBackendErr(typ string) error { | ||
return invalidBackendErr{backendType: typ} | ||
} | ||
|
||
func (err invalidBackendErr) Error() string { | ||
return fmt.Sprintf("the backend type < %s > is illegal", err.backendType) | ||
} | ||
|
||
func IsInvalidBackendErr(err error) bool { | ||
return errors.As(err, &invalidBackendErr{}) | ||
} |
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,14 @@ | ||
package types | ||
|
||
type Type string | ||
|
||
func (t Type) String() string { | ||
return string(t) | ||
} | ||
|
||
const ( | ||
Local Type = "local" | ||
S3 Type = "s3" | ||
K8s Type = "k8s" | ||
K8sAlis Type = "kubernetes" | ||
) |
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
Oops, something went wrong.