Skip to content

Commit

Permalink
hotfix 1.1.3 state upgraders for checks
Browse files Browse the repository at this point in the history
  • Loading branch information
rocktavious committed Aug 16, 2024
1 parent cb9a258 commit 4f8f2e6
Show file tree
Hide file tree
Showing 11 changed files with 232 additions and 9 deletions.
20 changes: 12 additions & 8 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,17 @@
name: "Release"

on:
workflow_dispatch: {}
workflow_dispatch:
inputs:
bump:
description: 'The version bump type'
required: true
default: 'patch'
type: choice
options:
- patch
- minor
- major
repository_dispatch:
types:
- release
Expand All @@ -21,18 +31,12 @@ jobs:
token: ${{ secrets.ORG_GITHUB_TOKEN }}
- name: Fetch All Tags
run: git fetch --force --tags
- name: Get version bump
id: bump
env:
VERSION_BUMP: ${{ toJson(github.event.client_payload.bump) }}
run: |
echo version_bump=$(echo $VERSION_BUMP | tr -d "\"") >> $GITHUB_OUTPUT
- name: Determine Next Version
id: next_version
uses: zwaldowski/semver-release-action@v4
with:
dry_run: true
bump: ${{ steps.bump.outputs.version_bump }}
bump: ${{ inputs.bump || toJson(github.event.client_payload.bump) }}
prefix: "v"
github_token: ${{ secrets.GITHUB_TOKEN }}
- name: Set up Go
Expand Down
8 changes: 8 additions & 0 deletions opslevel/common.go
Original file line number Diff line number Diff line change
Expand Up @@ -167,3 +167,11 @@ func flattenTeamsArray(teams *opslevel.TeamConnection) []string {
}
return output
}

