דוגמאות קוד למדיניות אפליקציות

הבקשות הבאות ממחישות איך מנהלים את המדיניות באמצעות Policy API, תוך שימוש במדיניות באפליקציות כדוגמה. לפני שמתחילים, חשוב לעיין בסקירה הכללית על Chrome Policy API ובמדריך לסכימות המדיניות.

כל הבקשות שמוצגות בהמשך משתמשות במשתנים הבאים:

  • $TOKEN – אסימון OAuth 2
  • $CUSTOMER – מספר הלקוח או מספר הלקוח my_customer

חיוב התקנה של אפליקציה

הדוגמאות הבאות מתייחסות ליחידה ארגונית. בקשת Group תהיה זהה, מלבד ה-targetResource, שלפני המזהה שלו יופיעו "groups/" במקום "orgunits/".

כאן אנחנו מגדירים את אפליקציית Google Drawings להתקנה לפי הגדרת האדמין:

curl -X POST \
  -H "Content-Type: application/json" \
  -H "Authorization: Bearer $TOKEN" \
  -d '{
        requests: [{
                policyTargetKey: {
                        targetResource: "orgunits/04fatzly4jbjho9",
                        additionalTargetKeys: {"app_id": "chrome:mkaakpdehdafacodkgkpghoibnmamcme"}
                        },
                policyValue: {
                        policySchema: "chrome.users.apps.InstallType",
                        value: {appInstallType: "FORCED"}
                        },
                updateMask: {paths: "appInstallType"}
                }]
      }' \
  "https://chromepolicy.googleapis.com/v1/customers/$CUSTOMER/policies/orgunits:batchModify"

תגובה מוצלחת צריכה להיות ריקה:

{}

הדוגמה הזו מיועדת לאפליקציית משתמש. בקשה מנוהלת לגלישה כאורח תהיה זהה, אבל סכימת המדיניות תהיה chrome.devices.managedguest.apps.InstallType. בקשת המדיניות המקבילה של אפליקציית "קיוסק":

curl -X POST \
  -H "Content-Type: application/json" \
  -H "Authorization: Bearer $TOKEN" \
  -d '{
        requests: [{
                policyTargetKey: {
                        targetResource: "orgunits/04fatzly4jbjho9",
                        additionalTargetKeys: {"app_id": "chrome:mkaakpdehdafacodkgkpghoibnmamcme"}
                        },
                policyValue: {
                        policySchema: "chrome.devices.kiosk.apps.ForceInstall",
                        value: {forceInstall: false}
                        },
                updateMask: {paths: "forceInstall"}
                }]
      }' \
  "https://chromepolicy.googleapis.com/v1/customers/$CUSTOMER/policies/orgunits:batchModify"

תגובה מוצלחת צריכה להיות ריקה:

{}

מחיקת אפליקציה

מחיקה של אפליקציה צריכה להתבצע ביחידה הארגונית שבה האפליקציה נוספה באופן מפורש לניהול. במהלך הקריאה, השדה addedSourceKey מכיל את היחידה הארגונית שאליה הוא נוסף לצורך ניהול. במילים אחרות, צריך להפעיל את delete רק עבור אפליקציות שבהן היחידה הארגונית ב-addedSourceKey זהה לזו שב-policyTargetKey.

כדי למחוק אפליקציה (להסיר אותה מהניהול באופן מפורש), צריך לשלוח בקשת batchInherit שבה policySchema היא הסכימה של סוג האפליקציה הנתון, עם כוכבית (*) במקום מדיניות ספציפית. בדוגמה הזו אנחנו מוחקים את אפליקציית Google Drawings, שמותקנת ביחידה הארגונית '04fatzly4jbjho9':

curl -X POST \
  -H "Content-Type: application/json" \
  -H "Authorization: Bearer $TOKEN" \
  -d '{
        requests: [{
                policyTargetKey: {
                        targetResource: "orgunits/04fatzly4jbjho9",
                        additionalTargetKeys: {"app_id": "chrome:gbchcmhmhahfdphkhkmpfmihenigjmpp"}
                        },
                policySchema: "chrome.users.apps.*",
                }]
      }' \
  "https://chromepolicy.googleapis.com/v1/customers/$CUSTOMER/policies/orgunits:batchInherit"

תגובה מוצלחת צריכה להיות ריקה:

{}

בקשות למחיקת אפליקציות "קיוסק" ואפליקציות של גלישה מנוהלת כאורחים יתבססו על הסכימות chrome.devices.kiosk.apps.\* ו-chrome.devices.managedguest.apps.\*, בהתאמה.

קבלת מדיניות התקנה של אפליקציה עבור אפליקציה ביחידה ארגונית

כדי לקבל מדיניות לאפליקציה ספציפית, צריך לציין בבקשה את המדיניות וגם את מזהה האפליקציה. בדוגמה הזו אנחנו קוראים את הערך של מדיניות InstallType של אפליקציית Google Drawings:

בקשה

  curl -X POST \
  -H "Content-Type: application/json" \
  -H "Authorization: Bearer $TOKEN" \
  -d '{
        policyTargetKey: {
          targetResource: "orgunits/04fatzly4jbjho9",
          additionalTargetKeys: {"app_id": "chrome:mkaakpdehdafacodkgkpghoibnmamcme"}
        },
        policySchemaFilter: "chrome.users.apps.InstallType"
    }' \
  "https://chromepolicy.googleapis.com/v1/$CUSTOMER/C02l1chq7/policies:resolve"

תשובה

{
  "resolvedPolicies": [
    {
      "targetKey": {
        "targetResource": "orgunits/04fatzly4jbjho9",
        "additionalTargetKeys": {
          "app_id": "chrome:mkaakpdehdafacodkgkpghoibnmamcme"
        }
      },
      "value": {
        "policySchema": "chrome.users.apps.InstallType",
        "value": {
          "appInstallType": "FORCED"
        }
      },
      "sourceKey": {
        "targetResource": "orgunits/04fatzly4jbjho9"
      },
      "addedSourceKey": {
        "targetResource": "orgunits/04fatzly4jbjho9"
      }
    }
  ]
}

קבלת מדיניות התקנה של אפליקציות לכל האפליקציות ביחידה ארגונית

אם מזהה האפליקציה יושמט מהבקשה בדוגמה הקודמת, הוא יהפוך לבקשה לערך של מדיניות סוג ההתקנה עבור כל האפליקציות באותה יחידה ארגונית.

בקשה

  curl -X POST \
  -H "Content-Type: application/json" \
  -H "Authorization: Bearer $TOKEN" \
  -d '{
        policyTargetKey: {
          targetResource: "orgunits/04fatzly4jbjho9",
        },
        policySchemaFilter: "chrome.users.apps.InstallType"
    }' \
  "https://chromepolicy.googleapis.com/v1/$CUSTOMER/C02l1chq7/policies:resolve"

תשובה

{
  "resolvedPolicies": [
    {
      "targetKey": {
        "targetResource": "orgunits/04fatzly4jbjho9",
        "additionalTargetKeys": {
          "app_id": "chrome:mkaakpdehdafacodkgkpghoibnmamcme"
        }
      },
      "value": {
        "policySchema": "chrome.users.apps.InstallType",
        "value": {
          "appInstallType": "FORCED"
        }
      },
      "sourceKey": {
        "targetResource": "orgunits/04fatzly4jbjho9"
      },
      "addedSourceKey": {
        "targetResource": "orgunits/04fatzly4jbjho9"
      }
    },
    {
      "targetKey": {
        "targetResource": "orgunits/04fatzly4jbjho9",
        "additionalTargetKeys": {
          "app_id": "chrome:fhcfdhnmhdkemdfdncjmgnanbekfmbab"
        }
      },
      "value": {
        "policySchema": "chrome.users.apps.InstallType",
        "value": {
          "appInstallType": "ALLOWED"
        }
      },
      "sourceKey": {
        "targetResource": "orgunits/04fatzly4jbjho9"
      },
      "addedSourceKey": {
        "targetResource": "orgunits/04fatzly4jbjho9"
      }
    },
    ...
  ]
}

הצגת רשימה של כל כללי המדיניות של אפליקציה ביחידה הארגונית

ממש כמו שאפשר להשמיט את מזהה האפליקציה מהבקשה לאחזור כללי המדיניות של כל האפליקציות, אפשר גם להשתמש בתו כללי לחיפוש במדיניות כדי לקבל את כל כללי המדיניות של אפליקציה אחת. בדוגמה הזו אנחנו מקבלים את הערכים של כל כללי המדיניות של אפליקציית Google Drawings.

בקשה

  curl -X POST \
  -H "Content-Type: application/json" \
  -H "Authorization: Bearer $TOKEN" \
  -d '{
        policyTargetKey: {
          targetResource: "orgunits/04fatzly4jbjho9",
          additionalTargetKeys: {"app_id": "chrome:mkaakpdehdafacodkgkpghoibnmamcme"}
        },
        policySchemaFilter: "chrome.users.apps.*"
    }' \
  "https://chromepolicy.googleapis.com/v1/$CUSTOMER/C02l1chq7/policies:resolve"

תשובה

{
  "resolvedPolicies": [
    {
      "targetKey": {
        "targetResource": "orgunits/04fatzly4jbjho9",
        "additionalTargetKeys": {
          "app_id": "chrome:mkaakpdehdafacodkgkpghoibnmamcme"
        }
      },
      "value": {
        "policySchema": "chrome.users.apps.InstallType",
        "value": {
          "appInstallType": "FORCED"
        }
      },
      "sourceKey": {
        "targetResource": "orgunits/04fatzly4jbjho9"
      },
      "addedSourceKey": {
        "targetResource": "orgunits/04fatzly4jbjho9"
      }
    },
    {
      "targetKey": {
        "targetResource": "orgunits/04fatzly4jbjho9",
        "additionalTargetKeys": {
          "app_id": "chrome:mkaakpdehdafacodkgkpghoibnmamcme"
        }
      },
      "value": {
        "policySchema": "chrome.users.apps.IncludeInChromeWebStoreCollection",
        "value": {
          "includeInCollection": true
        }
      },
      "sourceKey": {
        "targetResource": "orgunits/04fatzly4jbjho9"
      },
      "addedSourceKey": {
        "targetResource": "orgunits/04fatzly4jbjho9"
      }
    },
    ...
  ]
}

