Skip to content

Commit

Permalink
Merge pull request #1 from hanneshayashi/0.2.5
Browse files Browse the repository at this point in the history
0.2.5
  • Loading branch information
hanneshayashi committed Mar 30, 2021
2 parents e9aabef + fde63c4 commit f755182
Show file tree
Hide file tree
Showing 744 changed files with 11,804 additions and 2,085 deletions.
11 changes: 7 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -70,13 +70,16 @@ GSM currently supports the following APIs:
Most of these APIs allow you to manage multiple object types with each object type allowing multiple operations.\
Overall, GSM supports over **65 [main commands](https://gsm.hayashi-ke/gsm)**, with each one representing an API with multiple methods and each method implemented as a sub command. This amounts to over **500 commands in total**, including over **200 ["batch" commands](https://gsm.hayashi-ke.online/batch_commands)** that allow you to utilize CSV files to apply updates to multiple objects in a multi-threaded manner and over **30 ["recursive" commands](https://gsm.hayashi-ke.online/recursive_commands)** that allow you to apply updates to multiple users in one command, by specifying one or more organizational unit(s) (OUs) and/or group(s).

You can use GSM in one of two modes
You can use GSM in one of three modes
- user: User mode allows you to use any Google account (even private ones) to access the APIs.\
Note that you will only have access to the resources and APIs your account can access!
- dwd: DWD (Domain Wide Delegation) allows you to utilize a GCP service account to impersonate user accounts in a Workspace domain.\
You need to add the service account and the appropriate scopes in the Admin Console of your Workspace domain to us this mode.
- adc: ADC ("Application Default Credentials") mode works like DWD mode, but it allows you to utilize Application Default Credentials, such as the implicit credentials of a Compute Engine instance's Service Account or the "application-default" credentials of the Google Cloud SDK (gcloud), to impersonate a Service Account. This means you don't have to manage Service Account key files.

You can set up multiple configurations using [gsm configs](https://gsm.hayashi-ke.online/gsm/configs) and switch between them using [gsm configs load](https://gsm.hayashi-ke.online/gsm/configs/load) or by specifying the name of the config with the `--config` flag.
See [Setup](https://gsm.hayashi-ke.online/setup) on how to set up GSM in these modes.

You can also set up multiple configurations using [gsm configs](https://gsm.hayashi-ke.online/gsm/configs) and switch between them using [gsm configs load](https://gsm.hayashi-ke.online/gsm/configs/load) or by specifying the name of the config with the `--config` flag.

### Output

Expand All @@ -93,7 +96,7 @@ GSM works nicely with PowerShell's ConvertFrom-Json commandlet (although there a

You can take a look at some examples under [scripting](https://gsm.hayashi-ke.online/scripting).

You can also try the auto-generated [PowerShell module](https://github.com/hanneshayashi/gsm_crescendo).\
You can also try the auto-generated [PowerShell module](https://github.com/hanneshayashi/gsm-powershell).\
Note that this module is created with [Crescendo](https://github.com/PowerShell/Crescendo), which is also still in beta. However, for an auto-generated module, it seems to work reasonably well. The module also automatically utilizes streaming.

#### Logging
Expand All @@ -110,4 +113,4 @@ You can also use the [log command](https://gsm.hayashi-ke.online/gsm/log) to vie
* [Recursive commands](https://gsm.hayashi-ke.online/recursive_commands) - How to use recursive commands
* [Examples](https://gsm.hayashi-ke.online/examples) - See some examples
* [Scripting examples](https://gsm.hayashi-ke.online/scripting) - Some examples on how to use GSM in scripts
* [PowerShell module](https://github.com/hanneshayashi/gsm_crescendo) - Auto-generated PowerShell module
* [PowerShell module](https://github.com/hanneshayashi/gsm-powershell) - Auto-generated PowerShell module
9 changes: 7 additions & 2 deletions cmd/about.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
package cmd

import (
"log"

"github.com/hanneshayashi/gsm/gsmhelpers"

"github.com/spf13/cobra"
Expand All @@ -30,8 +32,11 @@ var aboutCmd = &cobra.Command{
Long: `This API only works with the currently authenticated user!
https://developers.google.com/drive/api/v3/reference/about`,
DisableAutoGenTag: true,
Run: func(cmd *cobra.Command, args []string) {
cmd.Help()
Run: func(cmd *cobra.Command, _ []string) {
err := cmd.Help()
if err != nil {
log.Fatalln(err)
}
},
}

Expand Down
7 changes: 5 additions & 2 deletions cmd/about_get.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,13 +32,16 @@ var aboutGetCmd = &cobra.Command{
Short: "Gets information about the user, the user's Drive, and system capabilities.",
Long: "https://developers.google.com/drive/api/v3/reference/about/get",
DisableAutoGenTag: true,
Run: func(cmd *cobra.Command, args []string) {
Run: func(cmd *cobra.Command, _ []string) {
flags := gsmhelpers.FlagsToMap(cmd.Flags())
result, err := gsmdrive.GetAbout(flags["fields"].GetString())
if err != nil {
log.Fatalf("Error getting about information: %v", err)
}
gsmhelpers.Output(result, "json", compressOutput)
err = gsmhelpers.Output(result, "json", compressOutput)
if err != nil {
log.Fatalln(err)
}
},
}

Expand Down
12 changes: 9 additions & 3 deletions cmd/activities.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
package cmd

import (
"log"

"github.com/hanneshayashi/gsm/gsmhelpers"

"github.com/spf13/cobra"
Expand All @@ -29,8 +31,11 @@ var activitiesCmd = &cobra.Command{
Short: "Manage (list) activities (Part of Admin SDK)",
Long: "https://developers.google.com/admin-sdk/reports/reference/rest/v1/activities?hl=en",
DisableAutoGenTag: true,
Run: func(cmd *cobra.Command, args []string) {
cmd.Help()
Run: func(cmd *cobra.Command, _ []string) {
err := cmd.Help()
if err != nil {
log.Fatalln(err)
}
},
}

Expand Down Expand Up @@ -168,7 +173,8 @@ Format: "id:abc123,id:xyz456"`,
See https://developers.google.com/gdata/docs/2.0/basics#PartialResponse for more information.`,
},
}
var activityFlagsALL = gsmhelpers.GetAllFlags(activityFlags)

// var activityFlagsALL = gsmhelpers.GetAllFlags(activityFlags)

func init() {
rootCmd.AddCommand(activitiesCmd)
Expand Down
12 changes: 9 additions & 3 deletions cmd/activities_list.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,20 +35,26 @@ For more information, see the guides for administrator and Google Drive activity
For more information about the activity report's parameters, see the activity parameters reference guides.`,
Long: "https://developers.google.com/admin-sdk/reports/reference/rest/v1/activities/list",
DisableAutoGenTag: true,
Run: func(cmd *cobra.Command, args []string) {
Run: func(cmd *cobra.Command, _ []string) {
flags := gsmhelpers.FlagsToMap(cmd.Flags())
result, err := gsmreports.ListActivities(flags["userKey"].GetString(), flags["applicationName"].GetString(), flags["actorIpAddress"].GetString(), flags["customerId"].GetString(), flags["endTime"].GetString(), flags["eventName"].GetString(), flags["filters"].GetString(), flags["groupIdFilter"].GetString(), flags["orgUnitId"].GetString(), flags["startTime"].GetString(), flags["fields"].GetString(), gsmhelpers.MaxThreads(0))
if streamOutput {
enc := gsmhelpers.GetJSONEncoder(false)
for i := range result {
enc.Encode(i)
err := enc.Encode(i)
if err != nil {
log.Println(err)
}
}
} else {
final := []*reports.Activity{}
for i := range result {
final = append(final, i)
}
gsmhelpers.Output(final, "json", compressOutput)
err := gsmhelpers.Output(final, "json", compressOutput)
if err != nil {
log.Fatalln(err)
}
}
e := <-err
if e != nil {
Expand Down
9 changes: 7 additions & 2 deletions cmd/asps.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
package cmd

import (
"log"

"github.com/hanneshayashi/gsm/gsmhelpers"

"github.com/spf13/cobra"
Expand All @@ -36,8 +38,11 @@ https://http//support.google.com/a/bin/answer.py?amp;answer=1032419.
https://developers.google.com/admin-sdk/directory/v1/reference/asps`,
DisableAutoGenTag: true,
Run: func(cmd *cobra.Command, args []string) {
cmd.Help()
Run: func(cmd *cobra.Command, _ []string) {
err := cmd.Help()
if err != nil {
log.Fatalln(err)
}
},
}

Expand Down
7 changes: 5 additions & 2 deletions cmd/asps_delete.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,13 +32,16 @@ var aspsDeleteCmd = &cobra.Command{
Short: "Delete an ASP issued by a user.",
Long: "https://developers.google.com/admin-sdk/directory/v1/reference/asps/delete",
DisableAutoGenTag: true,
Run: func(cmd *cobra.Command, args []string) {
Run: func(cmd *cobra.Command, _ []string) {
flags := gsmhelpers.FlagsToMap(cmd.Flags())
result, err := gsmadmin.DeleteAsp(flags["userKey"].GetString(), flags["codeId"].GetInt64())
if err != nil {
log.Fatalf("Error deleting ASP: %v", err)
}
gsmhelpers.Output(result, "json", compressOutput)
err = gsmhelpers.Output(result, "json", compressOutput)
if err != nil {
log.Fatalln(err)
}
},
}

Expand Down
12 changes: 9 additions & 3 deletions cmd/asps_delete_batch.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ var aspsDeleteBatchCmd = &cobra.Command{
"crescendoAttachToParent": "true",
},
DisableAutoGenTag: true,
Run: func(cmd *cobra.Command, args []string) {
Run: func(cmd *cobra.Command, _ []string) {
maps, err := gsmhelpers.GetBatchMaps(cmd, aspFlags)
if err != nil {
log.Fatalln(err)
Expand Down Expand Up @@ -71,14 +71,20 @@ var aspsDeleteBatchCmd = &cobra.Command{
if streamOutput {
enc := gsmhelpers.GetJSONEncoder(false)
for r := range results {
enc.Encode(r)
err := enc.Encode(r)
if err != nil {
log.Println(err)
}
}
} else {
final := []resultStruct{}
for res := range results {
final = append(final, res)
}
gsmhelpers.Output(final, "json", compressOutput)
err := gsmhelpers.Output(final, "json", compressOutput)
if err != nil {
log.Fatalln(err)
}
}
},
}
Expand Down
7 changes: 5 additions & 2 deletions cmd/asps_get.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,13 +32,16 @@ var aspsGetCmd = &cobra.Command{
Short: "Get information about an ASP issued by a user.",
Long: "https://developers.google.com/admin-sdk/directory/v1/reference/asps/get",
DisableAutoGenTag: true,
Run: func(cmd *cobra.Command, args []string) {
Run: func(cmd *cobra.Command, _ []string) {
flags := gsmhelpers.FlagsToMap(cmd.Flags())
result, err := gsmadmin.GetAsp(flags["userKey"].GetString(), flags["fields"].GetString(), flags["codeId"].GetInt64())
if err != nil {
log.Fatalf("Error getting ASP: %v", err)
}
gsmhelpers.Output(result, "json", compressOutput)
err = gsmhelpers.Output(result, "json", compressOutput)
if err != nil {
log.Fatalln(err)
}
},
}

Expand Down
12 changes: 9 additions & 3 deletions cmd/asps_get_batch.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ var aspsGetBatchCmd = &cobra.Command{
"crescendoAttachToParent": "true",
},
DisableAutoGenTag: true,
Run: func(cmd *cobra.Command, args []string) {
Run: func(cmd *cobra.Command, _ []string) {
maps, err := gsmhelpers.GetBatchMaps(cmd, aspFlags)
if err != nil {
log.Fatalln(err)
Expand Down Expand Up @@ -66,14 +66,20 @@ var aspsGetBatchCmd = &cobra.Command{
if streamOutput {
enc := gsmhelpers.GetJSONEncoder(false)
for r := range results {
enc.Encode(r)
err := enc.Encode(r)
if err != nil {
log.Println(err)
}
}
} else {
final := []*admin.Asp{}
for res := range results {
final = append(final, res)
}
gsmhelpers.Output(final, "json", compressOutput)
err := gsmhelpers.Output(final, "json", compressOutput)
if err != nil {
log.Fatalln(err)
}
}
},
}
Expand Down
12 changes: 9 additions & 3 deletions cmd/asps_list.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ var aspsListCmd = &cobra.Command{
Short: "List the ASPs issued by a user.",
Long: "https://developers.google.com/admin-sdk/directory/v1/reference/asps/list",
DisableAutoGenTag: true,
Run: func(cmd *cobra.Command, args []string) {
Run: func(cmd *cobra.Command, _ []string) {
flags := gsmhelpers.FlagsToMap(cmd.Flags())
result, err := gsmadmin.ListAsps(flags["userKey"].GetString(), flags["fields"].GetString())
if err != nil {
Expand All @@ -41,10 +41,16 @@ var aspsListCmd = &cobra.Command{
if streamOutput {
enc := gsmhelpers.GetJSONEncoder(false)
for i := range result {
enc.Encode(result[i])
err = enc.Encode(result[i])
if err != nil {
log.Println(err)
}
}
} else {
gsmhelpers.Output(result, "json", compressOutput)
err = gsmhelpers.Output(result, "json", compressOutput)
if err != nil {
log.Fatalln(err)
}
}
},
}
Expand Down
12 changes: 9 additions & 3 deletions cmd/asps_list_batch.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ var aspsListBatchCmd = &cobra.Command{
"crescendoAttachToParent": "true",
},
DisableAutoGenTag: true,
Run: func(cmd *cobra.Command, args []string) {
Run: func(cmd *cobra.Command, _ []string) {
maps, err := gsmhelpers.GetBatchMaps(cmd, aspFlags)
if err != nil {
log.Fatalln(err)
Expand Down Expand Up @@ -71,14 +71,20 @@ var aspsListBatchCmd = &cobra.Command{
if streamOutput {
enc := gsmhelpers.GetJSONEncoder(false)
for r := range results {
enc.Encode(r)
err := enc.Encode(r)
if err != nil {
log.Println(err)
}
}
} else {
final := []resultStruct{}
for res := range results {
final = append(final, res)
}
gsmhelpers.Output(final, "json", compressOutput)
err := gsmhelpers.Output(final, "json", compressOutput)
if err != nil {
log.Fatalln(err)
}
}
},
}
Expand Down
12 changes: 9 additions & 3 deletions cmd/asps_list_recursive.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ var aspsListRecursiveCmd = &cobra.Command{
"crescendoAttachToParent": "true",
},
DisableAutoGenTag: true,
Run: func(cmd *cobra.Command, args []string) {
Run: func(cmd *cobra.Command, _ []string) {
flags := gsmhelpers.FlagsToMap(cmd.Flags())
threads := gsmhelpers.MaxThreads(flags["batchThreads"].GetInt())
type resultStruct struct {
Expand Down Expand Up @@ -69,14 +69,20 @@ var aspsListRecursiveCmd = &cobra.Command{
if streamOutput {
enc := gsmhelpers.GetJSONEncoder(false)
for r := range results {
enc.Encode(r)
err := enc.Encode(r)
if err != nil {
log.Println(err)
}
}
} else {
final := []resultStruct{}
for r := range results {
final = append(final, r)
}
gsmhelpers.Output(final, "json", compressOutput)
err := gsmhelpers.Output(final, "json", compressOutput)
if err != nil {
log.Fatalln(err)
}
}
},
}
Expand Down
9 changes: 7 additions & 2 deletions cmd/attachments.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
package cmd

import (
"log"

"github.com/hanneshayashi/gsm/gsmhelpers"

"github.com/spf13/cobra"
Expand All @@ -29,8 +31,11 @@ var attachmentsCmd = &cobra.Command{
Short: "Manage (get..) message attachements (Part of Gmail API)",
Long: "https://developers.google.com/gmail/api/reference/rest/v1/users.messages.attachments",
DisableAutoGenTag: true,
Run: func(cmd *cobra.Command, args []string) {
cmd.Help()
Run: func(cmd *cobra.Command, _ []string) {
err := cmd.Help()
if err != nil {
log.Fatalln(err)
}
},
}

Expand Down
7 changes: 5 additions & 2 deletions cmd/attachments_get.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,13 +32,16 @@ var attachmentsGetCmd = &cobra.Command{
Short: "Gets the specified message attachment.",
Long: "https://developers.google.com/gmail/api/reference/rest/v1/users.messages.attachments/get",
DisableAutoGenTag: true,
Run: func(cmd *cobra.Command, args []string) {
Run: func(cmd *cobra.Command, _ []string) {
flags := gsmhelpers.FlagsToMap(cmd.Flags())
result, err := gsmgmail.GetAttachment(flags["userId"].GetString(), flags["messageId"].GetString(), flags["id"].GetString(), flags["fields"].GetString())
if err != nil {
log.Fatalf("Error getting attachment with id %s: %v", flags["id"].GetString(), err)
}
gsmhelpers.Output(result, "json", compressOutput)
err = gsmhelpers.Output(result, "json", compressOutput)
if err != nil {
log.Fatalln(err)
}
},
}

Expand Down
Loading

0 comments on commit f755182

Please sign in to comment.