Skip to content

Commit

Permalink
add drafts of new tables
Browse files Browse the repository at this point in the history
  • Loading branch information
ellisvalentiner committed Feb 13, 2022
1 parent 001a7be commit 0478ea4
Show file tree
Hide file tree
Showing 6 changed files with 122 additions and 77 deletions.
5 changes: 4 additions & 1 deletion confluence/table_confluence_content.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
146 changes: 96 additions & 50 deletions confluence/table_confluence_content_label.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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,
Expand All @@ -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,
Expand All @@ -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

Expand All @@ -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
}
15 changes: 6 additions & 9 deletions confluence/table_confluence_content_metadata.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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,
Expand All @@ -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)

Expand Down
27 changes: 13 additions & 14 deletions confluence/table_confluence_content_version.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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
Expand All @@ -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)

Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -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 (
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -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=
Expand Down

0 comments on commit 0478ea4

Please sign in to comment.