Skip to content

Commit

Permalink
make changes for nilaway
Browse files Browse the repository at this point in the history
  • Loading branch information
Taimoor Ahmad committed Jan 31, 2024
1 parent 6f5d458 commit edc22f7
Show file tree
Hide file tree
Showing 9 changed files with 34 additions and 24 deletions.
5 changes: 4 additions & 1 deletion opslevel/datasource_opslevel_filter.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,10 +54,13 @@ func filterFilters(data []opslevel.Filter, field string, value string) (*opsleve

func datasourceFilterRead(d *schema.ResourceData, client *opslevel.Client) error {
resp, err := client.ListFilters(nil)
results := resp.Nodes
if err != nil {
return err
}
if resp == nil {
return fmt.Errorf("unexpected: listing filters returned nil")
}
results := resp.Nodes

field := d.Get("filter.0.field").(string)
value := d.Get("filter.0.value").(string)
Expand Down
6 changes: 5 additions & 1 deletion opslevel/datasource_opslevel_filters.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package opslevel

import (
"fmt"
"github.com/opslevel/opslevel-go/v2024"

"github.com/hashicorp/terraform-plugin-sdk/helper/schema"
Expand All @@ -26,10 +27,13 @@ func datasourceFilters() *schema.Resource {

func datasourceFiltersRead(d *schema.ResourceData, client *opslevel.Client) error {
resp, err := client.ListFilters(nil)
result := resp.Nodes
if err != nil {
return err
}
if resp == nil {
return fmt.Errorf("unexpected: listing filters returned nil")
}
result := resp.Nodes

count := len(result)
ids := make([]string, count)
Expand Down
5 changes: 4 additions & 1 deletion opslevel/datasource_opslevel_integration.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,10 +54,13 @@ func filterIntegrations(data []opslevel.Integration, field string, value string)

func datasourceIntegrationRead(d *schema.ResourceData, client *opslevel.Client) error {
resp, err := client.ListIntegrations(nil)
results := resp.Nodes
if err != nil {
return err
}
if resp == nil {
return fmt.Errorf("unexpected: listing integrations returned nil")
}
results := resp.Nodes

field := d.Get("filter.0.field").(string)
value := d.Get("filter.0.value").(string)
Expand Down
6 changes: 5 additions & 1 deletion opslevel/datasource_opslevel_integrations.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package opslevel

import (
"fmt"
"github.com/opslevel/opslevel-go/v2024"

"github.com/hashicorp/terraform-plugin-sdk/helper/schema"
Expand All @@ -26,10 +27,13 @@ func datasourceIntegrations() *schema.Resource {

func datasourceIntegrationsRead(d *schema.ResourceData, client *opslevel.Client) error {
resp, err := client.ListIntegrations(nil)
result := resp.Nodes
if err != nil {
return err
}
if resp == nil {
return fmt.Errorf("unexpected: listing integrations returned nil")
}
result := resp.Nodes

count := len(result)
ids := make([]string, count)
Expand Down
2 changes: 1 addition & 1 deletion opslevel/resource_opslevel_check_repository_grep.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ func resourceCheckRepositoryGrepCreate(d *schema.ResourceData, client *opslevel.
fileContentsPredicate := expandPredicate(d, "file_contents_predicate")
if fileContentsPredicate == nil {
input.FileContentsPredicate = opslevel.PredicateInput{
Type: opslevel.PredicateTypeEnum("exists"),
Type: opslevel.PredicateTypeEnumExists,
}
}

Expand Down
7 changes: 6 additions & 1 deletion opslevel/resource_opslevel_check_repository_search.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package opslevel

import (
"fmt"
"github.com/hashicorp/terraform-plugin-sdk/helper/schema"
"github.com/opslevel/opslevel-go/v2024"
)
Expand Down Expand Up @@ -35,7 +36,11 @@ func resourceCheckRepositorySearchCreate(d *schema.ResourceData, client *opsleve
checkCreateInput := getCheckCreateInputFrom(d)
input := opslevel.NewCheckCreateInputTypeOf[opslevel.CheckRepositorySearchCreateInput](checkCreateInput)
input.FileExtensions = opslevel.RefOf(getStringArray(d, "file_extensions"))
input.FileContentsPredicate = *expandPredicate(d, "file_contents_predicate")
predicate := expandPredicate(d, "file_contents_predicate")
if predicate == nil {
return fmt.Errorf("unexpected: expanding predicate 'file_contents_predicate' returned nil")
}
input.FileContentsPredicate = *predicate

resource, err := client.CreateCheckRepositorySearch(*input)
if err != nil {
Expand Down
1 change: 0 additions & 1 deletion opslevel/resource_opslevel_check_service_ownership.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,6 @@ func resourceCheckServiceOwnershipCreate(d *schema.ResourceData, client *opsleve
if tagKey, ok := d.GetOk("tag_key"); ok {
input.TagKey = opslevel.RefOf(tagKey.(string))
}

input.TagPredicate = expandPredicate(d, "tag_predicate")

resource, err := client.CreateCheckServiceOwnership(*input)
Expand Down
3 changes: 3 additions & 0 deletions opslevel/resource_opslevel_property_assignment.go
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,9 @@ func resourcePropertyAssignmentRead(d *schema.ResourceData, client *opslevel.Cli

func resourcePropertyAssignmentDelete(d *schema.ResourceData, client *opslevel.Client) error {
id := strings.Split(d.Id(), ":")
if len(id) != 2 {
return fmt.Errorf("[%s] invalid property assignment id, should be in format 'ownerId:definitionId' (only a single colon between both ids, no spaces or special characters)", d.Id())
}
ownerId := id[0]
definitionId := id[1]
err := client.PropertyUnassign(ownerId, definitionId)
Expand Down
23 changes: 6 additions & 17 deletions opslevel/resource_opslevel_service.go
Original file line number Diff line number Diff line change
Expand Up @@ -101,26 +101,11 @@ func resourceService() *schema.Resource {
ForceNew: false,
Optional: true,
Elem: &schema.Schema{Type: schema.TypeString},
// ValidateFunc: validateServiceTags, // TODO: Not Yet Supported
},
},
}
}

func validateServiceTags(i interface{}, k string) (warnings []string, errors []error) {
data, ok := i.([]string)
if !ok {
return nil, []error{fmt.Errorf("expected type of %s to be string", k)}
}
for _, item := range data {
key := strings.TrimSpace(strings.Split(item, ":")[0])
if ok := TagKeyRegex.MatchString(key); !ok {
return nil, []error{fmt.Errorf("'%s' - %s", key, TagKeyErrorMsg)}
}
}
return nil, nil
}

func reconcileServiceAliases(d *schema.ResourceData, service *opslevel.Service, client *opslevel.Client) error {
expectedAliases := getStringArray(d, "aliases")
existingAliases := service.ManagedAliases
Expand Down Expand Up @@ -165,8 +150,12 @@ func reconcileTags(d *schema.ResourceData, service *opslevel.Service, client *op
}
tagInput := map[string]string{}
for _, tag := range tags {
key := strings.TrimSpace(strings.Split(tag, ":")[0])
value := strings.TrimSpace(strings.Split(tag, ":")[1])
parts := strings.Split(tag, ":")
if len(parts) != 2 {
return fmt.Errorf("invalid tag: '%s'", tag)
}
key := parts[0]
value := parts[1]
tagInput[key] = value
}
_, err := client.AssignTags(string(service.Id), tagInput)
Expand Down

0 comments on commit edc22f7

Please sign in to comment.