דוגמאות קוד

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

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

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

הצגת רשימה של סכימות לכללי מדיניות למדפסות

כדי לרשום סכימות שרלוונטיות רק לכללי מדיניות בנושא מדפסות, נחיל את ההגדרה filter לבקשת הרשימה של Schema Service. אפשר לשלוט בעימוד של התוצאה באמצעות הפרמטרים pageSize ו-pageToken.

בקשה

  curl -X GET \
  -H "Authorization: Bearer $TOKEN" \
  "https://chromepolicy.googleapis.com/v1/customers/$CUSTOMER/policySchemas?filter=chrome.printers&pageSize=2"

תשובה

{
  "policySchemas": [
    {
      "name": "customers/C0202nabg/policySchemas/chrome.printers.AllowForUsers",
      "policyDescription": "Allows a printer for users in a given organization.",
      "additionalTargetKeyNames": [
        {
          "key": "printer_id",
          "keyDescription": "Id of printer as visible in Admin SDK printers API."
        }
      ],
      "definition": {
        "messageType": [
          {
            "name": "AllowForUsers",
            "field": [
              {
                "name": "allowForUsers",
                "number": 1,
                "label": "LABEL_OPTIONAL",
                "type": "TYPE_BOOL"
              }
            ]
          }
        ]
      },
      "fieldDescriptions": [
        {
          "field": "allowForUsers",
          "description": "Controls whether a printer is allowed for users in a given organization."
        }
      ],
      "schemaName": "chrome.printers.AllowForUsers"
    },
    {
      "name": "customers/C0202nabg/policySchemas/chrome.printers.AllowForDevices",
      "policyDescription": "Allows a printer for devices in a given organization.",
      "additionalTargetKeyNames": [
        {
          "key": "printer_id",
          "keyDescription": "Id of printer as visible in Admin SDK printers API."
        }
      ],
      "definition": {
        "messageType": [
          {
            "name": "AllowForDevices",
            "field": [
              {
                "name": "allowForDevices",
                "number": 1,
                "label": "LABEL_OPTIONAL",
                "type": "TYPE_BOOL"
              }
            ]
          }
        ]
      },
      "fieldDescriptions": [
        {
          "field": "allowForDevices",
          "description": "Controls whether a printer is allowed for devices in a given organization."
        }
      ],
      "schemaName": "chrome.printers.AllowForDevices"
    }
  ],
  "nextPageToken": "AEbDN_obE8A98T8YhIeU9VCIZhEBylLBwZRQpGu_DUug-mU4bnzcDx30UnO2xMuuImvfVpmeuXRF6VhJ4OmZpZ4H6EaRvu2qMOPxVN_u"
}

חיפוש סכימות

אפשר ליצור שאילתות חיפוש מורכבות באמצעות הפרמטר filter= בסכימה בקשה לרשימת שירותים. לדוגמה אם רוצים לחפש סכימות שמכילות את המילה "מדפסת" בשם ובמילה "מכשירים" בתיאור שאפשר להחיל את הערך הבא במסנן name=printers AND description=devices.

איך יוצרים רשימה של סכימות של מדיניות

בקשה

  curl -X GET \
  -H "Authorization: Bearer $TOKEN" \
  "https://chromepolicy.googleapis.com/v1/customers/$CUSTOMER/policySchemas?filter=name=printers%20AND%20description=devices"

תשובה

{
  "policySchemas": [
    {
      "name": "customers/C0202nabg/policySchemas/chrome.printers.AllowForDevices",
      "policyDescription": "Allows a printer for devices in a given organization.",
      "additionalTargetKeyNames": [
        {
          "key": "printer_id",
          "keyDescription": "Id of printer as visible in Admin SDK printers API."
        }
      ],
      "definition": {
        "messageType": [
          {
            "name": "AllowForDevices",
            "field": [
              {
                "name": "allowForDevices",
                "number": 1,
                "label": "LABEL_OPTIONAL",
                "type": "TYPE_BOOL"
              }
            ]
          }
        ]
      },
      "fieldDescriptions": [
        {
          "field": "allowForDevices",
          "description": "Controls whether a printer is allowed for devices in a given organization."
        }
      ],
      "schemaName": "chrome.printers.AllowForDevices"
    }
  ]
}

אחזור של סכימה ספציפית

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

הנה דוגמה לסכימה של chrome.printers.AllowForUsers.

