taers232c / GAMADV-XTD3

Command line tool to manage Google Workspace
714 stars 87 forks source link

[FEATURE REQUEST] Partial support for the Channel Services API #258

Closed jay-eleven closed 2 years ago

jay-eleven commented 2 years ago

Hi Ross!

I understand that the target audience for this request is (very) small, but... how feasible is it to implement a handful of read only methods from the Cloud Channel API? These are:

These methods use the https://www.googleapis.com/auth/apps.order scope which is already being used for the Reseller API methods, so it should be easy to integrate them.

Thoughts? 😅

taers232c commented 2 years ago

Jay,

Your list is doable but we;ll need to figure out a way I can test as I'm not a reseller.

Ross

jay-eleven commented 2 years ago

Ross,

I have access to a reseller account, so if you're willing to code, I'm willing to test!

taers232c commented 2 years ago

Now the hard part; naming; accounts and customer are already being used individually. How about?

gam print|show channelcustomers <AccountID>
gam print|show channelentitlements <AccountID> <CustomerID>
gam print|show channeloffers <AccountID>
gam print|show channelproducts <AccountID>
gam print|show channelskus <AccountID> <ProductID>
jay-eleven commented 2 years ago

channelxxxxxx seems the perfect choice. This would be aligned with the Reseller API's resoldxxxxx commands. <AccountID>, <CustomerID> and <ProductID> look like perfectly good parameter names. print|show would need to support JSON output. The standard filter, pageSize, fields, etc... parameters (were available) would still work, right?

taers232c commented 2 years ago
<ChannelCustomerField> ::=
        alternateemail |
        channelpartnerid |
        cloudidentityid |
        cloudidentityinfo |
        createtime |
        domain |
        languagecode |
        name |
        orgdisplayname |
        orgpostaladdress |
        primarycontactinfo |
        updatetime
<ChannelCustomerFieldList> ::= "<ChannelCustomerField>(,<ChannelCustomerField>)*"

gam print channelcustomers [todrive <ToDriveAttribute>*]
        accountid <AccountID> [filter <String>]
        [fields <ChannelCustomerFieldList>]
        [maxresults <Integer>]
        [formatjson [quotechar <Character>]]
gam show channelcustomers
        accountid <AccountID> [filter <String>]
        [fields <ChannelCustomerFieldList>]
        [maxresults <Integer>]
        [formatjson]

<ChannelCustomerEntitlementField> ::=
        associationinfo |
        commitmentsettings |
        createtime |
        name |
        offer |
        parameters |
        provisionedservice |
        provisioningstate |
        purchaseorderid |
        suspensionreasons |
        trialsettings |
        updatetime
<ChannelCustomerEntitlementFieldList> ::= "<ChannelCustomerEntitlementField>(,<ChannelCustomerEntitlementField>)*"

gam print channelcustomercentitlements [todrive <ToDriveAttribute>*]
        (accountid <AccountID> customerid <CustomerID>)|(name accounts/<AccountID/customers/<CustomerID>)
        [fields <ChannelCustomerEntitlementsFieldList>]
        [maxresults <Integer>]
        [formatjson [quotechar <Character>]]
gam show channelcustomerentitlements
        (accountid <AccountID> customerid <CustomerID>)|(name accounts/<AccountID/customers/<CustomerID>)
        [fields <ChannelCustomerEntitlementsFieldList>]
        [maxresults <Integer>]
        [formatjson]

<ChannelCustomerOfferField> ::=
        constraints |
        endtime |
        marketinginfo |
        name |
        parameterdefinitions |
        plan |
        pricebyresources |
        sku |
        starttime
<ChannelOfferFieldList> ::= "<ChannelOfferField>(,<ChannelOfferField>)*"

gam print channeloffers [todrive <ToDriveAttribute>*]
        accountid <AccountID> [filter <String>] [language <LanguageCode]
        [fields <ChannelOfferFieldList>]
        [maxresults <Integer>]
        [formatjson [quotechar <Character>]]
gam show channeloffers
        accountid <AccountID> [filter <String>] [language <LanguageCode]
        [fields <ChannelOfferFieldList>]
        [maxresults <Integer>]
        [formatjson]

<ChannelProductField> ::=
        marketinginfo |
        name
<ChannelProductFieldList> ::= "<ChannelProductField>(,<ChannelProductField>)*"

gam print channelproducts [todrive <ToDriveAttribute>*]
        accountid <AccountID> [language <LanguageCode]
        [fields <ChannelProductFieldList>]
        [maxresults <Integer>]
        [formatjson [quotechar <Character>]]
gam show channelproducts
        accountid <AccountID> [language <LanguageCode]
        [fields <ChannelProductFieldList>]
        [maxresults <Integer>]
        [formatjson]

<ChannelSKUField> ::=
        marketinginfo |
        name |
        product
