Skip to content

Commit

Permalink
Update the linode SDK version to v1.37.0, added the connection key qu…
Browse files Browse the repository at this point in the history
…als (#56)
  • Loading branch information
ParthaI authored Aug 9, 2024
1 parent 6d9a64c commit ed562ac
Show file tree
Hide file tree
Showing 18 changed files with 136 additions and 66 deletions.
24 changes: 11 additions & 13 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -5,17 +5,16 @@ go 1.21.0
toolchain go1.21.4

require (
github.com/linode/linodego v1.9.1
github.com/linode/linodego v1.37.0
github.com/pkg/errors v0.9.1
github.com/turbot/go-kit v0.10.0-rc.0
github.com/turbot/steampipe-plugin-sdk/v5 v5.10.1
golang.org/x/oauth2 v0.17.0
golang.org/x/oauth2 v0.21.0
)

require (
cloud.google.com/go v0.112.0 // indirect
cloud.google.com/go/compute v1.24.0 // indirect
cloud.google.com/go/compute/metadata v0.2.3 // indirect
cloud.google.com/go/compute/metadata v0.3.0 // indirect
cloud.google.com/go/iam v1.1.6 // indirect
cloud.google.com/go/storage v1.36.0 // indirect
github.com/acarl005/stripansi v0.0.0-20180116102854-5a71ef0e047d // indirect
Expand All @@ -41,7 +40,7 @@ require (
github.com/ghodss/yaml v1.0.0 // indirect
github.com/go-logr/logr v1.4.1 // indirect
github.com/go-logr/stdr v1.2.2 // indirect
github.com/go-resty/resty/v2 v2.7.0 // indirect
github.com/go-resty/resty/v2 v2.13.1 // indirect
github.com/golang/glog v1.2.0 // indirect
github.com/golang/groupcache v0.0.0-20210331224755-41bb18bfe9da // indirect
github.com/golang/mock v1.6.0 // indirect
Expand Down Expand Up @@ -95,17 +94,16 @@ require (
go.opentelemetry.io/otel/sdk/metric v1.26.0 // indirect
go.opentelemetry.io/otel/trace v1.26.0 // indirect
go.opentelemetry.io/proto/otlp v1.2.0 // indirect
golang.org/x/crypto v0.21.0 // indirect
golang.org/x/crypto v0.25.0 // indirect
golang.org/x/exp v0.0.0-20230522175609-2e198f4a06a1 // indirect
golang.org/x/mod v0.8.0 // indirect
golang.org/x/net v0.23.0 // indirect
golang.org/x/sync v0.6.0 // indirect
golang.org/x/sys v0.19.0 // indirect
golang.org/x/text v0.14.0 // indirect
golang.org/x/mod v0.17.0 // indirect
golang.org/x/net v0.27.0 // indirect
golang.org/x/sync v0.7.0 // indirect
golang.org/x/sys v0.22.0 // indirect
golang.org/x/text v0.16.0 // indirect
golang.org/x/time v0.5.0 // indirect
golang.org/x/tools v0.6.0 // indirect
golang.org/x/tools v0.21.1-0.20240508182429-e35e4ccd0d2d // indirect
google.golang.org/api v0.162.0 // indirect
google.golang.org/appengine v1.6.8 // indirect
google.golang.org/genproto v0.0.0-20240227224415-6ceb2ff114de // indirect
google.golang.org/genproto/googleapis/api v0.0.0-20240227224415-6ceb2ff114de // indirect
google.golang.org/genproto/googleapis/rpc v0.0.0-20240401170217-c3f982113cda // indirect
Expand Down
67 changes: 42 additions & 25 deletions go.sum

Large diffs are not rendered by default.

53 changes: 53 additions & 0 deletions linode/common_columns.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
package linode

import (
"context"

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

func commonColumns(c []*plugin.Column) []*plugin.Column {
return append([]*plugin.Column{
{
Name: "euuid",
Description: "An external unique identifier for this account.",
Type: proto.ColumnType_STRING,
Hydrate: getAccountEuuid,
Transform: transform.FromValue(),
},
}, c...)
}

// if the caching is required other than per connection, build a cache key for the call and use it in Memoize.
var getAccountEuuidMemoized = plugin.HydrateFunc(getAccountEuuidUncached).Memoize(memoize.WithCacheKeyFunction(getAccountEuuidCacheKey))

// declare a wrapper hydrate function to call the memoized function
// - this is required when a memoized function is used for a column definition
func getAccountEuuid(ctx context.Context, d *plugin.QueryData, h *plugin.HydrateData) (interface{}, error) {
return getAccountEuuidMemoized(ctx, d, h)
}

// Build a cache key for the call to getAccountEuuidCacheKey.
func getAccountEuuidCacheKey(ctx context.Context, d *plugin.QueryData, h *plugin.HydrateData) (interface{}, error) {
key := "getAccountEuuid"
return key, nil
}

func getAccountEuuidUncached(ctx context.Context, d *plugin.QueryData, h *plugin.HydrateData) (interface{}, error) {

conn, err := connect(ctx, d)
if err != nil {
plugin.Logger(ctx).Error("linode_account_settings.getAccount", "connection_error", err)
return nil, err
}
item, err := conn.GetAccount(ctx)
if err != nil {
plugin.Logger(ctx).Error("linode_account_settings.getAccount", "query_error", err)
return nil, err
}

return item.EUUID, nil
}
2 changes: 2 additions & 0 deletions linode/table_linode_account.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (

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

func tableLinodeAccount(ctx context.Context) *plugin.Table {
Expand All @@ -28,6 +29,7 @@ func tableLinodeAccount(ctx context.Context) *plugin.Table {
{Name: "credit_card", Type: proto.ColumnType_JSON, Description: "Credit Card information associated with this Account."},
{Name: "first_name", Type: proto.ColumnType_STRING, Description: "The first name of the person associated with this Account."},
{Name: "last_name", Type: proto.ColumnType_STRING, Description: "The last name of the person associated with this Account."},
{Name: "euuid", Type: proto.ColumnType_STRING, Description: "An external unique identifier for this account.", Transform: transform.FromField("EUUID")},
{Name: "phone", Type: proto.ColumnType_STRING, Description: "The phone number associated with this Account."},
{Name: "state", Type: proto.ColumnType_STRING, Description: "The state for this Account’s billing address."},
{Name: "tax_id", Type: proto.ColumnType_STRING, Description: "The tax identification number associated with this Account, for tax calculations in some countries. If you do not live in a country that collects tax, this should be null."},
Expand Down
4 changes: 2 additions & 2 deletions linode/table_linode_bucket.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,14 @@ func tableLinodeBucket(ctx context.Context) *plugin.Table {
KeyColumns: plugin.AllColumns([]string{"cluster", "label"}),
Hydrate: getBucket,
},
Columns: []*plugin.Column{
Columns: commonColumns([]*plugin.Column{
// Top columns
{Name: "label", Type: proto.ColumnType_STRING, Description: "The name of this bucket."},
// Other columns
{Name: "cluster", Type: proto.ColumnType_STRING, Description: "The ID of the Object Storage Cluster this bucket is in."},
{Name: "created", Type: proto.ColumnType_TIMESTAMP, Description: "When this bucket was created."},
{Name: "hostname", Type: proto.ColumnType_STRING, Description: "The hostname where this bucket can be accessed. This hostname can be accessed through a browser if the bucket is made public."},
},
}),
}
}

Expand Down
4 changes: 2 additions & 2 deletions linode/table_linode_domain.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ func tableLinodeDomain(ctx context.Context) *plugin.Table {
KeyColumns: plugin.SingleColumn("id"),
Hydrate: getDomain,
},
Columns: []*plugin.Column{
Columns: commonColumns([]*plugin.Column{
// Top columns
{Name: "id", Type: proto.ColumnType_INT, Description: "The unique ID of this Domain."},
{Name: "domain", Type: proto.ColumnType_STRING, Description: "The domain this Domain represents. These must be unique in our system; you cannot have two Domains representing the same domain."},
Expand All @@ -45,7 +45,7 @@ func tableLinodeDomain(ctx context.Context) *plugin.Table {
{Name: "tags", Type: proto.ColumnType_JSON, Transform: transform.FromField("Tags").Transform(transform.StringArrayToMap), Description: "Tags applied to this domain as a map."},
{Name: "tags_src", Type: proto.ColumnType_JSON, Transform: transform.FromField("Tags"), Description: "List of Tags applied to this domain."},
{Name: "ttl_sec", Type: proto.ColumnType_INT, Transform: transform.FromField("TTLSec").NullIfZero(), Description: "Time to Live - the amount of time in seconds that this Domain's records may be cached by resolvers or other domain servers."},
},
}),
}
}

Expand Down
4 changes: 2 additions & 2 deletions linode/table_linode_domain_record.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ func tableLinodeDomainRecord(ctx context.Context) *plugin.Table {
KeyColumns: plugin.AllColumns([]string{"domain_id", "id"}),
Hydrate: getDomainRecord,
},
Columns: []*plugin.Column{
Columns: commonColumns([]*plugin.Column{
// Top columns
{Name: "domain_id", Type: proto.ColumnType_INT, Transform: transform.FromQual("domain_id"), Description: "The ID of the Domain for the record."},
{Name: "id", Type: proto.ColumnType_INT, Description: "This Record’s unique ID."},
Expand All @@ -40,7 +40,7 @@ func tableLinodeDomainRecord(ctx context.Context) *plugin.Table {
{Name: "target", Type: proto.ColumnType_STRING, Description: "The target for this Record. For requests, this property’s actual usage and whether it is required depends on the type of record this represents. For example, for CNAME it is the domain target."},
{Name: "ttl_sec", Type: proto.ColumnType_INT, Transform: transform.FromField("TTLSec").NullIfZero(), Description: "Time to Live - the amount of time in seconds that the domain record may be cached by resolvers or other domain servers."},
{Name: "weight", Type: proto.ColumnType_INT, Description: "The relative weight of this Record used in the case of identical priority. Higher values are preferred. Only valid and required for SRV record requests."},
},
}),
}
}

Expand Down
4 changes: 2 additions & 2 deletions linode/table_linode_event.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ func tableLinodeEvent(ctx context.Context) *plugin.Table {
KeyColumns: plugin.SingleColumn("id"),
Hydrate: getEvent,
},
Columns: []*plugin.Column{
Columns: commonColumns([]*plugin.Column{
// Top columns
{Name: "id", Type: proto.ColumnType_INT, Description: "The unique ID of this Event."},
{Name: "created", Type: proto.ColumnType_TIMESTAMP, Description: "The date and time this event was created."},
Expand All @@ -43,7 +43,7 @@ func tableLinodeEvent(ctx context.Context) *plugin.Table {
{Name: "seen", Type: proto.ColumnType_BOOL, Description: "If this Event has been seen."},
{Name: "secondary_entity", Type: proto.ColumnType_JSON, Description: "Detailed information about the Event's secondary or related entity, including ID, type, label, and URL used to access it."},
{Name: "time_remaining", Type: proto.ColumnType_INT, Description: "The estimated time remaining until the completion of this Event. This value is only returned for in-progress events."},
},
}),
}
}

Expand Down
4 changes: 2 additions & 2 deletions linode/table_linode_image.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ func tableLinodeImage(ctx context.Context) *plugin.Table {
KeyColumns: plugin.SingleColumn("id"),
Hydrate: getImage,
},
Columns: []*plugin.Column{
Columns: commonColumns([]*plugin.Column{
// Top columns
{Name: "id", Type: proto.ColumnType_STRING, Description: "The unique ID of this Image."},
{Name: "label", Type: proto.ColumnType_STRING, Description: "A short description of the Image."},
Expand All @@ -45,7 +45,7 @@ func tableLinodeImage(ctx context.Context) *plugin.Table {
{Name: "is_public", Type: proto.ColumnType_BOOL, Description: "True if the Image is public."},
{Name: "size", Type: proto.ColumnType_INT, Description: "The minimum size this Image needs to deploy. Size is in MB."},
{Name: "vendor", Type: proto.ColumnType_STRING, Description: "The upstream distribution vendor. None for private Images."},
},
}),
}
}

Expand Down
4 changes: 2 additions & 2 deletions linode/table_linode_instance.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ func tableLinodeInstance(ctx context.Context) *plugin.Table {
KeyColumns: plugin.SingleColumn("id"),
Hydrate: getInstance,
},
Columns: []*plugin.Column{
Columns: commonColumns([]*plugin.Column{
// Top columns
{Name: "id", Type: proto.ColumnType_INT, Description: "The unique ID of this Instance."},
{Name: "label", Type: proto.ColumnType_STRING, Description: "The Instance’s label is for display purposes only."},
Expand All @@ -52,7 +52,7 @@ func tableLinodeInstance(ctx context.Context) *plugin.Table {
{Name: "tags_src", Type: proto.ColumnType_JSON, Transform: transform.FromField("Tags"), Description: "List of Tags applied to this instance."},
{Name: "updated", Type: proto.ColumnType_TIMESTAMP, Description: "When this Instance was last updated."},
{Name: "watchdog_enabled", Type: proto.ColumnType_BOOL, Description: "The watchdog, named Lassie, is a Shutdown Watchdog that monitors your Linode and will reboot it if it powers off unexpectedly."},
},
}),
}
}

Expand Down
4 changes: 2 additions & 2 deletions linode/table_linode_kubernetes_cluster.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ func tableLinodeKubernetesCluster(ctx context.Context) *plugin.Table {
KeyColumns: plugin.SingleColumn("id"),
Hydrate: getKubernetesCluster,
},
Columns: []*plugin.Column{
Columns: commonColumns([]*plugin.Column{
// Top columns
{Name: "id", Type: proto.ColumnType_INT, Description: "This Kubernetes cluster’s unique ID."},
{Name: "label", Type: proto.ColumnType_STRING, Description: "This Kubernetes cluster’s unique label for display purposes only."},
Expand All @@ -36,7 +36,7 @@ func tableLinodeKubernetesCluster(ctx context.Context) *plugin.Table {
{Name: "tags", Type: proto.ColumnType_JSON, Transform: transform.FromField("Tags").Transform(transform.StringArrayToMap), Description: "Tags applied to the Kubernetes cluster as a map."},
{Name: "tags_src", Type: proto.ColumnType_JSON, Transform: transform.FromField("Tags"), Description: "List of Tags applied to the Kubernetes cluster."},
{Name: "updated", Type: proto.ColumnType_TIMESTAMP, Description: "When this Kubernetes cluster was updated."},
},
}),
}
}

