Git Product home page Git Product logo

turbot / steampipe-plugin-googleworkspace Goto Github PK

View Code? Open in Web Editor NEW
18.0 11.0 3.0 325 KB

Use SQL to instantly query calendar events, drive files, gmail messages, and more from Google Workspace. Open source CLI. No DB required.

Home Page: https://hub.steampipe.io/plugins/turbot/googleworkspace

License: Apache License 2.0

Makefile 0.13% PLSQL 1.63% Go 98.23%
sql postgresql google-workspace steampipe steampipe-plugin postgresql-fdw gmail-api calendar-api drive-api hacktoberfest

steampipe-plugin-googleworkspace's Introduction

image

Google Workspace Plugin for Steampipe

Use SQL to query users, groups, org units and more from your Google Workspace.

Quick start

Install the plugin with Steampipe:

steampipe plugin install googleworkspace

Configure your credentials and config file.

Run a query:

select
  summary,
  hangout_link,
  start_time,
  end_time
from
  googleworkspace_calendar_my_event
where
  start_time > now()::timestamp
  and end_time < ('now'::timestamp + interval '1 day');

Engines

This plugin is available for the following engines:

Engine Description
Steampipe The Steampipe CLI exposes APIs and services as a high-performance relational database, giving you the ability to write SQL-based queries to explore dynamic data. Mods extend Steampipe's capabilities with dashboards, reports, and controls built with simple HCL. The Steampipe CLI is a turnkey solution that includes its own Postgres database, plugin management, and mod support.
Postgres FDW Steampipe Postgres FDWs are native Postgres Foreign Data Wrappers that translate APIs to foreign tables. Unlike Steampipe CLI, which ships with its own Postgres server instance, the Steampipe Postgres FDWs can be installed in any supported Postgres database version.
SQLite Extension Steampipe SQLite Extensions provide SQLite virtual tables that translate your queries into API calls, transparently fetching information from your API or service as you request it.
Export Steampipe Plugin Exporters provide a flexible mechanism for exporting information from cloud services and APIs. Each exporter is a stand-alone binary that allows you to extract data using Steampipe plugins without a database.
Turbot Pipes Turbot Pipes is the only intelligence, automation & security platform built specifically for DevOps. Pipes provide hosted Steampipe database instances, shared dashboards, snapshots, and more.

Developing

Prerequisites:

Clone:

git clone https://github.com/turbot/steampipe-plugin-googleworkspace.git
cd steampipe-plugin-googleworkspace

Build, which automatically installs the new version to your ~/.steampipe/plugins directory:

make

Configure the plugin:

