From 0478ea4b7ccf33e675937e02e53b22e7da07f8a6 Mon Sep 17 00:00:00 2001 From: Ellis Valentiner Date: Sun, 13 Feb 2022 17:42:43 -0500 Subject: [PATCH] add drafts of new tables --- confluence/table_confluence_content.go | 5 +- confluence/table_confluence_content_label.go | 146 ++++++++++++------ .../table_confluence_content_metadata.go | 15 +- .../table_confluence_content_version.go | 27 ++-- go.mod | 2 +- go.sum | 4 +- 6 files changed, 122 insertions(+), 77 deletions(-) diff --git a/confluence/table_confluence_content.go b/confluence/table_confluence_content.go index b685238..d1b5b0c 100644 --- a/confluence/table_confluence_content.go +++ b/confluence/table_confluence_content.go @@ -83,8 +83,11 @@ func listContent(ctx context.Context, d *plugin.QueryData, _ *plugin.HydrateData startAt := 0 + quals := d.KeyColumnQuals options := &model.GetContentOptionsScheme{ - Expand: []string{"childTypes.all", "body.storage", "body.view", "space", "version"}, + Expand: []string{"childTypes.all", "body.storage", "body.view", "space", "version"}, + SpaceKey: quals["space_key"].GetStringValue(), + // Status: quals["status"].GetStringValue(), } pagesLeft := true diff --git a/confluence/table_confluence_content_label.go b/confluence/table_confluence_content_label.go index ea1a6b6..6a6f0d7 100644 --- a/confluence/table_confluence_content_label.go +++ b/confluence/table_confluence_content_label.go @@ -3,11 +3,10 @@ package confluence import ( "context" - // "github.com/ctreminiom/go-atlassian/confluence" + model "github.com/ctreminiom/go-atlassian/pkg/infra/models" "github.com/turbot/steampipe-plugin-sdk/grpc/proto" "github.com/turbot/steampipe-plugin-sdk/plugin" - // "github.com/turbot/steampipe-plugin-sdk/plugin/transform" ) //// TABLE DEFINITION @@ -16,9 +15,10 @@ func tableConfluenceContentLabel() *plugin.Table { return &plugin.Table{ Name: "confluence_content_label", Description: "Confluence Content Label.", - // List: &plugin.ListConfig{ - // Hydrate: listContentLabel, - // }, + List: &plugin.ListConfig{ + ParentHydrate: listContent, + Hydrate: listContentLabel, + }, Get: &plugin.GetConfig{ KeyColumns: plugin.SingleColumn("id"), Hydrate: getContentLabel, @@ -29,6 +29,21 @@ func tableConfluenceContentLabel() *plugin.Table { Type: proto.ColumnType_STRING, Description: "Automatically assigned when the label is created", }, + { + Name: "content_id", + Type: proto.ColumnType_STRING, + Description: "Automatically assigned when the content is created", + }, + { + Name: "title", + Type: proto.ColumnType_STRING, + Description: "The content title", + }, + { + Name: "space_key", + Type: proto.ColumnType_STRING, + Description: "The space containing the content", + }, { Name: "prefix", Type: proto.ColumnType_STRING, @@ -48,48 +63,62 @@ func tableConfluenceContentLabel() *plugin.Table { } } +type contentLabel struct { + ID string `json:"id,omitempty"` + ContentID string `json:"contentId,omitempty"` + Title string `json:"title,omitempty"` + SpaceKey string `json:"spaceKey,omitempty"` + Prefix string `json:"prefix,omitempty"` + Name string `json:"name,omitempty"` + Label string `json:"label,omitempty"` +} + //// LIST FUNCTIONS -// func listContentLabel(ctx context.Context, d *plugin.QueryData, _ *plugin.HydrateData) (interface{}, error) { -// logger := plugin.Logger(ctx) -// logger.Trace("listContentLabel") -// -// instance, err := connect(ctx, d) -// if err != nil { -// 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 -// -// pagesLeft := true -// for pagesLeft { -// labels, _, err := instance.Content.Label.Gets(context.Background(), contentID, prefix, startAt, maxResults) -// if err != nil { -// return nil, err -// } -// for _, label := range labels.Results { -// d.StreamListItem(ctx, label) -// if plugin.IsCancelled(ctx) { -// return nil, nil -// } -// } -// if labels.Size < labels.Limit { -// pagesLeft = false -// } -// startAt += maxResults -// } -// return nil, nil -// } +func listContentLabel(ctx context.Context, d *plugin.QueryData, h *plugin.HydrateData) (interface{}, error) { + logger := plugin.Logger(ctx) + logger.Trace("listContentLabel") + + instance, err := connect(ctx, d) + if err != nil { + 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 + content := h.Item.(*model.ContentScheme) + quals := d.KeyColumnQuals + prefix := quals["prefix"].GetStringValue() + labels, _, err := instance.Content.Label.Gets(context.Background(), content.ID, prefix, startAt, maxResults) + if err != nil { + return nil, err + } + for _, label := range labels.Results { + row := contentLabel{ + ID: label.ID, + ContentID: content.ID, + Title: content.Title, + SpaceKey: content.Space.Key, + Prefix: label.Prefix, + Name: label.Name, + Label: label.Label, + } + d.StreamListItem(ctx, row) + if plugin.IsCancelled(ctx) { + return nil, nil + } + } + return nil, nil +} //// HYDRATE FUNCTIONS @@ -114,17 +143,34 @@ func getContentLabel(ctx context.Context, d *plugin.QueryData, h *plugin.Hydrate startAt := 0 + content := h.Item.(*model.ContentScheme) quals := d.KeyColumnQuals logger.Warn("getContentLabel", "quals", quals) - // id := quals["id"].GetStringValue() - // logger.Warn("getContentLabel", "id", id) - contentID := quals["contentid"].GetStringValue() + contentID := quals["content_id"].GetStringValue() prefix := quals["prefix"].GetStringValue() - content, _, err := instance.Content.Label.Gets(context.Background(), contentID, prefix, startAt, maxResults) + labels, _, err := instance.Content.Label.Gets(context.Background(), contentID, prefix, startAt, maxResults) if err != nil { return nil, err } + var rows []contentLabel + + for _, label := range labels.Results { + row := contentLabel{ + ID: label.ID, + ContentID: content.ID, + Title: content.Title, + SpaceKey: content.Space.Key, + Prefix: label.Prefix, + Name: label.Name, + Label: label.Label, + } + // d.StreamListItem(ctx, row) + if plugin.IsCancelled(ctx) { + return nil, nil + } + rows = append(rows, row) + } - return content, nil + return rows, nil } diff --git a/confluence/table_confluence_content_metadata.go b/confluence/table_confluence_content_metadata.go index f5ba177..42b3f14 100644 --- a/confluence/table_confluence_content_metadata.go +++ b/confluence/table_confluence_content_metadata.go @@ -3,7 +3,6 @@ package confluence import ( "context" - // "github.com/ctreminiom/go-atlassian/confluence" model "github.com/ctreminiom/go-atlassian/pkg/infra/models" "github.com/turbot/steampipe-plugin-sdk/grpc/proto" @@ -13,7 +12,7 @@ import ( //// TABLE DEFINITION func tableConfluenceContentMetadata() *plugin.Table { return &plugin.Table{ - Name: "confluence_content_metadata_currentuser", + Name: "confluence_content_metadata", Description: "Information about the current user in relation to the content, including when they last viewed it, modified it, contributed to it, or added it as a favorite.", List: &plugin.ListConfig{ ParentHydrate: listContent, @@ -34,23 +33,21 @@ func tableConfluenceContentMetadata() *plugin.Table { } } - // structs type metadata struct { - ID string `json:"id,omitempty"` - Metadata *model.MetadataScheme `json:"metadata,omitempty"` + ID string `json:"id,omitempty"` + Metadata *model.MetadataScheme `json:"metadata,omitempty"` } - //// LIST FUNCTIONS func listContentMetadata(ctx context.Context, d *plugin.QueryData, h *plugin.HydrateData) (interface{}, error) { logger := plugin.Logger(ctx) - logger.Trace("listContentMetadataCurrentUser") + logger.Trace("listContentMetadata") content := h.Item.(*model.ContentScheme) c := metadata{ - ID: content.ID, - Metadata: content.Metadata, + ID: content.ID, + Metadata: content.Metadata, } d.StreamListItem(ctx, c) diff --git a/confluence/table_confluence_content_version.go b/confluence/table_confluence_content_version.go index 7679c4a..00608aa 100644 --- a/confluence/table_confluence_content_version.go +++ b/confluence/table_confluence_content_version.go @@ -3,7 +3,6 @@ package confluence import ( "context" - // "github.com/ctreminiom/go-atlassian/confluence" model "github.com/ctreminiom/go-atlassian/pkg/infra/models" "github.com/turbot/steampipe-plugin-sdk/grpc/proto" @@ -56,12 +55,12 @@ func tableConfluenceContentVersion() *plugin.Table { } type contentVersion struct { - ID string `json:"id,omitempty"` - By *model.ContentUserScheme `json:"by,omitempty"` - Number int `json:"number,omitempty"` - When string `json:"when,omitempty"` - Message string `json:"message,omitempty"` - MinorEdit bool `json:"minorEdit,omitempty"` + ID string `json:"id,omitempty"` + By *model.ContentUserScheme `json:"by,omitempty"` + Number int `json:"number,omitempty"` + When string `json:"when,omitempty"` + Message string `json:"message,omitempty"` + MinorEdit bool `json:"minorEdit,omitempty"` } //// LIST FUNCTIONS @@ -71,13 +70,13 @@ func listContentVersion(ctx context.Context, d *plugin.QueryData, h *plugin.Hydr logger.Trace("listContentVersion") content := h.Item.(*model.ContentScheme) - c := contentVersion { - ID: content.ID, - By: content.Version.By, - Number: content.Version.Number, - When: content.Version.When, - Message: content.Version.Message, - MinorEdit: content.Version.MinorEdit, + c := contentVersion{ + ID: content.ID, + By: content.Version.By, + Number: content.Version.Number, + When: content.Version.When, + Message: content.Version.Message, + MinorEdit: content.Version.MinorEdit, } d.StreamListItem(ctx, c) diff --git a/go.mod b/go.mod index 457aa0c..54cab18 100644 --- a/go.mod +++ b/go.mod @@ -4,7 +4,7 @@ go 1.17 require ( github.com/ctreminiom/go-atlassian v1.4.2 - github.com/turbot/steampipe-plugin-sdk v1.8.2 + github.com/turbot/steampipe-plugin-sdk v1.8.3 ) require ( diff --git a/go.sum b/go.sum index 6d68761..cd52db8 100644 --- a/go.sum +++ b/go.sum @@ -146,8 +146,8 @@ github.com/tkrajina/go-reflector v0.5.4 h1:dS9aJEa/eYNQU/fwsb5CSiATOxcNyA/gG/A7a github.com/tkrajina/go-reflector v0.5.4/go.mod h1:9PyLgEOzc78ey/JmQQHbW8cQJ1oucLlNQsg8yFvkVk8= github.com/turbot/go-kit v0.3.0 h1:o4zZIO1ovdmJ2bHWOdXnnt8jJMIDGqYSkZvBREzFeMQ= github.com/turbot/go-kit v0.3.0/go.mod h1:SBdPRngbEfYubiR81iAVtO43oPkg1+ASr+XxvgbH7/k= -github.com/turbot/steampipe-plugin-sdk v1.8.2 h1:ng/UNCI1mS8/iYwj42MdHU/hGkU2XBH0HR0W3IB3nw4= -github.com/turbot/steampipe-plugin-sdk v1.8.2/go.mod h1:76H3wr6KB6t+kDS38EEOZAsw61Ie/q7/IV9X0kv5NjI= +github.com/turbot/steampipe-plugin-sdk v1.8.3 h1:P6Bxp9GWbUhXaR5Rq/tFuFvuhe/hFFKCiDxzxv4OH9A= +github.com/turbot/steampipe-plugin-sdk v1.8.3/go.mod h1:76H3wr6KB6t+kDS38EEOZAsw61Ie/q7/IV9X0kv5NjI= github.com/vmihailenco/msgpack v3.3.3+incompatible/go.mod h1:fy3FlTQTDXWkZ7Bh6AcGMlsjHatGryHQYUTf1ShIgkk= github.com/vmihailenco/msgpack/v4 v4.3.12/go.mod h1:gborTTJjAo/GWTqqRjrLCn9pgNN+NXzzngzBKDPIqw4= github.com/vmihailenco/tagparser v0.1.1/go.mod h1:OeAg3pn3UbLjkWt+rN9oFYB6u/cQgqMEUPoW2WPyhdI=