ããã«ã¡ã¯ãData Division ã® id:beniyama ã§ãã
ä»å㯠Looker Advent Calendar 2019 ï¼æ¥ç®ã®è¨äºã¨ãã¦ãæè¿ Looker 6.22 ã¨ãã¦ãªãªã¼ã¹ããã Looker Python SDK ã使ã£ãã¢ã«ã¦ã³ã管çã®å¹çåäºä¾ããç´¹ä»ãã¾ãã
ã¢ã«ã¦ã³ãã¯ã«ã¸ã¥ã¢ã«ã«çºè¡ãã¦ä½¿ããªããããªãåæ¢ããã
エンジニアを魅了する次世代 BI ツール『Looker』を Quipper が導入した理由(わけ) - スタディサプリ Product Team Blog ããæ©ï¼å¹´ä½ã社å ã§çºè¡ãã¦ãã Looker ã¢ã«ã¦ã³ããé 調ã«å¢å ããä»ã§ã¯çµæ§ãªå²åã®ã¡ã³ãã¼ã Looker ãè¦ããããã«ãªãã¾ããã
æ¯æ¥ãã°ã¤ã³ãã¦æ¥ã ã®ææ決å®ã«ä½¿ã£ã¦ããã¡ã³ãã¼ãå¢ãã¦ããä¸æ¹ã§ãã¢ã«ã¦ã³ãç³è«ãã¦ã¿ããã®ã®ç¶ç¶çã«ãã°ã¤ã³ããã«ã¯è³ãããç¡æ²æ±°ã«ãªã£ã¦ãã¾ã人ãããã®ãäºå®ã§ãã
ã³ã¹ã管çãè¡ã£ã¦ããéç¨å´ã¨ãã¦ã¯å¥ç´ãã¦ããã¢ã«ã¦ã³ãæ°ã«å¯¾ããæ´»ç¨çã®æ大åãç®æãããã®ã§ããããã¨ãã£ã¦äºåæ¿èªã®ããã¼ãéããã¦å ¥ãå£ãçããã¨ãããã¨ã¯ãã¦ãã¾ããã
ããã¼ã¿ã®æ°ä¸»åããæ¨é²ããããã«ã¯ã端çã«è¨ãã¨ããã¤ã§ãä¼ããããã·ã¥ãã¼ãããããã®ï¼å°ç·çã«ãå¿ççã«ãï¼è¦ªè¿æããããã¨ã大äºã ã¨æã£ã¦ãã¾ãã
ã§ãã®ã§ã代ããã«ãã¨ããããã«ã¸ã¥ã¢ã«ã«ã¢ã«ã¦ã³ãçºè¡ããããã§ãä¸å®æé使ããªãã¨åæ¢ï¼Disableï¼ããããã¾ã使ããããªã£ãã復活ç³è«ãã¦ãï¼ãã¨ããããªã·ã¼ã§éç¨ããã¦ãã¾ããåé¤ããªãã¦ãä¸æ¦åæ¢ã¨ããç¶æ ãæã¦ãã®ãè¯ãã§ããã
ä¸å³ã®ããã« Google ãã©ã¼ã ããå¿ è¦äºé ãè¨å ¥ãã¦ããããç³è«ãæ¥ã㨠Slack ã§éç¥ãæ¥ãããã«ãã¦ãã¾ããä»åãç´¹ä»ãã SDK ã使ãã¨ãã®è¾ºã®æ°è¦ã¦ã¼ã¶ã¼ä½æããã³æ¨©éä»ä¸ãå®å ¨èªååãå¯è½ã§ãã®ã§ãããããããããã£ã¦ããããã§ãã
Python SDK ã使ã£ã¦ä¸å®æéãã°ã¤ã³ã®ãªãã¢ã«ã¦ã³ããåæ¢ãã
ãã¨ã㨠120% ã«ãã¬ãã¸ãæ¨æ¦ãã¦ãããããå å®ãã¦ãã Looker ã® API ã§ãããå æ¥å ¬éããã 6.22 ã§ã¯ Python ã Javascript & Typescript ã® SDK ãæä¾ãããããã«ãªãã¾ããã
ä¾ãã° Python ã® SDK 㯠looker-sdk · PyPI ã«è©³ãã説æãããã¾ãã
ãã¦ä»åã¯
- å ¨ã¦ã® Looker ã¢ã«ã¦ã³ãæ å ±ãåå¾
- ãã°ã¤ã³æ¸ã¿ãã©ããããã§ãã¯ããã¦ãããæçµãã°ã¤ã³æ¥ãåå¾
- æçµãã°ã¤ã³æ¥ãæå®ãããæéï¼ããã©ã«ãã§ã¯ 180 æ¥ï¼ããåã§ããã°åæ¢ï¼
disable
ç¶æ ã«å¤æ´ï¼ - ã¤ãã§ã«ä»ã©ãã ãã¢ã«ã¦ã³ããçºè¡ããã¦ãããããã¼ã«ãã¨ã«ã«ã¦ã³ã
ãããããªã¹ã¯ãªãããä½ã£ã¦ããã¾ãã
èªè¨¼æ å ±ã looker.ini ã¨ãã¦è¨è¼
sdk-codegen/python at main · looker-open-source/sdk-codegen · GitHub ã«ãè¨è¼ãããã¾ãããLooker å´ã§çºè¡ãã API key ãã¨ã³ããã¤ã³ãã looker.ini
ã¨ãã¦æå®ããã¹ã¯ãªããä¸ãããããèªã¿è¾¼ã¾ãã¾ãã
[Looker] # API version is required api_version=3.1 # Base URL for API. Do not include /api/* in the url base_url=https://YourLookerDomain.looker.com:19999 # API 3 client id client_id=YourClientID # API 3 client secret client_secret=YourClientSecret # Set to false if testing locally against self-signed certs. Otherwise leave True verify_ssl=True
ç¹ã«é£ããã¨ããã¯ãªãã§ããã
ãã¡ããã¨èªã¾ã以åã®ã³ã¼ããã³ããããéã«ãµããã£ã¬ã¯ããªä»¥éãæå®ãã¦ãã¾ã£ã¦è»½ããããã¾ããâ¦
ã¹ã¯ãªããå´ã§ã¯
from looker_sdk import client, models sdk = client.setup("looker.ini")
ã¨ãã¦èªè¨¼ãå®æ½ãã¾ãã
SDK è¶ãã«æ å ±ãåå¾ãã
ä¾ãã°ã
my_id = sdk.me(fields="id")
ãªã©ã¨ããã¨èªåèªèº«ã® Looker ã¢ã«ã¦ã³ã ID ãåå¾ã§ãã¾ããèªåãåæ¢ãããã¨ãå¯è½ãªã®ãã¡ãã£ã¨ãããã¾ããããä¸ãä¸ã«ã§ã disable ã«ãã¦ãã¾ãã¨ç®ãå½ã¦ãããªãã®ã§èªåãä½è ãªã®ãææ¡ãã¦ããã¾ãã
ä»ã«ã
all_users = sdk.all_users()
ãªã©ã¨ããã¨å ¨ã¦ã¼ã¶ã¼ã®ãªã¹ããåå¾ã§ãã¾ãã
ä¾ãã°ãã®ãªã¹ãããªãã¦ä¸è¨ã®ããã«ãã㨠Looker 社å´ã®ã¢ã«ã¦ã³ããã©ãããèå¥ãããã¨ãå¯è½ã§ãã
for user in all_users: if user.presumed_looker_employee: looker_user_cnt += 1
åæ¢ããã¦ããï¼disabled ãªï¼ã¢ã«ã¦ã³ããã©ããã¯
user.is_disabled
ã§åå¾ã§ãã¾ãã
ã©ããã£ãããããã£ããããã¯ãä¾ãã°ã¦ã¼ã¶ã¼å¨ãã§ããã° Looker API Interactive Reference ãè¦ãã¨ãããããã¾ãã
ã¦ã¼ã¶ã¼ã®æçµãã°ã¤ã³ã«ã¤ãã¦ã¯
user.credentials_email.logged_in_at
ã§åå¾ãå¯è½ã§ãããããã§æ³¨æãå¿
è¦ãªã®ã¯ä¸è¨ã¯ credentials_email
ãã¤ã¾ã email + ãã¹ã¯ã¼ãã«ãããã°ã¤ã³ã«ã¤ãã¦ã®æ
å ±ã®ã¿ã¨ãªãã¾ãã
ã§ãã®ã§ãä»ã®ãã°ã¤ã³ç¨®å¥ããµãã¼ããã¦ããå ´å㯠credentials_google
ã credentials_ldap
ãªã©ãè¦ãå¿
è¦ãããã¨æãã¾ãï¼åèï¼ã
SDK è¶ãã«ã¦ã¼ã¶ã¼ã®ç¶æ ãå¤æ´ãã
ä»åã¯ç¹å®ã®ã¦ã¼ã¶ã¼ã® is_disabled
ãã©ã°ãç«ã¦ããã®ã§ãä¸è¨ã®ããã«ãã¾ãã
sdk.update_user(user.id, body=models.WriteUser(is_disabled=True))
ã¨ã¦ãç°¡åã§ããã
å®è¡çµæ
ãã®ã¹ã¯ãªãããå®è¡ããã¨ä¸è¨ã®ãããªçµæãåºåããã¾ãã
$ pipenv run python disable_users.py XXX XXXX ([email protected])'s last login date is 2019-05-31 00:00:00 (189 days before). Disable the user ?? y/N >>y ...successfully disabled. XXX XXXX ([email protected])'s last login date is 2019-05-15 00:00:00 (205 days before). Disable the user ?? y/N >> ...skipped. XXX XXXX ([email protected])'s last login date is 2018-12-14 00:00:00 (357 days before). Disable the user ?? y/N >> ...skipped. XXX XXXX ([email protected])'s last login date is 2019-05-23 00:00:00 (197 days before). Disable the user ?? y/N >> ...skipped. XXX XXXX ([email protected])'s last login date is 2019-06-03 00:00:00 (186 days before). Disable the user ?? y/N >> ...skipped. ----------------------------- ---------- Summary ---------- ----------------------------- Total registered users: XXX (incl. 7 looker people) Active users: XXX No login users: 0 ----------------------------- Users disabled in this operation: 1 Errors: 0 ----------------------------- Admin : XX User : XX Developer : XX -----------------------------
ç¾ç¶ã¯é次 yes or no ã®ç¢ºèªã¤ã³ããããå ¥ãã¦ãã¾ãããåçç¡ç¨ã§å¼·å¶åæ¢ã«ããã®ã§ããã°ãããåãã¦æ¯æ¥åããã¨ãã§ãã¾ãã
ã¾ããç¾å¨ã® Looker ã®ç®¡çç»é¢ã§ã¯èª°ãã©ãã®ãã¼ã«ã«ãã¦ãããããã®ãã¼ã«ãå®éä½äººãªã®ãææ¡ãã¥ãããã¨ããããå©ç¨å®ç¸¾ã¨å¥ç´æ ãè¦æ¯ã¹ãããããããã«ä»åãã¼ã«ãã¨ã®éè¨æ©è½ãã¤ãã§ã«å ¥ãã¾ããã
ã¾ã¨ã
ä½ã大ããªãã¥ã¼ã¹ã«ãªã£ã¦ãã¾ããããå ¬å¼ã« SDK ããµãã¼ãããããã¨ã§ API ã使ã£ãæ§ã ãªéç¨æ¥åã®èªååãä¸æ®µã¨è¡ãããããªãã¾ããã
ä»å¾ã¯ã¢ã«ã¦ã³ãçºè¡ã®èªååããã®ãªã³ãã¼ãã£ã³ã°ä½é¨ã®åä¸ãSlack éç¥ãªã©ã«ããåæ¢åã®ãªãã¤ã³ãã»å©ç¨åèµ·ãªã©æ§ã ãªæ½çãæã£ã¦ãå©ç¨çã®ãããªãåä¸ãç®æãããã¨æãã¾ãã
ä»åä½æãããµã³ãã«ã³ã¼ã
ä»åä½æããã¹ã¯ãªããã¯ä¸è¨ Gist ã«å ¬éãã¦ãã¾ãã
ãã¨ãã¨ã¯ä»¥åããå ¬éããã¦ãã https://github.com/llooker/python_api_samples/blob/master/disable_users.py ãåèã«éçºãããã®ã§ãä»åã® Python SDK ãªãªã¼ã¹ãæ©ã«åæãæ¸ãæãã¦ãã¾ãã
ã¾ããç°å¢æ§ç¯å¨ãã¯ãã¡ããã覧ãã ããã