Skip to content

Commit

Permalink
feat: git auth type (#127)
Browse files Browse the repository at this point in the history
* feat: git auth type

* fix: add enums

* fix: client

* fix: unit test

* fix: strict type for enum

* feat: test trigger types

* feat: test trigger types

* fix: enum typo

* fix: test trigger type usage

* fix: spelling
  • Loading branch information
vsukhin authored Mar 29, 2023
1 parent 3ccbf30 commit ecf1391
Show file tree
Hide file tree
Showing 21 changed files with 293 additions and 65 deletions.
10 changes: 9 additions & 1 deletion apis/executor/v1/executor_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ type ExecutorSpec struct {

// ExecutorType one of "rest" for rest openapi based executors or "job" which will be default runners for testkube
// or "container" for container executors
ExecutorType string `json:"executor_type,omitempty"`
ExecutorType ExecutorType `json:"executor_type,omitempty"`

// URI for rest based executors
URI string `json:"uri,omitempty"`
Expand Down Expand Up @@ -68,6 +68,14 @@ const (
FeatureJUnitReport Feature = "junit-report"
)

// +kubebuilder:validation:Enum=job;container
type ExecutorType string

const (
ExecutorTypeJob ExecutorType = "job"
ExecutorTypeContainer ExecutorType = "container"
)

// +kubebuilder:validation:Enum=string;file-uri;git-file;git-dir;git
type ScriptContentType string

Expand Down
19 changes: 18 additions & 1 deletion apis/executor/v1/webhook_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,13 +31,30 @@ type WebhookSpec struct {
// Uri is address where webhook should be made
Uri string `json:"uri,omitempty"`
// Events declare list if events on which webhook should be called
Events []string `json:"events,omitempty"`
Events []EventType `json:"events,omitempty"`
// Labels to filter for tests and test suites
Selector string `json:"selector,omitempty"`
// will load the generated payload for notification inside the object
PayloadObjectField string `json:"payloadObjectField,omitempty"`
}

// +kubebuilder:validation:Enum=start-test;end-test-success;end-test-failed;end-test-aborted;end-test-timeout;start-testsuite;end-testsuite-success;end-testsuite-failed;end-testsuite-aborted;end-testsuite-timeout
type EventType string

// List of EventType
const (
START_TEST_EventType EventType = "start-test"
END_TEST_SUCCESS_EventType EventType = "end-test-success"
END_TEST_FAILED_EventType EventType = "end-test-failed"
END_TEST_ABORTED_EventType EventType = "end-test-aborted"
END_TEST_TIMEOUT_EventType EventType = "end-test-timeout"
START_TESTSUITE_EventType EventType = "start-testsuite"
END_TESTSUITE_SUCCESS_EventType EventType = "end-testsuite-success"
END_TESTSUITE_FAILED_EventType EventType = "end-testsuite-failed"
END_TESTSUITE_ABORTED_EventType EventType = "end-testsuite-aborted"
END_TESTSUITE_TIMEOUT_EventType EventType = "end-testsuite-timeout"
)

// WebhookStatus defines the observed state of Webhook
type WebhookStatus struct {
// INSERT ADDITIONAL STATUS FIELD - define observed state of cluster
Expand Down
2 changes: 1 addition & 1 deletion apis/executor/v1/zz_generated.deepcopy.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions apis/tests/v3/test_conversion.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ func (src *Test) ConvertTo(dstRaw conversion.Hub) error {
if src.Spec.Content != nil {
dst.Spec.Content = &testkubev2.TestContent{
Data: src.Spec.Content.Data,
Type_: src.Spec.Content.Type_,
Type_: string(src.Spec.Content.Type_),
Uri: src.Spec.Content.Uri,
}
}
Expand Down Expand Up @@ -112,7 +112,7 @@ func (dst *Test) ConvertFrom(srcRaw conversion.Hub) error {
if src.Spec.Content != nil {
dst.Spec.Content = &TestContent{
Data: src.Spec.Content.Data,
Type_: src.Spec.Content.Type_,
Type_: TestContentType(src.Spec.Content.Type_),
Uri: src.Spec.Content.Uri,
}
}
Expand Down
62 changes: 45 additions & 17 deletions apis/tests/v3/test_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ type Variable commonv1.Variable
// TestContent defines test content
type TestContent struct {
// test type
Type_ string `json:"type,omitempty"`
Type_ TestContentType `json:"type,omitempty"`
// repository of test content
Repository *Repository `json:"repository,omitempty"`
// test content body
Expand All @@ -59,6 +59,19 @@ type TestContent struct {
Uri string `json:"uri,omitempty"`
}

// +kubebuilder:validation:Enum=string;file-uri;git-file;git-dir;git
type TestContentType string

const (
TestContentTypeString TestContentType = "string"
TestContentTypeFileURI TestContentType = "file-uri"
// Deprecated: use git instead
TestContentTypeGitFile TestContentType = "git-file"
// Deprecated: use git instead
TestContentTypeGitDir TestContentType = "git-dir"
TestContentTypeGit TestContentType = "git"
)

// Testkube internal reference for secret storage in Kubernetes secrets
type SecretRef struct {
// object kubernetes namespace
Expand All @@ -80,14 +93,28 @@ type Repository struct {
// commit id (sha) for checkout
Commit string `json:"commit,omitempty"`
// if needed we can checkout particular path (dir or file) in case of BIG/mono repositories
Path string `json:"path,omitempty"`
UsernameSecret *SecretRef `json:"usernameSecret,omitempty"`
TokenSecret *SecretRef `json:"tokenSecret,omitempty"`
CertificateSecret string `json:"certificateSecret,omitempty"`
Path string `json:"path,omitempty"`
UsernameSecret *SecretRef `json:"usernameSecret,omitempty"`
TokenSecret *SecretRef `json:"tokenSecret,omitempty"`
// git auth certificate secret for private repositories
CertificateSecret string `json:"certificateSecret,omitempty"`
// if provided we checkout the whole repository and run test from this directory
WorkingDir string `json:"workingDir,omitempty"`
// auth type for git requests
AuthType GitAuthType `json:"authType,omitempty"`
}

// GitAuthType defines git auth type
// +kubebuilder:validation:Enum=basic;header
type GitAuthType string

const (
// GitAuthTypeBasic for git basic auth requests
GitAuthTypeBasic GitAuthType = "basic"
// GitAuthTypeHeader for git header auth requests
GitAuthTypeHeader GitAuthType = "header"
)

// artifact request body for container executors with test artifacts
type ArtifactRequest struct {
// artifact storage class name
Expand All @@ -101,11 +128,22 @@ type ArtifactRequest struct {
// running context for test or test suite execution
type RunningContext struct {
// One of possible context types
Type_ string `json:"type"`
Type_ RunningContextType `json:"type"`
// Context value depending from its type
Context string `json:"context,omitempty"`
}

type RunningContextType string

const (
RunningContextTypeUserCLI RunningContextType = "user-cli"
RunningContextTypeUserUI RunningContextType = "user-ui"
RunningContextTypeTestSuite RunningContextType = "testsuite"
RunningContextTypeTestTrigger RunningContextType = "testtrigger"
RunningContextTypeScheduler RunningContextType = "scheduler"
RunningContextTypeEmpty RunningContextType = ""
)

// test execution request body
type ExecutionRequest struct {
// test execution custom name
Expand Down Expand Up @@ -165,17 +203,6 @@ type ExecutionRequest struct {
RunningContext *RunningContext `json:"runningContext,omitempty"`
}

type RunningContextType string

const (
RunningContextTypeUserCLI RunningContextType = "user-cli"
RunningContextTypeUserUI RunningContextType = "user-ui"
RunningContextTypeTestSuite RunningContextType = "testsuite"
RunningContextTypeTestTrigger RunningContextType = "testtrigger"
RunningContextTypeScheduler RunningContextType = "scheduler"
RunningContextTypeEmpty RunningContextType = ""
)

// Reference to env resource
type EnvReference struct {
v1.LocalObjectReference `json:"reference"`
Expand All @@ -187,6 +214,7 @@ type EnvReference struct {
MapToVariables bool `json:"mapToVariables,omitempty"`
}

// +kubebuilder:validation:Enum=queued;running;passed;failed;aborted;timeout
type ExecutionStatus string

// List of ExecutionStatus
Expand Down
37 changes: 32 additions & 5 deletions apis/testsource/v1/testsource_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ type TestSourceSpec struct {
// INSERT ADDITIONAL SPEC FIELDS - desired state of cluster
// Important: Run "make" to regenerate code after modifying this file

Type_ string `json:"type,omitempty"`
Type_ TestSourceType `json:"type,omitempty"`
// repository of test content
Repository *Repository `json:"repository,omitempty"`
// test content body
Expand All @@ -37,6 +37,19 @@ type TestSourceSpec struct {
Uri string `json:"uri,omitempty"`
}

// +kubebuilder:validation:Enum=string;file-uri;git-file;git-dir;git
type TestSourceType string

const (
TestSourceTypeString TestSourceType = "string"
TestSourceTypeFileURI TestSourceType = "file-uri"
// Deprecated: use git instead
TestSourceTypeGitFile TestSourceType = "git-file"
// Deprecated: use git instead
TestSourceTypeGitDir TestSourceType = "git-dir"
TestSourceTypeGit TestSourceType = "git"
)

// Testkube internal reference for secret storage in Kubernetes secrets
type SecretRef struct {
// object kubernetes namespace
Expand All @@ -58,14 +71,28 @@ type Repository struct {
// commit id (sha) for checkout
Commit string `json:"commit,omitempty"`
// if needed we can checkout particular path (dir or file) in case of BIG/mono repositories
Path string `json:"path,omitempty"`
UsernameSecret *SecretRef `json:"usernameSecret,omitempty"`
TokenSecret *SecretRef `json:"tokenSecret,omitempty"`
CertificateSecret string `json:"certificateSecret,omitempty"`
Path string `json:"path,omitempty"`
UsernameSecret *SecretRef `json:"usernameSecret,omitempty"`
TokenSecret *SecretRef `json:"tokenSecret,omitempty"`
// git auth certificate secret for private repositories
CertificateSecret string `json:"certificateSecret,omitempty"`
// if provided we checkout the whole repository and run test from this directory
WorkingDir string `json:"workingDir,omitempty"`
// auth type for git requests
AuthType GitAuthType `json:"authType,omitempty"`
}

// GitAuthType defines git auth type
// +kubebuilder:validation:Enum=basic;header
type GitAuthType string

const (
// GitAuthTypeBasic for git basic auth requests
GitAuthTypeBasic GitAuthType = "basic"
// GitAuthTypeHeader for git header auth requests
GitAuthTypeHeader GitAuthType = "header"
)

// TestSourceStatus defines the observed state of TestSource
type TestSourceStatus struct {
// INSERT ADDITIONAL STATUS FIELD - define observed state of cluster
Expand Down
2 changes: 1 addition & 1 deletion apis/testsuite/v1/testsuite_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ type TestSuiteStepSpec struct {
Delay *TestSuiteStepDelay `json:"delay,omitempty"`
}

// TestSuiteStepType deines different type of test suite steps
// TestSuiteStepType defines different type of test suite steps
type TestSuiteStepType string

const (
Expand Down
4 changes: 2 additions & 2 deletions apis/testsuite/v2/testsuite_conversion.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ func (src *TestSuite) ConvertTo(dstRaw conversion.Hub) error {
for i := range stepType.Source {
value := stepType.Source[i]
step := testkubev1.TestSuiteStepSpec{
Type: value.Type,
Type: string(value.Type),
}

if value.Delay != nil {
Expand Down Expand Up @@ -132,7 +132,7 @@ func (dst *TestSuite) ConvertFrom(srcRaw conversion.Hub) error {
for i := range stepType.source {
value := stepType.source[i]
step := TestSuiteStepSpec{
Type: value.Type,
Type: TestSuiteStepType(value.Type),
}

if value.Delay != nil {
Expand Down
30 changes: 16 additions & 14 deletions apis/testsuite/v2/testsuite_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,12 +47,13 @@ type Variable commonv1.Variable

// TestSuiteStepSpec for particular type will have config for possible step types
type TestSuiteStepSpec struct {
Type string `json:"type,omitempty"`
Type TestSuiteStepType `json:"type,omitempty"`
Execute *TestSuiteStepExecute `json:"execute,omitempty"`
Delay *TestSuiteStepDelay `json:"delay,omitempty"`
}

// TestSuiteStepType deines different type of test suite steps
// TestSuiteStepType defines different type of test suite steps
// +kubebuilder:validation:Enum=execute;delay
type TestSuiteStepType string

const (
Expand All @@ -76,11 +77,22 @@ type TestSuiteStepDelay struct {
// running context for test or test suite execution
type RunningContext struct {
// One of possible context types
Type_ string `json:"type"`
Type_ RunningContextType `json:"type"`
// Context value depending from its type
Context string `json:"context,omitempty"`
}

type RunningContextType string

const (
RunningContextTypeUserCLI RunningContextType = "user-cli"
RunningContextTypeUserUI RunningContextType = "user-ui"
RunningContextTypeTestSuite RunningContextType = "testsuite"
RunningContextTypeTestTrigger RunningContextType = "testtrigger"
RunningContextTypeScheduler RunningContextType = "scheduler"
RunningContextTypeEmpty RunningContextType = ""
)

// test suite execution request body
type TestSuiteExecutionRequest struct {
// test execution custom name
Expand All @@ -105,17 +117,7 @@ type TestSuiteExecutionRequest struct {
RunningContext *RunningContext `json:"runningContext,omitempty"`
}

type RunningContextType string

const (
RunningContextTypeUserCLI RunningContextType = "user-cli"
RunningContextTypeUserUI RunningContextType = "user-ui"
RunningContextTypeTestSuite RunningContextType = "testsuite"
RunningContextTypeTestTrigger RunningContextType = "testtrigger"
RunningContextTypeScheduler RunningContextType = "scheduler"
RunningContextTypeEmpty RunningContextType = ""
)

// +kubebuilder:validation:Enum=queued;running;passed;failed;aborting;aborted;timeout
type TestSuiteExecutionStatus string

// List of TestSuiteExecutionStatus
Expand Down
Loading

0 comments on commit ecf1391

Please sign in to comment.