Contoh kode untuk kebijakan aplikasi

Permintaan di bawah ini menggambarkan pengelolaan kebijakan dengan Policy API menggunakan kebijakan aplikasi sebagai contoh. Sebelum memulai, pastikan Anda meninjau Ringkasan Chrome Policy API dan Panduan skema kebijakan.

Semua permintaan yang ditampilkan di bawah ini menggunakan variabel berikut:

  • $TOKEN - Token OAuth 2
  • $CUSTOMER - ID pelanggan atau my_customer literal

Menginstal otomatis aplikasi

Contoh berikut adalah untuk Unit Organisasi. Permintaan Grup akan sama kecuali untuk targetResource, yang akan memiliki "groups/" bukan "orgunits/" sebelum ID.

Di sini, kita menyetel aplikasi Google Gambar untuk diinstal otomatis:

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"

Respons yang berhasil harus kosong:

{}

Contoh ini ditujukan untuk Aplikasi Pengguna. Permintaan Sesi Tamu Terkelola akan identik, kecuali skema kebijakannya adalah chrome.devices.managedguest.apps.InstallType. Permintaan kebijakan Aplikasi Kios yang setara adalah sebagai berikut:

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"

Respons yang berhasil harus kosong:

{}

Menghapus aplikasi

Penghapusan aplikasi harus dilakukan di Unit Organisasi tempat aplikasi ditambahkan secara eksplisit untuk pengelolaan. Saat memanggil resolve, kolom addedSourceKey berisi Unit Organisasi tempat kolom tersebut ditambahkan untuk pengelolaan. Dengan kata lain, delete hanya boleh dipanggil untuk aplikasi yang Unit Organisasi di addedSourceKey sama dengan yang ada di policyTargetKey.

Untuk menghapus aplikasi (secara eksplisit menghapusnya dari pengelolaan), Anda harus mengirim permintaan batchInherit yang mana policySchema merupakan skema untuk jenis aplikasi tertentu, dengan tanda bintang (*) sebagai pengganti kebijakan tertentu. Dalam contoh ini, kami menghapus aplikasi Google Gambar, yang diinstal di Unit Organisasi "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"

Respons yang berhasil harus kosong:

{}

Permintaan untuk menghapus aplikasi Kios dan aplikasi Sesi Tamu Terkelola masing-masing akan menggunakan skema chrome.devices.kiosk.apps.\* dan chrome.devices.managedguest.apps.\*.

Mendapatkan Kebijakan penginstalan aplikasi untuk aplikasi di Unit Organisasi

Untuk mendapatkan kebijakan untuk aplikasi tertentu, Anda harus menentukan kebijakan dan ID Aplikasi dalam permintaan. Dalam contoh ini, kita membaca nilai kebijakan InstallType untuk aplikasi Google Gambar:

Permintaan

  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"

Respons

{
  "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"
      }
    }
  ]
}

Mendapatkan Kebijakan penginstalan aplikasi untuk semua aplikasi di Unit Organisasi

Jika ID Aplikasi dihapus dari permintaan di contoh sebelumnya, ID tersebut akan menjadi permintaan nilai kebijakan InstallType untuk semua aplikasi di OU tersebut.

Permintaan

  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"

Respons

{
  "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"
      }
    },
    ...
  ]
}

Mencantumkan semua kebijakan untuk aplikasi di Unit Organisasi

Seperti halnya Anda dapat menghilangkan ID Aplikasi dari permintaan untuk mengambil kebijakan bagi semua aplikasi, Anda juga bisa mendapatkan semua kebijakan untuk satu aplikasi menggunakan karakter pengganti dalam kebijakan. Dalam contoh ini, kita mendapatkan nilai semua kebijakan untuk aplikasi Google Gambar.

Permintaan

  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"

Respons

{
  "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"
      }
    },
    ...
  ]
}

Mencantumkan semua kebijakan untuk semua aplikasi di Unit Organisasi

ID Aplikasi dapat dihilangkan dan karakter pengganti dapat digunakan dalam kebijakan untuk meminta semua setelan aplikasi untuk semua aplikasi pada OU.

Permintaan

  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"

Respons

{
  "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"
      }
    },
    ...
  ]
}

Menghapus AutoLaunchApp Kiosk Appsconfig

Untuk menghapus AutoLaunchApp, appId dapat disetel ke "None".

Perhatikan bahwa saat menetapkan appId ke "None", semua setelan AutoLaunchApp lainnya akan ditetapkan ke nilai defaultnya. Dalam kasus ini, setelan AutoLaunchApp apa pun selain appId yang dikirim dalam permintaan akan diabaikan.

Permintaan

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"

Respons

Respons yang berhasil kosong.

{}