Skip to content

Commit

Permalink
Merge pull request #18 from ellisvalentiner/feat/add-new-tables
Browse files Browse the repository at this point in the history
feat: add new tables
  • Loading branch information
ellisvalentiner authored Apr 17, 2022
2 parents 4943653 + 6d48d5b commit e85a592
Show file tree
Hide file tree
Showing 12 changed files with 398 additions and 59 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/golangci-lint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,10 @@ jobs:
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v2
uses: actions/checkout@v3

- name: golangci-lint
uses: golangci/golangci-lint-action@v2
uses: golangci/golangci-lint-action@v3
with:
# Required: the version of golangci-lint is required and must be specified without patch version: we always use the latest patch version.
version: v1.29
Expand Down
2 changes: 2 additions & 0 deletions confluence/plugin.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ func Plugin(ctx context.Context) *plugin.Plugin {
"confluence_content": tableConfluenceContent(),
"confluence_content_body_storage": tableConfluenceContentBodyStorage(),
"confluence_content_body_view": tableConfluenceContentBodyView(),
"confluence_content_label": tableConfluenceContentLabel(),
"confluence_content_version": tableConfluenceContentVersion(),
"confluence_space": tableConfluenceSpace(),
},
}
Expand Down
53 changes: 27 additions & 26 deletions confluence/table_confluence_content.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ 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"
Expand Down Expand Up @@ -64,45 +64,46 @@ func tableConfluenceContent() *plugin.Table {

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

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)
}
var limit int
if d.QueryContext.Limit != nil {
limit = int(limit)
} else {
maxResults = 100
limit = 1000
}

startAt := 0

options := &confluence.GetContentOptionsScheme{
Expand: []string{"childTypes.all", "body.storage", "body.view", "space", "version"},
quals := d.KeyColumnQuals
options := &model.GetContentOptionsScheme{
Expand: []string{"childTypes.all", "body.storage", "body.view", "metadata.labels", "space", "version"},
SpaceKey: quals["space_key"].GetStringValue(),
}

startAt := 0
pageSize := 25
pagesLeft := true
for pagesLeft {
page, _, err := instance.Content.Gets(context.Background(), options, startAt, maxResults)
page, response, err := instance.Content.Gets(context.Background(), options, startAt, pageSize)
if err != nil {
return nil, err
}
for _, content := range page.Results {
d.StreamListItem(ctx, content)
if plugin.IsCancelled(ctx) {
return nil, nil
logger.Warn("Encountered error", "error", err, "Response", response)
return nil, nil
} else {
logger.Trace("Adding content items", "start", page.Start, "size", page.Size, "links", page.Links)
for _, content := range page.Results {
d.StreamListItem(ctx, content)
if plugin.IsCancelled(ctx) {
return nil, nil
}
}
if page.Size < page.Limit || limit <= page.Size {
pagesLeft = false
}
startAt += pageSize
}
if page.Size < page.Limit {
pagesLeft = false
}
startAt += maxResults
}
return nil, nil
}
Expand All @@ -111,7 +112,7 @@ func listContent(ctx context.Context, d *plugin.QueryData, _ *plugin.HydrateData

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

instance, err := connect(ctx, d)
if err != nil {
Expand Down
8 changes: 4 additions & 4 deletions confluence/table_confluence_content_body_storage.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ 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"
Expand Down Expand Up @@ -52,13 +52,13 @@ func listContentBodyStorage(ctx context.Context, d *plugin.QueryData, h *plugin.
logger := plugin.Logger(ctx)
logger.Trace("listContentBody")

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

return nil, nil
}
8 changes: 4 additions & 4 deletions confluence/table_confluence_content_body_view.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ 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"
Expand Down Expand Up @@ -45,13 +45,13 @@ func listContentBodyView(ctx context.Context, d *plugin.QueryData, h *plugin.Hyd
logger := plugin.Logger(ctx)
logger.Trace("listContentBody")

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

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

import (
"context"

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

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

//// TABLE DEFINITION

func tableConfluenceContentLabel() *plugin.Table {
return &plugin.Table{
Name: "confluence_content_label",
Description: "Confluence Content Label.",
List: &plugin.ListConfig{
ParentHydrate: listContent,
Hydrate: listContentLabel,
},
Columns: []*plugin.Column{
{
Name: "id",
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,
Description: "The label prefix",
},
{
Name: "name",
Type: proto.ColumnType_STRING,
Description: "The label name",
},
{
Name: "label",
Type: proto.ColumnType_STRING,
Description: "The label",
},
},
}
}

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, h *plugin.HydrateData) (interface{}, error) {
logger := plugin.Logger(ctx)
logger.Trace("listContentLabel")

content := h.Item.(*model.ContentScheme)
for _, label := range content.Metadata.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)
}

return nil, nil
}
Loading

0 comments on commit e85a592

Please sign in to comment.