cp config/* ~/.steampipe/config
vi ~/.steampipe/config/googleworkspace.spc

Try it!

steampipe query
> .inspect googleworkspace

Further reading:

Open Source & Contributing

This repository is published under the Apache 2.0 (source code) and CC BY-NC-ND (docs) licenses. Please see our code of conduct. We look forward to collaborating with you!

Steampipe is a product produced from this open source software, exclusively by Turbot HQ, Inc. It is distributed under our commercial terms. Others are allowed to make their own distribution of the software, but cannot use any of the Turbot trademarks, cloud services, etc. You can learn more in our Open Source FAQ.

Get Involved

Join #steampipe on Slack →

Want to help but don't know where to start? Pick up one of the help wanted issues:

steampipe-plugin-googleworkspace's People

Contributors

cbruno10 avatar dependabot[bot] avatar judell avatar misraved avatar subhajit97 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

steampipe-plugin-googleworkspace's Issues

Add table googleworkspace_gmail_labels (and my_labels)

Not super-high-pri, here is how I'm handling this now. Labels change infrequently, it's easy to capture them with a one-off API call, so not a terrible solution.

create or replace function gmail_labels () 
  returns table (label jsonb ) as $$
  -- from https://developers.google.com/gmail/api/reference/rest/v1/users.labels/list
  select jsonb_array_elements('[
		{ "id": "CHAT", "name": "CHAT" },
		{ "id": "SENT", "name": "SENT" },
		{ "id": "INBOX", "name": "INBOX" },
		{ "id": "IMPORTANT", "name": "IMPORTANT" },
		{ "id": "TRASH", "name": "TRASH" },
		{ "id": "DRAFT", "name": "DRAFT" },
		{ "id": "SPAM", "name": "SPAM" },
		{ "id": "CATEGORY_FORUMS", "name": "CATEGORY_FORUMS"  },
		{ "id": "CATEGORY_UPDATES", "name": "CATEGORY_UPDATES"  },
		{ "id": "CATEGORY_PERSONAL", "name": "CATEGORY_PERSONAL"  },
		{ "id": "CATEGORY_PROMOTIONS", "name": "CATEGORY_PROMOTIONS"  },
		{ "id": "CATEGORY_SOCIAL", "name": "CATEGORY_SOCIAL"  },
		{ "id": "STARRED", "name": "STARRED" },
		{ "id": "UNREAD", "name": "UNREAD"  },
		{ "id": "Label_17", "name": "elmcity" },
		{ "id": "Label_19", "name": "letters" },
		{ "id": "Label_22", "name": "radar" },
		{ "id": "Label_23", "name": "school" },
		{ "id": "Label_24", "name": "screencast" },
		{ "id": "Label_26", "name": "timO" },
		{ "id": "Label_27", "name": "toMe" },
		{ "id": "Label_28", "name": "travel" },
		{ "id": "Label_29", "name": "Notes"  },
		{ "id": "Label_30", "name": "heartbeat" }
    ]' :: jsonb)
$$ language sql;

create or replace function gmail_name_for_label_id (label_id text) returns text as $$
  select label ->> 'name'
  from gmail_labels()
  where label ->> 'id' = label_id
$$ language sql;

can we use the refresh token in ./config/gcloud/application_default_credentials.json?

I am using method 2 from https://hub.steampipe.io/plugins/turbot/googleworkspace. I acquire the credentials file like so:

gcloud auth application-default login --client-id-file=client_secret.json --scopes="https://www.googleapis.com/auth/calendar.readonly,https://www.googleapis.com/auth/contacts.other.readonly,https://www.googleapis.com/auth/contacts.readonly,https://www.googleapis.com/auth/directory.readonly,https://www.googleapis.com/auth/drive.readonly,https://www.googleapis.com/auth/gmail.readonly,https://www.googleapis.com/auth/spreadsheets.readonly"

After a couple of days this happens:

googleapi: Error 401: Request had invalid authentication credentials. Expected OAuth 2 access token, login cookie or other valid authentication credential.

I can, and do, reacquire the credentials file. But there's a refresh token in it, shouldn't the underlying Go SDK use that to refresh the access token?

per @cbruno10:

here’s a possibly relevant discussion from the SDK repo - googleapis/google-api-go-client#111

If that works it will also benefit the Google Directory and Google Sheets plugins.

Improve filtering in tables that support query filters

Is your feature request related to a problem? Please describe.
For tables that return large sets of data, it'll be faster and less expensive if we look at any query columns and build filters where possible before making the API requests.

Describe the solution you'd like
Add automatic filtering capabilities in tables based on quals.

Describe alternatives you've considered
Use the query column (or similar ones) when making queries.

Additional context
Add any other context or screenshots about the feature request here.

Add support for OAuth 2.0 client authorization

Is your feature request related to a problem? Please describe.
I'd like to be able to authorize in the plugin using OAuth 2.0 client credentials

Describe the solution you'd like
Implement support for OAuth authorization, with docs + config file support.

Describe alternatives you've considered
A clear and concise description of any alternative solutions or features you've considered.

Additional context
Add any other context or screenshots about the feature request here.

Extend googleworkspace settings attribute for Drive and Docs.

Is your feature request related to a problem? Please describe.
To satisfy the need of CIS v1.0.0 section 4

e.g. Link sharing default, Shared drive creation, Security update for files, Target audiences, Sharing options

image
Describe the solution you'd like
A clear and concise description of what you want to happen.

Describe alternatives you've considered
A clear and concise description of any alternative solutions or features you've considered.

Additional context
https://developers.google.com/admin-sdk/directory/reference/rest
Need to revalidate the API support for this

Use of tilde in the token_path parameter of the config file does not work

Describe the bug
When tilde(~) in the token_path parameter which is set in the googleworkspace.spc file then running a query returns cannot read credentials file: open ~/.config/gcloud/application_default_credentials.json: no such file or directory error

Steampipe version (steampipe -v)
Example: v0.10.0

Plugin version (steampipe plugin list)
Example: v0.0.3

To reproduce

  1. After following the steps of using OAuth client, we need to add the default path to the token_path parameter in the .spc file
  2. Running any query pertaining to googleworkspace tables will return cannot read credentials file: open ~/.config/gcloud/application_default_credentials.json: no such file or directory error

Expected behavior
Using ~/.config/gcloud/application_default_credentials.json as the token_path parameter should work without any errors and we should be able to query the googleworkspace tables

Additional context
Note: Providing the full path for home (without using tilde works correctly)

Add support for inline credentials via `credentials` argument in connection config

Is your feature request related to a problem? Please describe.
I would like to be able to specify the service account credentials inline in the config file, not in an external json file.

Describe the solution you'd like
Add support for a credentials argument in the connection config to allow a user to specify either the path to or the contents of a service account key file in JSON format. This should look roughly like the credentials arg in the Terraform google provider

After this is implemented, we may want to deprecate credential_file as it would be redundant at that point.

Update Google Workspace tables to return error if service API is disabled, instead of returning empty row

Describe the bug
googleworkspace_* returning empty row, if the corresponding service API is disabled.

Steampipe version (steampipe -v)
Example: v0.8.5

Plugin version (steampipe plugin list)
Example: v0.0.2

To reproduce

  • Disable the corresponding service API (i.e. Gmail API).
  • Run any query (select id, thread_id from googleworkspace_gmail_my_message)

Expected behavior
If the resources can't exist because the API is disabled then return zero rows. But if resources can be created while the API is disabled then we should return an error.

Additional context
N/A

Can't find gmail messages

Describe the bug
I can't find emails on gmail at all. Only return an empty set

Steampipe version (steampipe -v)
steampipe version 0.6.2

Plugin version (steampipe plugin list)
googleworkspace v0.0.2

To reproduce

steampipe query "select
       id,
       thread_id,
       internal_date,
       size_estimate,
       snippet
     from
       googleworkspace_gmail_my_message
     order by internal_date
     limit 10;
     "
+----+-----------+---------------+---------------+---------+
| id | thread_id | internal_date | size_estimate | snippet |
+----+-----------+---------------+---------------+---------+
+----+-----------+---------------+---------------+---------+

Expected behavior
To see 10 e-mails from my mailbox

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.