Expand Down
4 changes: 2 additions & 2 deletions linode/table_linode_profile.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ func tableLinodeProfile(ctx context.Context) *plugin.Table {
List: &plugin.ListConfig{
Hydrate: getProfile,
},
Columns: []*plugin.Column{
Columns: commonColumns([]*plugin.Column{
// Top columns
{Name: "uid", Type: proto.ColumnType_STRING, Description: "Your unique ID in our system. This value will never change, and can safely be used to identify your User."},
{Name: "username", Type: proto.ColumnType_STRING, Description: "Your username, used for logging in to our system."},
Expand All @@ -28,7 +28,7 @@ func tableLinodeProfile(ctx context.Context) *plugin.Table {
{Name: "restricted", Type: proto.ColumnType_BOOL, Description: "If true, your User has restrictions on what can be accessed on your Account."},
{Name: "timezone", Type: proto.ColumnType_STRING, Description: "The timezone you prefer to see times in."},
{Name: "two_factor_auth", Type: proto.ColumnType_BOOL, Description: "If true, logins from untrusted computers will require Two Factor Authentication."},
},
}),
}
}

Expand Down
4 changes: 2 additions & 2 deletions linode/table_linode_region.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,11 @@ func tableLinodeRegion(ctx context.Context) *plugin.Table {
KeyColumns: plugin.SingleColumn("id"),
Hydrate: getRegion,
},
Columns: []*plugin.Column{
Columns: commonColumns([]*plugin.Column{
// Top columns
{Name: "id", Type: proto.ColumnType_STRING, Description: "The region."},
{Name: "country", Type: proto.ColumnType_STRING, Description: "Country for the region."},
},
}),
}
}

