forked from harness/harness
-
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.
feat: [CDE-85]: Creating new pkg for infra providers. Adding interfac…
…e and types. (harness#2128)
- Loading branch information
1 parent
a2e3a3e
commit 62e5ae3
Showing
5 changed files
with
171 additions
and
0 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,23 @@ | ||
// Copyright 2023 Harness, Inc. | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
|
||
package enum | ||
|
||
func toInterfaceSlice[T interface{}](vals []T) []interface{} { | ||
res := make([]interface{}, len(vals)) | ||
for i := range vals { | ||
res[i] = vals[i] | ||
} | ||
return res | ||
} |
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,39 @@ | ||
// Copyright 2023 Harness, Inc. | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
|
||
package enum | ||
|
||
type InfraStatus string | ||
|
||
func (InfraStatus) Enum() []interface{} { | ||
return toInterfaceSlice(infraStatuses) | ||
} | ||
|
||
var infraStatuses = []InfraStatus{ | ||
InfraStatusPending, | ||
InfraStatusProvisioned, | ||
InfraStatusDestroyed, | ||
InfraStatusMarkedForDestroy, | ||
InfraStatusUnknown, | ||
InfraStatusSuspended, | ||
} | ||
|
||
const ( | ||
InfraStatusPending InfraStatus = "pending" | ||
InfraStatusProvisioned InfraStatus = "provisioned" | ||
InfraStatusDestroyed InfraStatus = "destroyed" | ||
InfraStatusMarkedForDestroy InfraStatus = "markedForDestroy" | ||
InfraStatusUnknown InfraStatus = "unknown" | ||
InfraStatusSuspended InfraStatus = "suspended" | ||
) |
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,27 @@ | ||
// Copyright 2023 Harness, Inc. | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
|
||
package enum | ||
|
||
type ProviderType string | ||
|
||
func (ProviderType) Enum() []interface{} { return toInterfaceSlice(providerTypes) } | ||
|
||
var providerTypes = []ProviderType{ | ||
ProviderTypeDocker, | ||
} | ||
|
||
const ( | ||
ProviderTypeDocker ProviderType = "docker" | ||
) |
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,41 @@ | ||
// Copyright 2023 Harness, Inc. | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
|
||
package infraprovider | ||
|
||
import ( | ||
"context" | ||
"io" | ||
|
||
"github.com/harness/gitness/infraprovider/enum" | ||
) | ||
|
||
type InfraProvider interface { | ||
// Provision provisions infrastructure against a resourceKey with the provided parameters. | ||
Provision(ctx context.Context, resourceKey string, parameters []Parameter) (Infrastructure, error) | ||
// Find finds infrastructure provisioned against a resourceKey. | ||
Find(ctx context.Context, resourceKey string, parameters []Parameter) (Infrastructure, error) | ||
// Stop frees up the resources allocated against a resourceKey, which can be freed. | ||
Stop(ctx context.Context, infra Infrastructure) (Infrastructure, error) | ||
// Destroy unprovisions all infrastructure provisioned againest the resourceKey. | ||
Destroy(ctx context.Context, infra Infrastructure) (Infrastructure, error) | ||
// Status checks the infrastructure status provisioned againest the resourceKey. | ||
Status(ctx context.Context, infra Infrastructure) (enum.InfraStatus, error) | ||
// AvailableParams provides a schema to define the infrastructure. | ||
AvailableParams() []ParameterSchema | ||
// ValidateParams validates the supplied params before defining the infrastructure resource . | ||
ValidateParams(parameters []Parameter) error | ||
// Exec executes a shell command in the infrastructure. | ||
Exec(ctx context.Context, infra Infrastructure, cmd []string) (io.Reader, io.Reader, 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
// Copyright 2023 Harness, Inc. | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
|
||
package infraprovider | ||
|
||
import "github.com/harness/gitness/infraprovider/enum" | ||
|
||
type ParameterSchema struct { | ||
Name string | ||
Description string | ||
DefaultValue string | ||
Required bool | ||
Secret bool | ||
Editable bool | ||
} | ||
|
||
type Parameter struct { | ||
Name string | ||
Value string | ||
} | ||
|
||
type Infrastructure struct { | ||
Identifier string | ||
ResourceKey string | ||
ProviderType enum.ProviderType | ||
Parameters []Parameter | ||
Status enum.InfraStatus | ||
Host string | ||
Port int | ||
} |