<ChannelSKUFieldList> ::= "<ChannelSKUField>(,<ChannelSKUField>)*"

gam print channelskus [todrive <ToDriveAttribute>*]
        accountid <AccountID> [language <LanguageCode] [productid <ProductID>]
        [fields <ChannelSKUFieldList>]
        [maxresults <Integer>]
        [formatjson [quotechar <Character>]]
gam show channelskus
        accountid <AccountID> [language <LanguageCode] [productid <ProductID>]
        [fields <ChannelSKUFieldList>]
        [maxresults <Integer>]
        [formatjson]
jay-eleven commented 2 years ago

This looks awesome!

Minor typos:

Hmmmm... How can I test? 🫣

taers232c commented 2 years ago

Go here: https://github.com/taers232c/GAMADV-XTD3/releases/edit/untagged-79d2c4b53e0146b59041 Grab a version At the moment, the Mac Version won't build.

gam update project gam oauth create

In addition to testing if the command works, test giving invalid AccountIDs, customerIDs and ProductIDS.

jay-eleven commented 2 years ago

Mmmm... The link doesn't work for me: I get a 404. Maybe lack of permissions? 😅

taers232c commented 2 years ago

https://github.com/taers232c/GAMADV-XTD3/releases

Download from the 6.18.00 Draft.

jay-eleven commented 2 years ago

On it!

jay-eleven commented 2 years ago

OK, I'm in business:

jay@cloudshell:~/gambeta$ ./gambeta
GAMADV-XTD3 6.18.00 - https://github.com/taers232c/GAMADV-XTD3 - pyinstaller
Ross Scroggs <ross.scroggs@gmail.com>
Python 3.10.3 64-bit final
Linux Debian 11 Bullseye x86_64
Path: /home/jay/gambeta
Config File: /home/jay/.gam/gam.cfg, Section: reseller, customer_id: my_customer, domain:
Help: Syntax in file /home/jay/gambeta/GamCommands.txt
Help: Documentation is at https://github.com/taers232c/GAMADV-XTD3/wiki

Extracted new gam to its own dir to make sure it's the one I use.

jay@cloudshell:~/gambeta$ ./gambeta show channelcustomers accountid ThisWillError
Channel Customer: accounts/ThisWillError, Show Failed: <eye3 title='/AuthzService.BatchCheckPrivileges, INVALID_ARGUMENT'/> APPLICATION_ERROR;google.internal.cloud.channel.v1/AuthzService.BatchCheckPrivileges;CustomerId : ThisWillError is invalid.
com.google.apps.framework.request.BadRequestException: CustomerId : ThisWillError is invalid.;AppErrorCode=3;StartTimeMs=1648481251973;unknown;ResFormat=AUTOMATIC;ServerTimeSec=0.009914624;LogBytes=256;FailFast;EffSecLevel=none;ReqFormat=AUTOMATIC;ReqID=6ef3a456b15b1545;GlobalID=0;Server=[::1]:0
jay@cloudshell:~/gambeta$

Good, the API is set up, scopes are granted and gam works correctly when a fake accountid is used. I've found some things that need fixing/tuning. How do you want me to report back? In this same thread? Should I compile my findings/tests in a separate doc I share with you?

taers232c commented 2 years ago

In print channelcustomerentitlements,

In print channelskus, try with invalid productid, e,g,, productid nv:xxxxxx

taers232c commented 2 years ago

Jay,

Email me suggestions; we can certainly Meet/Zoom as well to discuss.

jay-eleven commented 2 years ago

Super impressed! Almost everything works and I just found very minor nuances. Good job!! 👏

channelcustomers

name,marketingInfo.displayName
products/UADAVyrVqM6grP/skus/S6sH51ibL9dQY8,Google Workspace Enterprise Starter
products/UADAVyrVqM6grP/skus/SEVlaChVhiSE2J,Google Workspace Business Plus
[...]

accountid

The accountid parameter should be optional for gam. If not present, pull the customer_id variable from the gam.cfg file, it will work.

command syntax mismatch

Please, let me know if you need help updating the docs to remove SKU, Product...

taers232c commented 2 years ago

Thanks for the detailed info.

Do you have a moment for a Meet?

taers232c commented 2 years ago

New Draft posted at 4:20PM PDT.

For print channelcustomerentitlements, I need an accountID and customerID. Should the customerID default to gam.cfg/customer_id?

taers232c commented 2 years ago

Would it make sense to replace <AccountID> with <ResellerID> and add reseller_id to gam.cfg?

taers232c commented 2 years ago

Get latest draft 2022-02-28 08:56 PDT Added reseller_id to gam.cfg Replaced accountid <AccountID> with resellerid <ResellerID>; default is gam.cfg/reseller_id if defined, else gam.cfg/customer_id

jay-eleven commented 2 years ago

