Skip to content

Commit

Permalink
internal/snyk: rebase, cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
dobarx committed May 5, 2024
1 parent 4832789 commit 315e1dc
Show file tree
Hide file tree
Showing 4 changed files with 149 additions and 72 deletions.
87 changes: 72 additions & 15 deletions docs/plugins/snyk/data-sources/snyk_issues.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
title: snyk_issues
plugin:
name: blackstork/snyk
description: ""
description: "The `snyk_issues` data source fetches issues from Snyk"
tags: []
version: "v0.4.1"
source_github: "https://github.com/blackstork-io/fabric/tree/main/internal/snyk/"
Expand All @@ -15,6 +15,9 @@ type: docs

{{< plugin-resource-header "blackstork/snyk" "snyk" "v0.4.1" "snyk_issues" "data source" >}}

## Description
The `snyk_issues` data source fetches issues from Snyk.

## Installation

To use `snyk_issues` data source, you must install the plugin `blackstork/snyk`.
Expand All @@ -37,7 +40,10 @@ The data source supports the following configuration parameters:

```hcl
config data snyk_issues {
api_key = <string> # required
# The Snyk API key
#
# Required string. For example:
api_key = "some string"
}
```

Expand All @@ -47,18 +53,69 @@ The data source supports the following parameters in the data blocks:

```hcl
data snyk_issues {
created_after = <string> # optional
created_before = <string> # optional
effective_severity_level = <list of string> # optional
group_id = <string> # optional
ignored = <bool> # optional
limit = <number> # optional
org_id = <string> # optional
scan_item_id = <string> # optional
scan_item_type = <string> # optional
status = <list of string> # optional
type = <string> # optional
updated_after = <string> # optional
updated_before = <string> # optional
# The group ID
#
# Optional string. Default value:
group_id = null
# The organization ID
#
# Optional string. Default value:
org_id = null
# The scan item ID
#
# Optional string. Default value:
scan_item_id = null
# The scan item type
#
# Optional string. Default value:
scan_item_type = null
# The issue type
#
# Optional string. Default value:
type = null
# The updated before date
#
# Optional string. Default value:
updated_before = null
# The updated after date
#
# Optional string. Default value:
updated_after = null
# The created before date
#
# Optional string. Default value:
created_before = null
# The created after date
#
# Optional string. Default value:
created_after = null
# The effective severity level
#
# Optional list of string. Default value:
effective_severity_level = null
# The status
#
# Optional list of string. Default value:
status = null
# The ignored flag
#
# Optional bool. Default value:
ignored = null
# The limit of issues to fetch
#
# Optional number. Default value:
limit = null
}
```
1 change: 0 additions & 1 deletion internal/snyk/client/client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -169,5 +169,4 @@ func (s *ClientTestSuite) TestFull() {
Next: String("test_next"),
},
}, result)

}
54 changes: 35 additions & 19 deletions internal/snyk/data_snyk_issues.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,85 +4,101 @@ import (
"context"
"fmt"

"github.com/blackstork-io/fabric/internal/snyk/client"
"github.com/blackstork-io/fabric/plugin"
"github.com/hashicorp/hcl/v2"
"github.com/hashicorp/hcl/v2/hcldec"
"github.com/zclconf/go-cty/cty"

"github.com/blackstork-io/fabric/internal/snyk/client"
"github.com/blackstork-io/fabric/plugin"
"github.com/blackstork-io/fabric/plugin/dataspec"
)