בקשה

  curl -X GET \
  -H "Authorization: Bearer $TOKEN" \
  "https://chromepolicy.googleapis.com/v1/customers/$CUSTOMER/policySchemas/chrome.printers.AllowForUsers"

תשובה

{
  "name": "customers/C0202nabg/policySchemas/chrome.printers.AllowForUsers",
  "policyDescription": "Allows a printer for users in a given organization.",
  "additionalTargetKeyNames": [
    {
      "key": "printer_id",
      "keyDescription": "Id of printer as visible in Admin SDK printers API."
    }
  ],
  "definition": {
    "messageType": [
      {
        "name": "AllowForUsers",
        "field": [
          {
            "name": "allowForUsers",
            "number": 1,
            "label": "LABEL_OPTIONAL",
            "type": "TYPE_BOOL"
          }
        ]
      }
    ]
  },
  "fieldDescriptions": [
    {
      "field": "allowForUsers",
      "description": "Controls whether a printer is allowed for users in a given organization."
    }
  ],
  "schemaName": "chrome.printers.AllowForUsers"
}

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

קריאת ערך מדיניות

עכשיו נקרא את המדיניות chrome.printers.AllowForUsers לגבי מדפסת ספציפית. הודעה על שימוש בשדה additionalTargetKeys כדי לציין את מזהה המדפסת בבקשה.

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

תוכלו לראות את השדה sourceKey, שמציין הערך של המדיניות לפי יחידה ארגונית או קבוצה. עבור היחידות הארגוניות הן:

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

עבור קבוצות Google, מפתח המקור יהיה תמיד זהה לקבוצה שהייתה שצוינו בבקשה.

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

בקשה

  curl -X POST \
  -H "Content-Type: application/json" \
  -H "Authorization: Bearer $TOKEN" \
  -d '{
        policyTargetKey: {
          targetResource: "orgunits/04fatzly4jbjho9",
          additionalTargetKeys: {"printer_id":"0gjdgxs208tpef"}
        },
        policySchemaFilter: "chrome.printers.AllowForDevices"
    }' \
  "https://chromepolicy.googleapis.com/v1/customers/$CUSTOMER/policies:resolve"

תשובה

{
  "resolvedPolicies": [
    {
      "targetKey": {
        "targetResource": "orgunits/03ph8a2z1xdnme9"
        "additionalTargetKeys": {"printer_id":"0gjdgxs208tpef"}
      },
      "value": {
        "policySchema": "chrome.users.AllowForDevices",
        "value": {
          "allowForDevices": true
        }
      },
      "sourceKey": {
        "targetResource": "orgunits/03ph8a2z3qhz81k"
      }
    }
  ]
}

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

קריאה של כמה כללי מדיניות

הוספת מרחב שמות של סכימה עם כוכבית (למשל, chrome.printers.*) מותר לקרוא את הערכים של כל כללי המדיניות במרחב השמות הזה יחידה ארגונית או קבוצה. מידע נוסף על סכימות מדיניות

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

בקשה

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

תשובה

{
  "resolvedPolicies": [
    {
      "targetKey": {
        "targetResource": "orgunits/04fatzly4jbjho9",
        "additionalTargetKeys": {
          "printer_id": "0gjdgxs0xd59y1"
        }
      },
      "value": {
        "policySchema": "chrome.printers.AllowForUsers",
        "value": {
          "allowForUsers": false
        }
      }
    },
    {
      "targetKey": {
        "targetResource": "orgunits/04fatzly4jbjho9",
        "additionalTargetKeys": {
          "printer_id": "0gjdgxs0xd59y1"
        }
      },
      "value": {
        "policySchema": "chrome.printers.AllowForDevices",
        "value": {
          "allowForDevices": false
        }
      }
    },
    //...
  ],
  "nextPageToken": "AEbDN_pFvDeGSbQDkvMxr4UA0Ew7UEUw8aJyw95VPs2en6YxMmFcWQ9OQQEIeSkjnWFCQNyz5GGoOKQGEd50e2z6WqvM2w7sQz6TMxVOBD_4NmEHRWtIJCYymeYXWHIrNH29Ezl1wkeyYBAOKnE="
}

שינוי הערך במדיניות

כפי שמופיע בתגובה של סכימת המדיניות, המדיניות chrome.printers.AllowForUsers מכיל שדה אחד בשם allowForUsers. השדה הזה הוא מסוג בוליאני. דוגמה הערך של המדיניות יכול להיות {allowForUsers: false} או {allowForUsers: true}. במקרה הספציפי הזה, יש לנו רק שדה אחד, עם זאת, כללי מדיניות אחרים עשויים להכיל מספר שדות.

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