Hi Ross! My timezone is GMT+2, so bear with me if I'm not responsive at times... 😅 I posted my report just before going to bed... 😴

Added reseller_id to gam.cfg Replaced accountid with resellerid ; default is gam.cfg/reseller_id if defined, else gam.cfg/customer_id

This is the most flexible solution. I don't think it's needed, but having it is the safest bet. Let me test and I'll report back.

Getting latest draft and testing...

taers232c commented 2 years ago

Get new draft, 2022-03-29, 10:12 PDT

Fixes getting a list of fields

jay-eleven commented 2 years ago

Here it goes.

accountid -> resellerid

I've tried several combinations and everything works as expected. Defaulting to gam.cfg/customer_id if gam.cfg/reseller_id is not defined works as expected.

channelcustomers

Everything works as expected except:

channelcustomerentitlements

Everything works as expected except:

channeloffers

Everything works as expected except:

channelproducts

Everything works as expected except:

channelskus

Everything works as expected except:

jay-eleven commented 2 years ago

Oh! I'll get the new draft!

taers232c commented 2 years ago

Show me the command line for channelcustomers filter

See: https://github.com/taers232c/GAMADV-XTD3/wiki/Cloud-Channel#display-channel-customers

jay-eleven commented 2 years ago

./gambeta show channelcustomers filter cloud_identity_id="someid"

taers232c commented 2 years ago

This is a command line issue, not a GAM issue: Linux/MacOS ./gambeta show channelcustomers filter 'cloud_identity_id="someid"'

Windows Command Prompt ./gambeta show channelcustomers filter "cloud_identity_id=\"someid\""

Windows PowerShell ./gambeta show channelcustomers filter 'cloud_identity_id=\"someid\"'

jay-eleven commented 2 years ago

I can confirm filter works: ./gambeta print channelcustomers filter 'domain:"something*" AND org_display_name:"something_else *"' prints what it should

Testing fields...

jay-eleven commented 2 years ago

Added filter examples to docs

jay-eleven commented 2 years ago

Almost done!!!

fields in channel* show commands doesn't work. Eg. ./gambeta show channeloffers fields name:

  File "__init__.py", line 61417, in ProcessGAMCommand
  File "__init__.py", line 13250, in doPrintShowChannelOffers
  File "__init__.py", line 13144, in doPrintShowChannelItems
AttributeError: 'NoneType' object has no attribute 'AddField'

fields in channel* print commands almost works. Eg. ./gambeta print channel* fields name:

name,sku,startTime,endTime
accounts/someId/offers/S07jzJ4lP,,,
accounts/someId/offers/S0NnUiMpU,,,
accounts/someId/offers/S0b3RL2be,,,
accounts/someId/offers/S085nsuak,,,
[...]

Extra field names and , printed. Expected output:

name
accounts/someId/offers/S07jzJ4lP
accounts/someId/offers/S0NnUiMpU
accounts/someId/offers/S0b3RL2be
accounts/someId/offers/S085nsuak
[...]
taers232c commented 2 years ago

Have you finished testing, should I publish?

jay-eleven commented 2 years ago

fields needs some love yet... 😅

taers232c commented 2 years ago

OK, I'll wait for further news. Thanks for all of your help.

jay-eleven commented 2 years ago

Check my latest report on fields just before you asked if you could publish: https://github.com/taers232c/GAMADV-XTD3/issues/258#issuecomment-1082235463

taers232c commented 2 years ago

On the case.

taers232c commented 2 years ago

New draft available.

On Tue, Mar 29, 2022 at 11:36 AM Jay @.***> wrote:

Check my latest report on fields just before you asked if you could publish: #258 (comment) https://github.com/taers232c/GAMADV-XTD3/issues/258#issuecomment-1082235463

— Reply to this email directly, view it on GitHub https://github.com/taers232c/GAMADV-XTD3/issues/258#issuecomment-1082240636, or unsubscribe https://github.com/notifications/unsubscribe-auth/ACCTYL2WHDEYRCOFAQ6VIVDVCNEUFANCNFSM5RXDTQDQ . You are receiving this because you commented.Message ID: @.***>

-- Ross Scroggs @.***

jay-eleven commented 2 years ago

On it

jay-eleven commented 2 years ago

Everything works! Great job Ross! 👍

taers232c commented 1 year ago

Published.

Thanks

On Tue, Mar 29, 2022 at 12:53 PM Jay @.***> wrote:

Everything works! Great job Ross! 👍

— Reply to this email directly, view it on GitHub https://github.com/taers232c/GAMADV-XTD3/issues/258#issuecomment-1082312958, or unsubscribe https://github.com/notifications/unsubscribe-auth/ACCTYL5BTHRU5LTBTEA5FUDVCNNTTANCNFSM5RXDTQDQ . You are receiving this because you commented.Message ID: @.***>

-- Ross Scroggs @.***