func makeSnykIssuesDataSource(loader ClientLoadFn) *plugin.DataSource {
return &plugin.DataSource{
Doc: "The `snyk_issues` data source fetches issues from Snyk.",
DataFunc: fetchSnykIssues(loader),
Config: hcldec.ObjectSpec{
"api_key": &hcldec.AttrSpec{
Config: dataspec.ObjectSpec{
&dataspec.AttrSpec{
Doc: "The Snyk API key",
Name: "api_key",
Type: cty.String,
Required: true,
},
},
Args: hcldec.ObjectSpec{
"group_id": &hcldec.AttrSpec{
Args: dataspec.ObjectSpec{
&dataspec.AttrSpec{
Doc: "The group ID",
Name: "group_id",
Type: cty.String,
Required: false,
},
"org_id": &hcldec.AttrSpec{
&dataspec.AttrSpec{
Doc: "The organization ID",
Name: "org_id",
Type: cty.String,
Required: false,
},
"scan_item_id": &hcldec.AttrSpec{
&dataspec.AttrSpec{
Doc: "The scan item ID",
Name: "scan_item_id",
Type: cty.String,
Required: false,
},
"scan_item_type": &hcldec.AttrSpec{
&dataspec.AttrSpec{
Doc: "The scan item type",
Name: "scan_item_type",
Type: cty.String,
Required: false,
},
"type": &hcldec.AttrSpec{
&dataspec.AttrSpec{
Doc: "The issue type",
Name: "type",
Type: cty.String,
Required: false,
},
"updated_before": &hcldec.AttrSpec{
&dataspec.AttrSpec{
Doc: "The updated before date",
Name: "updated_before",
Type: cty.String,
Required: false,
},
"updated_after": &hcldec.AttrSpec{
&dataspec.AttrSpec{
Doc: "The updated after date",
Name: "updated_after",
Type: cty.String,
Required: false,
},
"created_before": &hcldec.AttrSpec{
&dataspec.AttrSpec{
Doc: "The created before date",
Name: "created_before",
Type: cty.String,
Required: false,
},
"created_after": &hcldec.AttrSpec{
&dataspec.AttrSpec{
Doc: "The created after date",
Name: "created_after",
Type: cty.String,
Required: false,
},
"effective_severity_level": &hcldec.AttrSpec{
&dataspec.AttrSpec{
Doc: "The effective severity level",
Name: "effective_severity_level",
Type: cty.List(cty.String),
Required: false,
},
"status": &hcldec.AttrSpec{
&dataspec.AttrSpec{
Doc: "The status",
Name: "status",
Type: cty.List(cty.String),
Required: false,
},
"ignored": &hcldec.AttrSpec{
&dataspec.AttrSpec{
Doc: "The ignored flag",
Name: "ignored",
Type: cty.Bool,
Required: false,
},
"limit": &hcldec.AttrSpec{
&dataspec.AttrSpec{
Doc: "The limit of issues to fetch",
Name: "limit",
Type: cty.Number,
Required: false,
Expand Down
79 changes: 42 additions & 37 deletions internal/snyk/data_snyk_issues_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import (
"github.com/zclconf/go-cty/cty"

"github.com/blackstork-io/fabric/internal/snyk/client"
"github.com/blackstork-io/fabric/internal/testtools"
client_mocks "github.com/blackstork-io/fabric/mocks/internalpkg/snyk/client"
"github.com/blackstork-io/fabric/plugin"
)
Expand Down Expand Up @@ -69,25 +70,27 @@ func (s *IssuesDataSourceTestSuite) TestPaging() {
}).Return(&client.ListIssuesRes{
Data: []any{},
}, nil)
cfg := testtools.ReencodeCTY(s.T(), s.schema.Config, cty.ObjectVal(map[string]cty.Value{
"api_key": cty.StringVal("test_api_key"),
}), nil)
args := testtools.ReencodeCTY(s.T(), s.schema.Args, cty.ObjectVal(map[string]cty.Value{
"group_id": cty.StringVal("test_group_id"),
"org_id": cty.NullVal(cty.String),
"scan_item_id": cty.NullVal(cty.String),
"scan_item_type": cty.NullVal(cty.String),
"type": cty.NullVal(cty.String),
"updated_before": cty.NullVal(cty.String),
"updated_after": cty.NullVal(cty.String),
"created_before": cty.NullVal(cty.String),
"created_after": cty.NullVal(cty.String),
"effective_severity_level": cty.NullVal(cty.List(cty.String)),
"status": cty.NullVal(cty.List(cty.String)),
"ignored": cty.NullVal(cty.Bool),
"limit": cty.NullVal(cty.Number),
}), nil)
res, diags := s.schema.DataFunc(s.ctx, &plugin.RetrieveDataParams{
Config: cty.ObjectVal(map[string]cty.Value{
"api_key": cty.StringVal("test_api_key"),
}),
Args: cty.ObjectVal(map[string]cty.Value{
"group_id": cty.StringVal("test_group_id"),
"org_id": cty.NullVal(cty.String),
"scan_item_id": cty.NullVal(cty.String),
"scan_item_type": cty.NullVal(cty.String),
"type": cty.NullVal(cty.String),
"updated_before": cty.NullVal(cty.String),
"updated_after": cty.NullVal(cty.String),
"created_before": cty.NullVal(cty.String),
"created_after": cty.NullVal(cty.String),
"effective_severity_level": cty.NullVal(cty.List(cty.String)),
"status": cty.NullVal(cty.List(cty.String)),
"ignored": cty.NullVal(cty.Bool),
"limit": cty.NullVal(cty.Number),
}),
Config: cfg,
Args: args,
})
s.Equal("test_api_key", s.storedAPIKey)
s.Len(diags, 0)
Expand Down Expand Up @@ -128,26 +131,28 @@ func (s *IssuesDataSourceTestSuite) TestFull() {
},
},
}, nil)

cfg := testtools.ReencodeCTY(s.T(), s.schema.Config, cty.ObjectVal(map[string]cty.Value{
"api_key": cty.StringVal("test_api_key"),
}), nil)
args := testtools.ReencodeCTY(s.T(), s.schema.Args, cty.ObjectVal(map[string]cty.Value{
"group_id": cty.NullVal(cty.String),
"org_id": cty.StringVal("test_org_id"),
"limit": cty.NumberIntVal(2),
"scan_item_id": cty.StringVal("test_scan_item_id"),
"scan_item_type": cty.StringVal("test_scan_item_type"),
"type": cty.StringVal("test_type"),
"updated_before": cty.StringVal("test_updated_before"),
"updated_after": cty.StringVal("test_updated_after"),
"created_before": cty.StringVal("test_created_before"),
"created_after": cty.StringVal("test_created_after"),
"effective_severity_level": cty.ListVal([]cty.Value{cty.StringVal("test_effective_severity_level_1"), cty.StringVal("test_effective_severity_level_2")}),
"status": cty.ListVal([]cty.Value{cty.StringVal("test_status_1"), cty.StringVal("test_status_2")}),
"ignored": cty.BoolVal(true),
}), nil)
res, diags := s.schema.DataFunc(s.ctx, &plugin.RetrieveDataParams{
Config: cty.ObjectVal(map[string]cty.Value{
"api_key": cty.StringVal("test_api_key"),
}),
Args: cty.ObjectVal(map[string]cty.Value{
"group_id": cty.NullVal(cty.String),
"org_id": cty.StringVal("test_org_id"),
"limit": cty.NumberIntVal(2),
"starting_after": cty.StringVal("test_starting_after"),
"scan_item_id": cty.StringVal("test_scan_item_id"),
"scan_item_type": cty.StringVal("test_scan_item_type"),
"type": cty.StringVal("test_type"),
"updated_before": cty.StringVal("test_updated_before"),
"updated_after": cty.StringVal("test_updated_after"),
"created_before": cty.StringVal("test_created_before"),
"created_after": cty.StringVal("test_created_after"),
"effective_severity_level": cty.ListVal([]cty.Value{cty.StringVal("test_effective_severity_level_1"), cty.StringVal("test_effective_severity_level_2")}),
"status": cty.ListVal([]cty.Value{cty.StringVal("test_status_1"), cty.StringVal("test_status_2")}),
"ignored": cty.BoolVal(true),
}),
Config: cfg,
Args: args,
})
s.Equal("test_api_key", s.storedAPIKey)
s.Len(diags, 0)
Expand Down

0 comments on commit 315e1dc

Please sign in to comment.