הדוגמאות הבאות מתייחסות ליחידה ארגונית. בקשות קבוצתיות הן זהה, למעט ה- targetResource, שכולל את המחרוזת "groups/ " במקום "orgunits/ " לפני המזהה. כאן לא נאפשר מדפסת 0gjdgxs208tpef עבור משתמשים במזהה היחידה הארגונית 04fatzly4jbjho9:

בקשה

curl -X POST \
  -H "Content-Type: application/json" \
  -H "Authorization: Bearer $TOKEN" \
  -d '{
        requests: [{
                policyTargetKey: {
                        targetResource: "orgunits/04fatzly4jbjho9",
                        additionalTargetKeys: {"printer_id":"0gjdgxs208tpef"}
                        },
                policyValue: {
                        policySchema: "chrome.printers.AllowForUsers",
                        value: {allowForUsers: false}
                        },
                updateMask: {paths: "allowForUsers"}
                }]
      }' \
  "https://chromepolicy.googleapis.com/v1/customers/$CUSTOMER/policies/orgunits:batchModify"

תשובה

התגובה שהתקבלה ריקה.

{}

שדות מרובי-ערכים, כמו רשימות או מערכים, מסומנים בתווית "LABEL_REPEATED" התיוג. כדי לאכלס שדות מרובי ערכים, צריך להשתמש בפורמט הבא של מערך JSON: [value1, value2, value3, ...]

לדוגמה, כדי להגדיר כתובות URL של מקורות עבור חבילות של אפליקציות ותוספים בתור "test1.com", "test2.com" ו-"test3.com", עלינו לשלוח את הבקשה הבאה:

בקשה

curl -X POST \
  -H "Content-Type: application/json" \
  -H "Authorization: Bearer $TOKEN" \
  -d "{
        requests: [
          {
            policy_target_key: {
              target_resource: 'orgunits/03ph8a2z28rz85a'
            },
            updateMask: {
              paths: ['extensionInstallSources']
            },
            policy_value: {
              policy_schema: 'chrome.users.appsconfig.AppExtensionInstallSources', 
              value: {
                extensionInstallSources: ['test1.com', 'test2.com', 'test3.com']
              }
            }
          }
        ]
      }" \
  "https://chromepolicy.googleapis.com/v1/customers/$CUSTOMER/policies/orgunits:batchModify"

תשובה

התגובה שהתקבלה ריקה.

{}

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

בקשה

curl -X POST \
  -H "Content-Type: application/json" \
  -H "Authorization: Bearer $TOKEN" \
  -d "{
        requests: [
          {
            policy_target_key: {
              target_resource: 'orgunits/03ph8a2z28rz85a'
            },
            updateMask: {
              paths: ['sessionDurationLimit']
            },
            policy_value: {
              policy_schema: 'chrome.users.SessionLengthV2',
              value: {
                sessionDurationLimit: {
                  duration: 10
                }
              }
            }
          }
        ]
      }" \
  "https://chromepolicy.googleapis.com/v1/customers/$CUSTOMER/policies/orgunits:batchModify"

תשובה

התגובה שהתקבלה ריקה.

{}

שינוי של כמה כללי מדיניות בבת אחת

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

בדוגמה הזאת נשנה, באותה בקשה, שני עקרונות מדיניות (chrome.printers.AllowForDevices ו-chrome.printers.AllowForUsers) עבור אותה מדפסת.

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

בקשה

curl -X POST \
  -H "Content-Type: application/json" \
  -H "Authorization: Bearer $TOKEN" \
  -d '{
        requests: [{
                policyTargetKey: {
                        targetResource: "orgunits/04fatzly4jbjho9",
                        additionalTargetKeys: {"printer_id":"0gjdgxs208tpef"}
                        },
                policyValue: {
                        policySchema: "chrome.printers.AllowForDevices",
                        value: {allowForDevices: true}
                        },
                updateMask: {paths: "allowForDevices"}
                },
                {
                policyTargetKey: {
                        targetResource: "orgunits/04fatzly4jbjho9",
                        additionalTargetKeys: {"printer_id":"0gjdgxs208tpef"}
                        },
                policyValue: {
                        policySchema: "chrome.printers.AllowForUsers",
                        value: {allowForUsers: true}
                        },
                updateMask: {paths: "allowForUsers"}
                }]
      }' \
  "https://chromepolicy.googleapis.com/v1/customers/C0202nabg/policies/orgunits:batchModify"

