Skip to content

Commit

Permalink
feat: add content search table
Browse files Browse the repository at this point in the history
  • Loading branch information
ellisvalentiner committed Jul 6, 2022
1 parent 316eabd commit bcf9037
Show file tree
Hide file tree
Showing 3 changed files with 144 additions and 0 deletions.
1 change: 1 addition & 0 deletions confluence/plugin.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ func Plugin(ctx context.Context) *plugin.Plugin {
"confluence_content_label": tableConfluenceContentLabel(),
"confluence_content_version": tableConfluenceContentVersion(),
"confluence_space": tableConfluenceSpace(),
"confluence_search_content": tableConfluenceSearchContent(),
},
}
return p
Expand Down
110 changes: 110 additions & 0 deletions confluence/table_confluence_search_content.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,110 @@
package confluence

import (
"context"

model "github.com/ctreminiom/go-atlassian/pkg/infra/models"

"github.com/turbot/steampipe-plugin-sdk/v3/grpc/proto"
"github.com/turbot/steampipe-plugin-sdk/v3/plugin"
"github.com/turbot/steampipe-plugin-sdk/v3/plugin/transform"
)

//// TABLE DEFINITION

func tableConfluenceSearchContent() *plugin.Table {
return &plugin.Table{
Name: "confluence_search_content",
Description: "Confluence Search Content.",
List: &plugin.ListConfig{
Hydrate: listSearchContent,
KeyColumns: plugin.SingleColumn("cql"),
},
Columns: []*plugin.Column{
{
Name: "id",
Type: proto.ColumnType_STRING,
Description: "Automatically assigned when the content is created.",
Transform: transform.FromField("Content.ID"),
},
{
Name: "title",
Type: proto.ColumnType_STRING,
Description: "The content title",
Transform: transform.FromField("Content.Title"),
},
{
Name: "status",
Type: proto.ColumnType_STRING,
Description: "The content status",
Transform: transform.FromField("Content.Status"),
},
{
Name: "type",
Type: proto.ColumnType_STRING,
Description: "The content type (page, blogpost, attachment or content)",
Transform: transform.FromField("Content.Type"),
},
{
Name: "last_modified",
Type: proto.ColumnType_STRING,
Description: "When the content was last modified",
Transform: transform.FromField("LastModified"),
},
{
Name: "cql",
Type: proto.ColumnType_STRING,
Transform: transform.FromQual("cql"),
Description: "The Confluence query langauge.",
},
},
}
}

//// LIST FUNCTIONS

func listSearchContent(ctx context.Context, d *plugin.QueryData, _ *plugin.HydrateData) (interface{}, error) {
logger := plugin.Logger(ctx)
logger.Trace("Search confluence content")

cql := d.KeyColumnQuals["cql"].GetStringValue()
logger.Trace("listSearchContent", "cql", cql)

instance, err := connect(ctx, d)
if err != nil {
return nil, err
}

var limit int
if d.QueryContext.Limit != nil {
limit = int(limit)
} else {
limit = 100
}
options := &model.SearchContentOptions{
Limit: limit,
Expand: []string{"space"},
}

startAt := 0
pageSize := 25
pagesLeft := true
for pagesLeft {
searchResults, response, err := instance.Search.Content(context.Background(), cql, options)
if err != nil {
logger.Warn("Encountered error", "error", err, "Response", response)
return nil, nil
}

for _, row := range searchResults.Results {
d.StreamListItem(ctx, row)
if plugin.IsCancelled(ctx) {
logger.Trace("CANCELLED!")
return nil, nil
}
}
pagesLeft = false
startAt += pageSize
}
return nil, nil
}
33 changes: 33 additions & 0 deletions docs/tables/confluence_search_content.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
# Table: confluence_search_content

Search content in a Confluence instance.

## Examples

### Get content with type "blogpost"

```sql
select
id,
title,
status,
type,
last_modified
from
confluence_search_content
where cql='type=blogpost';
```

### Get content with the "soc2" label

```sql
select
id,
title,
status,
type,
last_modified
from
confluence_search_content
where cql='label=soc2';
```

0 comments on commit bcf9037

Please sign in to comment.