func CheckUpgradeFunc[T any]() func(ctx context.Context, req resource.UpgradeStateRequest, resp *resource.UpgradeStateResponse) {
return func(ctx context.Context, req resource.UpgradeStateRequest, resp *resource.UpgradeStateResponse) {
upgradedStateModel := *new(T)
resp.Diagnostics.Append(req.State.Get(ctx, &upgradedStateModel)...)
resp.Diagnostics.Append(resp.State.Set(ctx, upgradedStateModel)...)
}
}
23 changes: 23 additions & 0 deletions opslevel/resource_opslevel_check_alert_source_usage.go
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,7 @@ func (r *CheckAlertSourceUsageResource) Metadata(ctx context.Context, req resour

func (r *CheckAlertSourceUsageResource) Schema(ctx context.Context, req resource.SchemaRequest, resp *resource.SchemaResponse) {
resp.Schema = schema.Schema{
Version: 1,
// This description is used by the documentation generator and the language server.
MarkdownDescription: "Check Alert Source Usage Resource",

Expand All @@ -109,6 +110,28 @@ func (r *CheckAlertSourceUsageResource) Schema(ctx context.Context, req resource
}
}

func (r *CheckAlertSourceUsageResource) UpgradeState(ctx context.Context) map[int64]resource.StateUpgrader {
return map[int64]resource.StateUpgrader{
// State upgrade implementation from 0 (prior state version) to 1 (Schema.Version)
0: {
PriorSchema: &schema.Schema{
Attributes: CheckBaseAttributes(map[string]schema.Attribute{
"alert_type": schema.StringAttribute{
Description: fmt.Sprintf(
"The type of the alert source. One of `%s`",
strings.Join(opslevel.AllAlertSourceTypeEnum, "`, `"),
),
Required: true,
Validators: []validator.String{stringvalidator.OneOf(opslevel.AllAlertSourceTypeEnum...)},
},
"alert_name_predicate": PredicateSchema(),
}),
},
StateUpgrader: CheckUpgradeFunc[CheckAlertSourceUsageResourceModel](),
},
}
}

func (r *CheckAlertSourceUsageResource) ValidateConfig(ctx context.Context, req resource.ValidateConfigRequest, resp *resource.ValidateConfigResponse) {
var configModel CheckAlertSourceUsageResourceModel
resp.Diagnostics.Append(req.Config.Get(ctx, &configModel)...)
Expand Down
28 changes: 28 additions & 0 deletions opslevel/resource_opslevel_check_repository_file.go
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,7 @@ func (r *CheckRepositoryFileResource) Metadata(ctx context.Context, req resource

func (r *CheckRepositoryFileResource) Schema(ctx context.Context, req resource.SchemaRequest, resp *resource.SchemaResponse) {
resp.Schema = schema.Schema{
Version: 1,
// This description is used by the documentation generator and the language server.
MarkdownDescription: "Check Repository File Resource",

Expand All @@ -118,6 +119,33 @@ func (r *CheckRepositoryFileResource) Schema(ctx context.Context, req resource.S
}
}

func (r *CheckRepositoryFileResource) UpgradeState(ctx context.Context) map[int64]resource.StateUpgrader {
return map[int64]resource.StateUpgrader{
// State upgrade implementation from 0 (prior state version) to 1 (Schema.Version)
0: {
PriorSchema: &schema.Schema{
Attributes: CheckBaseAttributes(map[string]schema.Attribute{
"directory_search": schema.BoolAttribute{
Description: "Whether the check looks for the existence of a directory instead of a file.",
Required: true,
},
"filepaths": schema.ListAttribute{
Description: "Restrict the search to certain file paths.",
Required: true,
ElementType: types.StringType,
},
"file_contents_predicate": PredicateSchema(),
"use_absolute_root": schema.BoolAttribute{
Description: "Whether the checks looks at the absolute root of a repo or the relative root (the directory specified when attached a repo to a service).",
Required: true,
},
}),
},
StateUpgrader: CheckUpgradeFunc[CheckRepositoryFileResourceModel](),
},
}
}

func (r *CheckRepositoryFileResource) ValidateConfig(ctx context.Context, req resource.ValidateConfigRequest, resp *resource.ValidateConfigResponse) {
var configModel CheckRepositoryFileResourceModel
resp.Diagnostics.Append(req.Config.Get(ctx, &configModel)...)
Expand Down
28 changes: 28 additions & 0 deletions opslevel/resource_opslevel_check_repository_grep.go
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,7 @@ func (r *CheckRepositoryGrepResource) Schema(ctx context.Context, req resource.S
predicateSchema.Required = true

resp.Schema = schema.Schema{
Version: 1,
// This description is used by the documentation generator and the language server.
MarkdownDescription: "Check Repository Grep Resource",

Expand All @@ -113,6 +114,33 @@ func (r *CheckRepositoryGrepResource) Schema(ctx context.Context, req resource.S
}
}

func (r *CheckRepositoryGrepResource) UpgradeState(ctx context.Context) map[int64]resource.StateUpgrader {
predicateSchema := PredicateSchema()
predicateSchema.Optional = false
predicateSchema.Required = true

return map[int64]resource.StateUpgrader{
// State upgrade implementation from 0 (prior state version) to 1 (Schema.Version)
0: {
PriorSchema: &schema.Schema{
Attributes: CheckBaseAttributes(map[string]schema.Attribute{
"directory_search": schema.BoolAttribute{
Description: "Whether the check looks for the existence of a directory instead of a file.",
Required: true,
},
"filepaths": schema.ListAttribute{
Description: "Restrict the search to certain file paths.",
Required: true,
ElementType: types.StringType,
},
"file_contents_predicate": predicateSchema,
}),
},
StateUpgrader: CheckUpgradeFunc[CheckRepositoryGrepResourceModel](),
},
}
}

func (r *CheckRepositoryGrepResource) ValidateConfig(ctx context.Context, req resource.ValidateConfigRequest, resp *resource.ValidateConfigResponse) {
var configModel CheckRepositoryGrepResourceModel
resp.Diagnostics.Append(req.Config.Get(ctx, &configModel)...)
Expand Down
27 changes: 27 additions & 0 deletions opslevel/resource_opslevel_check_repository_search.go
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,7 @@ func (r *CheckRepositorySearchResource) Schema(ctx context.Context, req resource
predicateSchema.Required = true

resp.Schema = schema.Schema{
Version: 1,
// This description is used by the documentation generator and the language server.
MarkdownDescription: "Check Repository Search Resource",

Expand All @@ -118,6 +119,32 @@ func (r *CheckRepositorySearchResource) Schema(ctx context.Context, req resource
}
}

func (r *CheckRepositorySearchResource) UpgradeState(ctx context.Context) map[int64]resource.StateUpgrader {
predicateSchema := PredicateSchema()
predicateSchema.Optional = false
predicateSchema.Required = true

return map[int64]resource.StateUpgrader{
// State upgrade implementation from 0 (prior state version) to 1 (Schema.Version)
0: {
PriorSchema: &schema.Schema{
Attributes: CheckBaseAttributes(map[string]schema.Attribute{
"file_extensions": schema.SetAttribute{
Description: "Restrict the search to files of given extensions. Extensions should contain only letters and numbers. For example: [\"py\", \"rb\"].",
Optional: true,
ElementType: types.StringType,
Validators: []validator.Set{
setvalidator.SizeAtLeast(1),
},
},
"file_contents_predicate": predicateSchema,
}),
},
StateUpgrader: CheckUpgradeFunc[CheckRepositorySearchResourceModel](),
},
}
}

func (r *CheckRepositorySearchResource) ValidateConfig(ctx context.Context, req resource.ValidateConfigRequest, resp *resource.ValidateConfigResponse) {
var configModel CheckRepositorySearchResourceModel
resp.Diagnostics.Append(req.Config.Get(ctx, &configModel)...)
Expand Down
36 changes: 36 additions & 0 deletions opslevel/resource_opslevel_check_service_ownership.go
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,7 @@ func (r *CheckServiceOwnershipResource) Metadata(ctx context.Context, req resour
func (r *CheckServiceOwnershipResource) Schema(ctx context.Context, req resource.SchemaRequest, resp *resource.SchemaResponse) {
enumAllContactTypes := append(opslevel.AllContactType, "any")
resp.Schema = schema.Schema{
Version: 1,
// This description is used by the documentation generator and the language server.
MarkdownDescription: "Check Service Ownership Resource",

Expand Down Expand Up @@ -136,6 +137,41 @@ func (r *CheckServiceOwnershipResource) Schema(ctx context.Context, req resource
}
}

func (r *CheckServiceOwnershipResource) UpgradeState(ctx context.Context) map[int64]resource.StateUpgrader {
enumAllContactTypes := append(opslevel.AllContactType, "any")
return map[int64]resource.StateUpgrader{
// State upgrade implementation from 0 (prior state version) to 1 (Schema.Version)
0: {
PriorSchema: &schema.Schema{
Attributes: CheckBaseAttributes(map[string]schema.Attribute{
"require_contact_method": schema.BoolAttribute{
Description: "True if a service's owner must have a contact method, False otherwise.",
Computed: true,
Optional: true,
Default: booldefault.StaticBool(false),
},
"contact_method": schema.StringAttribute{
Description: fmt.Sprintf(
"The type of contact method that is required. One of `%s`",
strings.Join(enumAllContactTypes, "`, `"),
),
Computed: true,
Optional: true,
Default: stringdefault.StaticString("ANY"),
Validators: []validator.String{stringvalidator.OneOfCaseInsensitive(enumAllContactTypes...)},
},
"tag_key": schema.StringAttribute{
Description: "The tag key where the tag predicate should be applied.",
Optional: true,
},
"tag_predicate": PredicateSchema(),
}),
},
StateUpgrader: CheckUpgradeFunc[CheckServiceOwnershipResourceModel](),
},
}
}

func (r *CheckServiceOwnershipResource) ValidateConfig(ctx context.Context, req resource.ValidateConfigRequest, resp *resource.ValidateConfigResponse) {
var configModel CheckServiceOwnershipResourceModel
resp.Diagnostics.Append(req.Config.Get(ctx, &configModel)...)
Expand Down
25 changes: 25 additions & 0 deletions opslevel/resource_opslevel_check_service_property.go
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,7 @@ func (r *CheckServicePropertyResource) Metadata(ctx context.Context, req resourc

func (r *CheckServicePropertyResource) Schema(ctx context.Context, req resource.SchemaRequest, resp *resource.SchemaResponse) {
resp.Schema = schema.Schema{
Version: 1,
// This description is used by the documentation generator and the language server.
MarkdownDescription: "Check Service Property Resource",

Expand All @@ -112,6 +113,30 @@ func (r *CheckServicePropertyResource) Schema(ctx context.Context, req resource.
}
}

func (r *CheckServicePropertyResource) UpgradeState(ctx context.Context) map[int64]resource.StateUpgrader {
return map[int64]resource.StateUpgrader{
// State upgrade implementation from 0 (prior state version) to 1 (Schema.Version)
0: {
PriorSchema: &schema.Schema{
Attributes: CheckBaseAttributes(map[string]schema.Attribute{
"property": schema.StringAttribute{
Description: fmt.Sprintf(
"The property of the service that the check will verify. One of `%s`",
strings.Join(opslevel.AllServicePropertyTypeEnum, "`, `"),
),
Required: true,
Validators: []validator.String{
stringvalidator.OneOf(opslevel.AllServicePropertyTypeEnum...),
},
},
"predicate": PredicateSchema(),
}),
},
StateUpgrader: CheckUpgradeFunc[CheckServicePropertyResourceModel](),
},
}
}

func (r *CheckServicePropertyResource) ValidateConfig(ctx context.Context, req resource.ValidateConfigRequest, resp *resource.ValidateConfigResponse) {
var configModel CheckServicePropertyResourceModel
resp.Diagnostics.Append(req.Config.Get(ctx, &configModel)...)
Expand Down
19 changes: 19 additions & 0 deletions opslevel/resource_opslevel_check_tag_defined.go
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,7 @@ func (r *CheckTagDefinedResource) Metadata(ctx context.Context, req resource.Met

func (r *CheckTagDefinedResource) Schema(ctx context.Context, req resource.SchemaRequest, resp *resource.SchemaResponse) {
resp.Schema = schema.Schema{
Version: 1,
// This description is used by the documentation generator and the language server.
MarkdownDescription: "Check Tag Defined Resource",

Expand All @@ -103,6 +104,24 @@ func (r *CheckTagDefinedResource) Schema(ctx context.Context, req resource.Schem
}
}

func (r *CheckTagDefinedResource) UpgradeState(ctx context.Context) map[int64]resource.StateUpgrader {
return map[int64]resource.StateUpgrader{
// State upgrade implementation from 0 (prior state version) to 1 (Schema.Version)
0: {
PriorSchema: &schema.Schema{
Attributes: CheckBaseAttributes(map[string]schema.Attribute{
"tag_key": schema.StringAttribute{
Description: "The tag key where the tag predicate should be applied.",
Required: true,
},
"tag_predicate": PredicateSchema(),
}),
},
StateUpgrader: CheckUpgradeFunc[CheckTagDefinedResourceModel](),
},
}
}

func (r *CheckTagDefinedResource) ValidateConfig(ctx context.Context, req resource.ValidateConfigRequest, resp *resource.ValidateConfigResponse) {
var configModel CheckTagDefinedResourceModel
resp.Diagnostics.Append(req.Config.Get(ctx, &configModel)...)
Expand Down
25 changes: 25 additions & 0 deletions opslevel/resource_opslevel_check_tool_usage.go
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,7 @@ func (r *CheckToolUsageResource) Metadata(ctx context.Context, req resource.Meta

func (r *CheckToolUsageResource) Schema(ctx context.Context, req resource.SchemaRequest, resp *resource.SchemaResponse) {
resp.Schema = schema.Schema{
Version: 1,
// This description is used by the documentation generator and the language server.
MarkdownDescription: "Check Tool Usage Resource",

Expand All @@ -135,6 +136,30 @@ func (r *CheckToolUsageResource) Schema(ctx context.Context, req resource.Schema
}
}

func (r *CheckToolUsageResource) UpgradeState(ctx context.Context) map[int64]resource.StateUpgrader {
return map[int64]resource.StateUpgrader{
// State upgrade implementation from 0 (prior state version) to 1 (Schema.Version)
0: {
PriorSchema: &schema.Schema{
Attributes: CheckBaseAttributes(map[string]schema.Attribute{
"tool_category": schema.StringAttribute{
Description: fmt.Sprintf(
"The category that the tool belongs to. One of `%s`",
strings.Join(opslevel.AllToolCategory, "`, `"),
),
Required: true,
Validators: []validator.String{stringvalidator.OneOf(opslevel.AllToolCategory...)},
},
"environment_predicate": PredicateSchema(),
"tool_name_predicate": PredicateSchema(),
"tool_url_predicate": PredicateSchema(),
}),
},
StateUpgrader: CheckUpgradeFunc[CheckToolUsageResourceModel](),
},
}
}

func (r *CheckToolUsageResource) ValidateConfig(ctx context.Context, req resource.ValidateConfigRequest, resp *resource.ValidateConfigResponse) {
var configModel CheckToolUsageResourceModel
resp.Diagnostics.Append(req.Config.Get(ctx, &configModel)...)
Expand Down

0 comments on commit 4f8f2e6

Please sign in to comment.