Expand Down
4 changes: 2 additions & 2 deletions linode/table_linode_tag.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,10 @@ func tableLinodeTag(ctx context.Context) *plugin.Table {
List: &plugin.ListConfig{
Hydrate: listTag,
},
Columns: []*plugin.Column{
Columns: commonColumns([]*plugin.Column{
// Top columns
{Name: "label", Type: proto.ColumnType_STRING, Description: "A Label used for organization of objects on your Account."},
},
}),
}
}

Expand Down
4 changes: 2 additions & 2 deletions linode/table_linode_token.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ func tableLinodeToken(ctx context.Context) *plugin.Table {
KeyColumns: plugin.SingleColumn("id"),
Hydrate: getToken,
},
Columns: []*plugin.Column{
Columns: commonColumns([]*plugin.Column{
// Top columns
{Name: "label", Type: proto.ColumnType_STRING, Description: "This token's label. This is for display purposes only, but can be used to more easily track what you're using each token for."},
{Name: "token", Type: proto.ColumnType_STRING, Description: "First 16 characters of the token."},
Expand All @@ -29,7 +29,7 @@ func tableLinodeToken(ctx context.Context) *plugin.Table {
{Name: "created", Type: proto.ColumnType_TIMESTAMP, Description: "The date and time this token was created."},
{Name: "expiry", Type: proto.ColumnType_TIMESTAMP, Description: "When this token will expire."},
{Name: "id", Type: proto.ColumnType_INT, Description: "This token's unique ID, which can be used to revoke it."},
},
}),
}
}