תשובה

התגובה שהתקבלה ריקה.

{}

ירושה של ערך מדיניות ביחידה ארגונית

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

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

בקשה

curl -X POST \
  -H "Content-Type: application/json" \
  -H "Authorization: Bearer $TOKEN" \
  -d '{
        requests: [{
                policyTargetKey: {
                        targetResource: "orgunits/04fatzly12wd3ox",
                        additionalTargetKeys: {"printer_id":"0gjdgxs208tpef"}
                        },
                policySchema: "chrome.printers.AllowForUsers"
                }]
      }' \
  "https://chromepolicy.googleapis.com/v1/customers/$CUSTOMER/policies/orgunits:batchInherit"

תשובה

התגובה שהתקבלה ריקה.

{}

מחיקת ערך מדיניות בקבוצה

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

השיטה batchDelete מאפשרת גם לשלוח מספר מחיקה של מדיניות בו-זמנית. עם זאת, לא ניתן לקבץ את כל כללי המדיניות. פרטים נוספים זמינים במאמר מדיניות העדכונים ב-Batch.

בקשה

curl -X POST \
  -H "Content-Type: application/json" \
  -H "Authorization: Bearer $TOKEN" \
  -d '{
        requests: [{
                policyTargetKey: {
                        targetResource: "groups/04fatzly12wd3ox",
                        additionalTargetKeys: {"printer_id":"0gjdgxs208tpef"}
                        },
                policySchema: "chrome.printers.AllowForUsers"
                }]
      }' \
  "https://chromepolicy.googleapis.com/v1/customers/$CUSTOMER/policies/groups:batchDelete"

תשובה

התגובה שהתקבלה ריקה.

{}

הצגת רשימה של סדר העדיפויות של הקבוצה

listGroupPriorityOrdering מאפשרת לרשום את סדר העדיפות של קבוצות Google עבור אפליקציה מסוימת.

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

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

בבקשה הזו, אנחנו מחזירים את סדר העדיפות עבור האפליקציה exampleapp אפליקציית משתמש Chrome.

בקשה

curl -X POST \
  -H "Content-Type: application/json" \
  -H "Authorization: Bearer $TOKEN" \
  -d '{
        policyTargetKey: {
                additionalTargetKeys: {"app_id":"chrome:exampleapp"}
                },
        policyNamespace: 'chrome.users.apps'
      }' \
  "https://chromepolicy.googleapis.com/v1/customers/$CUSTOMER/policies/groups:listGroupPriorityOrdering"

תשובה

{
  "policyTargetKey": {
    "additionalTargetKeys": {
      "app_id": "chrome:exampleapp"
    }
  },
  "policyNamespace": "chrome.users.apps",
  "groupIds": [
    "03ep43zb2k1nodu",
    "01t3h5sf2k52kol",
    "03q5sasy2ihwnlz"
  ]
}

עדכון סדר העדיפות של קבוצה

updateGroupPriorityOrdering מאפשרת לעדכן את סדר העדיפות של קבוצות Google עבור אפליקציה מסוימת.

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

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

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

בקשה

curl -X POST \
  -H "Content-Type: application/json" \
  -H "Authorization: Bearer $TOKEN" \
  -d '{
        policyTargetKey: {
                additionalTargetKeys: {"app_id":"chrome:exampleapp"}
                },
        policyNamespace: 'chrome.users.apps',
        groupIds: ['03ep43zb2k1nodu', '01t3h5sf2k52kol', '03q5sasy2ihwnlz']
      }' \
  "https://chromepolicy.googleapis.com/v1/customers/$CUSTOMER/policies/groups:updateGroupPriorityOrdering"

תשובה

התגובה שהתקבלה ריקה.

{}

טיפול בכללי מדיניות שדורשים אישור

חלק מסכימות המדיניות מציינות 'notices' עבור ערכים מסוימים בשדה מסוים שמצריכות אישור.

דוגמה למדיניות chrome.users.PluginVmAllowd:

{
  "name": "customers/C0202nabg/policySchemas/chrome.users.PluginVmAllowed",
  "policyDescription": "Parallels Desktop.",
  # ...
  "fieldDescriptions": [
    {
      "field": "pluginVmAllowed",
      "description": "N/A",
      "knownValueDescriptions": [
        {
          "value": "true",
          "description": "Allow users to use Parallels Desktop."
        },
        {
          "value": "false",
          "description": "Do not allow users to use Parallels Desktop."
        }
      ]
    },
    {
      "field": "ackNoticeForPluginVmAllowedSetToTrue",
      "description": "This field must be set to true to acknowledge the notice message associated with the field 'plugin_vm_allowed' set to value 'true'. Please see the notices listed with this policy for more information."
    }
  ],
  "notices": [
    {
      "field": "pluginVmAllowed",
      "noticeValue": "true",
      "noticeMessage": "By enabling Parallels Desktop, you agree to the Parallels End-User License Agreement specified at https://www.parallels.com/about/legal/eula/. Warning: Device identifiers may be shared with Parallels. Please see privacy policy for more details at https://www.parallels.com/about/legal/privacy/. The minimum recommended configuration includes an i5 processor, 16 GB RAM, and 128 GB storage: https://support.google.com/chrome/a/answer/10044480.",
      "acknowledgementRequired": true
    }
  ],
  "supportUri": "...",
  "schemaName": "chrome.users.PluginVmAllowed"
}

בדוגמה שלמעלה, הגדרת הערך של השדה pluginVmAllowed כ-true היא שמשויכת להודעה עם acknowledgementRequired. כדי לפתור את הבעיה אם הערך בשדה הזה הוא true, צריך לשלוח בקשה שמציינת שדה האישור ackNoticeForPluginVmAllowedSetToTrue עד true, אחרת, תקבלו שגיאה בבקשה.

בדוגמה הזו, צריך לשלוח את הבקשה הבאה לשינוי באצווה.

curl -X POST \
  -H "Content-Type: application/json" \
  -H "Authorization: Bearer $TOKEN" \
  -d "{
  'requests': [
    {
      'policyTargetKey': {
        'targetResource': 'orgunits/03ph8a2z10ybbh2'
      },
      'policyValue': {
        'policySchema': 'chrome.users.PluginVmAllowed',
        'value': {
          'pluginVmAllowed': true,
          'ackNoticeForPluginVmAllowedSetToTrue': true
        }
      },
      'updateMask': {
        'paths': [
          'pluginVmAllowed',
          'ackNoticeForPluginVmAllowedSetToTrue'
        ]
      }
    }
  ]
}" \
"https://chromepolicy.googleapis.com/v1/customers/$CUSTOMER/policies/orgunits:batchModify"

הגדרת כללי מדיניות לקבצים

בחלק מכללי המדיניות יש שדות שמוקלדים בתור UploadedFile. צריך להעלות את שברצונך להגדיר כערך של כללי המדיניות לשרת ה-API, כדי לקבל כתובת URL לשימוש בבקשות BatchModify.

בדוגמה הזו נגדיר את chrome.users.Wallpaper על ידי העלאת קובץ JPEG.

העלאת הקובץ

בקשה

curl -X POST \
  -H "Content-Type: image/jpeg" \
  -H "Authorization: Bearer $TOKEN" \
  -T "/path/to/the/file" \
  "https://chromepolicy.googleapis.com/upload/v1/customers/$CUSTOMER/policies/files:uploadPolicyFile?policy_field=chrome.users.Wallpaper.wallpaperImage"

תשובה

תגובה מוצלחת צריכה לכלול את כתובת ה-URL כדי לגשת לקובץ:

{
  "downloadUri": "https://storage.googleapis.com/chromeos-mgmt/0gjdgxs370bkl6/ChromeOsWallpaper/32ac50ab-b5ae-4bba-afa8-b6b443912897"
}

הגדרת מדיניות הקובץ

בקשה

curl -X POST \
  -H "Content-Type: application/json" \
  -H "Authorization: Bearer $TOKEN" \
  -d '{
        requests: [{
                policyTargetKey: {
                        targetResource: "orgunits/04fatzly4jbjho9",
                        },
                policyValue: {
                        policySchema: "chrome.users.Wallpaper",
                        value: {
                          wallpaperImage: {downloadUri: "https://storage.googleapis.com/chromeos-mgmt/0gjdgxs370bkl6/ChromeOsWallpaper/32ac50ab-b5ae-4bba-afa8-b6b443912897"}
                          }
                        },
                updateMask: {paths: "wallpaperImage"}
                }]
      }' \
  "https://chromepolicy.googleapis.com/v1/customers/$CUSTOMER/policies/orgunits:batchModify"

תשובה

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

{}