Skip to content

Commit

Permalink
Merge pull request #14 from ellisvalentiner/fix/issue-7-initial-plugi…
Browse files Browse the repository at this point in the history
…n-suggestions

fix: initial plugin suggestions
  • Loading branch information
ellisvalentiner authored Jan 11, 2022
2 parents 26976a0 + dc46359 commit 955ea46
Show file tree
Hide file tree
Showing 14 changed files with 509 additions and 162 deletions.
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@

install:
go build -o ~/.steampipe/plugins/hub.steampipe.io/plugins/confluence/confluence@latest/steampipe-plugin-confluence.plugin *.go
go build -o ~/.steampipe/plugins/hub.steampipe.io/plugins/ellisvalentiner/confluence@latest/steampipe-plugin-confluence.plugin *.go
2 changes: 1 addition & 1 deletion config/confluence.spc
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
connection "confluence" {
plugin = "confluence"
plugin = "ellisvalentiner/confluence"

# Base URI of your Confluence Cloud instance
base_url = "https://your-domain.atlassian.net/"
Expand Down
6 changes: 4 additions & 2 deletions confluence/plugin.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,10 @@ func Plugin(ctx context.Context) *plugin.Plugin {
Schema: ConfigSchema,
},
TableMap: map[string]*plugin.Table{
"confluence_content": tableConfluenceContent(),
"confluence_content_body": tableConfluenceContentBody(),
"confluence_content": tableConfluenceContent(),
"confluence_content_body_storage": tableConfluenceContentBodyStorage(),
"confluence_content_body_view": tableConfluenceContentBodyView(),
"confluence_space": tableConfluenceSpace(),
},
}
return p
Expand Down
77 changes: 27 additions & 50 deletions confluence/table_confluence_content.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,67 +30,31 @@ func tableConfluenceContent() *plugin.Table {
Description: "Automatically assigned when the content is created",
},
{
Name: "body",
Type: proto.ColumnType_JSON,
Description: "The body of the content.",
},
{
Name: "child_types",
Type: proto.ColumnType_JSON,
Description: "Shows whether a piece of content has attachments, comments, or child pages. Note, this doesn't actually contain the child objects.",
Transform: transform.FromField("Fields.childTypes"),
},
{
Name: "expandable",
Type: proto.ColumnType_JSON,
Description: "",
Transform: transform.FromField("Fields._expandable"),
},
{
Name: "extensions",
Type: proto.ColumnType_JSON,
Description: "",
},
{
Name: "metadata",
Type: proto.ColumnType_JSON,
Description: "Metadata object for page, blogpost, comment content",
},
{
Name: "links",
Type: proto.ColumnType_JSON,
Description: "",
Transform: transform.FromField("Fields._links"),
},
{
Name: "operations",
Type: proto.ColumnType_JSON,
Description: "An operation and the target entity that it applies to, e.g. create page",
Name: "title",
Type: proto.ColumnType_STRING,
Description: "The content title",
},
{
Name: "space",
Type: proto.ColumnType_JSON,
Name: "space_key",
Type: proto.ColumnType_STRING,
Description: "The space containing the content",
Transform: transform.FromField("Space.Key"),
},
{
Name: "status",
Type: proto.ColumnType_STRING,
Description: "The content status",
},
{
Name: "title",
Type: proto.ColumnType_STRING,
Description: "The content title",
},
{
Name: "type",
Type: proto.ColumnType_STRING,
Description: "The content type (page, blogpost, attachment or content)",
},
{
Name: "version",
Type: proto.ColumnType_JSON,
Name: "version_number",
Type: proto.ColumnType_INT,
Description: "The content version",
Transform: transform.FromField("Version.Number"),
},
},
}
Expand All @@ -107,23 +71,36 @@ func listContent(ctx context.Context, d *plugin.QueryData, _ *plugin.HydrateData
return nil, err
}

var maxResults int
limit := d.QueryContext.Limit
if limit != nil {
if *limit < int64(100) {
maxResults = int(*limit)
}
} else {
maxResults = 100
}

startAt := 0
maxResults := 50