Expand Down
4 changes: 2 additions & 2 deletions linode/table_linode_type.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ func tableLinodeType(ctx context.Context) *plugin.Table {
KeyColumns: plugin.SingleColumn("id"),
Hydrate: getType,
},
Columns: []*plugin.Column{
Columns: commonColumns([]*plugin.Column{
// Top columns
{Name: "id", Type: proto.ColumnType_STRING, Description: "The ID representing the Linode Type."},
{Name: "disk", Type: proto.ColumnType_INT, Description: "The Disk size, in MB, of the Linode Type."},
Expand All @@ -32,7 +32,7 @@ func tableLinodeType(ctx context.Context) *plugin.Table {
{Name: "memory", Type: proto.ColumnType_INT, Description: "Amount of RAM included in this Linode Type."},
{Name: "transfer", Type: proto.ColumnType_INT, Description: "The monthly outbound transfer amount, in MB."},
{Name: "vcpus", Type: proto.ColumnType_INT, Transform: transform.FromField("VCPUs"), Description: "The number of VCPU cores this Linode Type offers."},
},
}),
}
}

Expand Down
4 changes: 2 additions & 2 deletions linode/table_linode_user.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,15 +26,15 @@ func tableLinodeUser(ctx context.Context) *plugin.Table {
KeyColumns: plugin.SingleColumn("username"),
Hydrate: getUser,
},
Columns: []*plugin.Column{
Columns: commonColumns([]*plugin.Column{
// Top columns
{Name: "username", Type: proto.ColumnType_STRING, Description: "This User’s username. This is used for logging in, and may also be displayed alongside actions the User performs (for example, in Events or public StackScripts)."},
{Name: "email", Type: proto.ColumnType_STRING, Description: "The email address for this User, for account management communications, and may be used for other communications as configured."},
{Name: "restricted", Type: proto.ColumnType_BOOL, Description: "If true, this User must be granted access to perform actions or access entities on this Account."},
{Name: "ssh_keys", Type: proto.ColumnType_JSON, Description: "A list of SSH Key labels added by this User. These are the keys that will be deployed if this User is included in the authorized_users field of a create Linode, rebuild Linode, or create Disk request."},
// Other columns
{Name: "filter", Type: proto.ColumnType_STRING, Transform: transform.FromQual("filter"), Description: "Raw Linode list filter string in JSON format."},
},
}),
}
}

Expand Down
4 changes: 2 additions & 2 deletions linode/table_linode_volume.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ func tableLinodeVolume(ctx context.Context) *plugin.Table {
KeyColumns: plugin.SingleColumn("id"),
Hydrate: getVolume,
},
Columns: []*plugin.Column{
Columns: commonColumns([]*plugin.Column{
// Top columns
{Name: "id", Type: proto.ColumnType_INT, Description: "The unique ID of this Volume."},
{Name: "label", Type: proto.ColumnType_STRING, Description: "The Volume’s label is for display purposes only."},
Expand All @@ -42,7 +42,7 @@ func tableLinodeVolume(ctx context.Context) *plugin.Table {
{Name: "tags", Type: proto.ColumnType_JSON, Transform: transform.FromField("Tags").Transform(transform.StringArrayToMap), Description: "Tags applied to this volume as a map."},
{Name: "tags_src", Type: proto.ColumnType_JSON, Transform: transform.FromField("Tags"), Description: "List of Tags applied to this volume."},
{Name: "updated", Type: proto.ColumnType_TIMESTAMP, Description: "When this Volume was last updated."},
},
}),
}
}

Expand Down

0 comments on commit ed562ac

Please sign in to comment.