הצגת רשימה של כל כללי המדיניות לכל האפליקציות ביחידה ארגונית

אפשר להשמיט את מזהה האפליקציה ולהשתמש בתו כללי לחיפוש במדיניות כדי לבקש את כל ההגדרות של האפליקציה לכל האפליקציות ביחידה ארגונית.

בקשה

  curl -X POST \
  -H "Content-Type: application/json" \
  -H "Authorization: Bearer $TOKEN" \
  -d '{
        policyTargetKey: {
          targetResource: "orgunits/04fatzly4jbjho9"
        },
        policySchemaFilter: "chrome.users.apps.*"
    }' \
  "https://chromepolicy.googleapis.com/v1/$CUSTOMER/C02l1chq7/policies:resolve"

תשובה

{
  "resolvedPolicies": [
    {
      "targetKey": {
        "targetResource": "orgunits/04fatzly4jbjho9",
        "additionalTargetKeys": {
          "app_id": "chrome:mkaakpdehdafacodkgkpghoibnmamcme"
        }
      },
      "value": {
        "policySchema": "chrome.users.apps.InstallType",
        "value": {
          "appInstallType": "FORCED"
        }
      },
      "sourceKey": {
        "targetResource": "orgunits/04fatzly4jbjho9"
      },
      "addedSourceKey": {
        "targetResource": "orgunits/04fatzly4jbjho9"
      }
    },
    {
      "targetKey": {
        "targetResource": "orgunits/04fatzly4jbjho9",
        "additionalTargetKeys": {
          "app_id": "chrome:mkaakpdehdafacodkgkpghoibnmamcme"
        }
      },
      "value": {
        "policySchema": "chrome.users.apps.IncludeInChromeWebStoreCollection",
        "value": {
          "includeInCollection": true
        }
      },
      "sourceKey": {
        "targetResource": "orgunits/04fatzly4jbjho9"
      },
      "addedSourceKey": {
        "targetResource": "orgunits/04fatzly4jbjho9"
      }
    },
    {
      "targetKey": {
        "targetResource": "orgunits/04fatzly4jbjho9",
        "additionalTargetKeys": {
          "app_id": "chrome:fhcfdhnmhdkemdfdncjmgnanbekfmbab"
        }
      },
      "value": {
        "policySchema": "chrome.users.apps.InstallType",
        "value": {
          "appInstallType": "ALLOWED"
        }
      },
      "sourceKey": {
        "targetResource": "orgunits/04fatzly4jbjho9"
      },
      "addedSourceKey": {
        "targetResource": "orgunits/04fatzly4jbjho9"
      }
    },
    {
      "targetKey": {
        "targetResource": "orgunits/04fatzly4jbjho9",
        "additionalTargetKeys": {
          "app_id": "chrome:fhcfdhnmhdkemdfdncjmgnanbekfmbab"
        }
      },
      "value": {
        "policySchema": "chrome.users.apps.CertificateManagement",
        "value": {
          "allowAccessToKeys": true
        }
      },
      "sourceKey": {
        "targetResource": "orgunits/04fatzly4jbjho9"
      },
      "addedSourceKey": {
        "targetResource": "orgunits/04fatzly4jbjho9"
      }
    },
    ...
  ]
}

ניקוי האפליקציה Kiosk Appsconfig AutoLaunchApp

כדי למחוק את AutoLaunchApp, אפשר להגדיר את appId כ-None.

שימו לב שכאשר מגדירים את appId כ-None, כל ההגדרות האחרות של AutoLaunchApp יוגדרו לערכי ברירת המחדל. במקרה כזה, המערכת תתעלם מהגדרות AutoLaunchApp, מלבד המזהה של האפליקציה שנשלחות בבקשה.

בקשה

curl -X POST \
  -H "Content-Type: application/json" \
  -H "Authorization: Bearer $TOKEN" \
  -d '{
        requests: [{
                policyTargetKey: {
                        targetResource: "orgunits/04fatzly4jbjho9"
                        },
                policyValue: {
                        policySchema: "chrome.devices.kiosk.appsconfig.AutoLaunchApp",
                        value: {appId: "None"}
                        },
                updateMask: {paths: "appId"}
                }]
      }' \
  "https://chromepolicy.googleapis.com/v1/customers/$CUSTOMER/policies/orgunits:batchModify"

תשובה

אין תשובה מוצלחת.

{}