options := &confluence.GetContentOptionsScheme{
Expand: []string{"childTypes.all", "body.storage"},
Expand: []string{"childTypes.all", "body.storage", "body.view", "space", "version"},
}

for {
pagesLeft := true
for pagesLeft {
page, _, err := instance.Content.Gets(context.Background(), options, startAt, maxResults)
if err != nil {
return nil, err
}
for _, content := range page.Results {
d.StreamListItem(ctx, content)
if plugin.IsCancelled(ctx) {
return nil, nil
}
}
if page.Size < page.Limit {
break
pagesLeft = false
}
startAt += maxResults
}
Expand All @@ -146,7 +123,7 @@ func getContent(ctx context.Context, d *plugin.QueryData, h *plugin.HydrateData)
id := quals["id"].GetStringValue()
logger.Warn("getContent", "id", id)

expand := []string{"any"}
expand := []string{"childTypes.all", "body.storage", "body.view", "space", "version"}
version := 1

content, _, err := instance.Content.Get(context.Background(), id, expand, version)
Expand Down
92 changes: 0 additions & 92 deletions confluence/table_confluence_content_body.go

This file was deleted.

64 changes: 64 additions & 0 deletions confluence/table_confluence_content_body_storage.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
package confluence

import (
"context"

"github.com/ctreminiom/go-atlassian/confluence"

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

//// TABLE DEFINITION

func tableConfluenceContentBodyStorage() *plugin.Table {
return &plugin.Table{
Name: "confluence_content_body_storage",
Description: "Confluence Content Body in the Storage Format.",
List: &plugin.ListConfig{
ParentHydrate: listContent,
Hydrate: listContentBodyStorage,
},
Columns: []*plugin.Column{
{
Name: "id",
Type: proto.ColumnType_STRING,
Description: "The ID of the content.",
},
{
Name: "representation",
Type: proto.ColumnType_STRING,
Description: "The representation type of the content.",
},
{
Name: "value",
Type: proto.ColumnType_STRING,
Description: "The content body.",
},
},
}
}

// structs
type contentBody struct {
ID string `json:"id,omitempty"`
Representation string `json:"representation,omitempty"`
Value string `json:"value,omitempty"`
}

//// LIST FUNCTIONS

func listContentBodyStorage(ctx context.Context, d *plugin.QueryData, h *plugin.HydrateData) (interface{}, error) {
logger := plugin.Logger(ctx)
logger.Trace("listContentBody")

content := h.Item.(*confluence.ContentScheme)
c := contentBody{
ID: content.ID,
Representation: content.Body.Storage.Representation,
Value: content.Body.Storage.Value,
}
d.StreamListItem(ctx, c)

return nil, nil
}
57 changes: 57 additions & 0 deletions confluence/table_confluence_content_body_view.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
package confluence

import (
"context"

"github.com/ctreminiom/go-atlassian/confluence"

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

//// TABLE DEFINITION

func tableConfluenceContentBodyView() *plugin.Table {
return &plugin.Table{
Name: "confluence_content_body_view",
Description: "Confluence Content Body in the View Format.",
List: &plugin.ListConfig{
ParentHydrate: listContent,
Hydrate: listContentBodyView,
},
Columns: []*plugin.Column{
{
Name: "id",
Type: proto.ColumnType_STRING,
Description: "The ID of the content.",
},
{
Name: "representation",
Type: proto.ColumnType_STRING,
Description: "The representation type of the content.",
},
{
Name: "value",
Type: proto.ColumnType_STRING,
Description: "The content body.",
},
},
}
}

//// LIST FUNCTIONS

func listContentBodyView(ctx context.Context, d *plugin.QueryData, h *plugin.HydrateData) (interface{}, error) {
logger := plugin.Logger(ctx)
logger.Trace("listContentBody")

content := h.Item.(*confluence.ContentScheme)
c := contentBody{
ID: content.ID,
Representation: content.Body.View.Representation,
Value: content.Body.View.Value,
}
d.StreamListItem(ctx, c)

return nil, nil
}
Loading

0 comments on commit 955ea46

Please sign in to comment.