

翻訳は機械翻訳により提供されています。提供された翻訳内容と英語版の間で齟齬、不一致または矛盾がある場合、英語版が優先します。

# カスタムプロビジョニングプラグインを開発する
<a name="develop-custom-provisioning-plugins"></a>

カスタムプロビジョニングプラグインを開発するには、`com.aws.greengrass.provisioning.DeviceIdentityInterface` インターフェイスを実装する Java クラスを作成します。Greengrass nucleus JAR ファイルをプロジェクトに含めて、このインターフェイスとクラスにアクセスすることができます。このインターフェイスは、プラグイン設定を入力し、プロビジョニング設定を出力するメソッドを定義するためのものです。プロビジョニング設定では、システムと [Greengrass nucleus コンポーネント](greengrass-nucleus-component.md)の設定を定義します。 AWS IoT Greengrass Core ソフトウェアインストーラは、このプロビジョニング設定を使用して、デバイスで AWS IoT Greengrass Core ソフトウェアを設定します。

カスタムプロビジョニングプラグインを開発したら、インストール中にプラグインを実行するために AWS IoT Greengrass Core ソフトウェアインストーラに提供できる JAR ファイルとして構築します。インストーラは、インストーラが使用するものと同じ JVM でカスタムプロビジョニングプラグインを実行するため、プラグインコードのみが含まれた JAR を作成することができます。

**注記**  
[AWS IoT フリートプロビジョニングプラグイン](fleet-provisioning.md)は、インストール中にフリートプロビジョニングを使用するため、`DeviceIdentityInterface` を実装します。フリートプロビジョニングプラグインはオープンソースであるため、ソースコードを確認して、プロビジョニングプラグインインターフェイスの使用方法例を見ることができます。詳細については、GitHub の「[AWS IoT フリートプロビジョニングプラグイン](https://github.com/aws-greengrass/aws-greengrass-fleet-provisioning-by-claim)」を参照してください。

**Topics**
+ [要件](#custom-provisioning-plugin-requirements)
+ [DeviceIdentityInterface インターフェイスを実装する](#implement-device-identity-interface)

## 要件
<a name="custom-provisioning-plugin-requirements"></a>

カスタムプロビジョニングプラグインを開発するには、次の要件を満たす Java クラスを作成する必要があります。
+ `com.aws.greengrass` パッケージ、または `com.aws.greengrass` パッケージ内のパッケージを使用します。
+ 引数を持たないコンストラクタが必要です。
+ `DeviceIdentityInterface` インターフェイスを実装します。詳細については、「[DeviceIdentityInterface インターフェイスを実装する](#implement-device-identity-interface)」を参照してください。

## DeviceIdentityInterface インターフェイスを実装する
<a name="implement-device-identity-interface"></a>

カスタムプラグインで `com.aws.greengrass.provisioning.DeviceIdentityInterface` インターフェースを使用するには、Greengrass nucleus をプロジェクトの依存関係として追加します。

**カスタムプロビジョニングプラグインプロジェクトで DeviceIdentityInterface を使用するには**
+ Greengrass nucleus JAR ファイルをライブラリとして追加するか、Greengrass nucleus を Maven の依存関係として追加できます。次のいずれかを行います。
  + Greengrass nucleus JAR ファイルをライブラリとして追加するには、Greengrass nucleus JAR を含む AWS IoT Greengrass Core ソフトウェアをダウンロードします。 AWS IoT Greengrass Core ソフトウェアの最新バージョンは、次の場所からダウンロードできます。
    + [https://d2s8p88vqu9w66.cloudfront.net/releases/greengrass-nucleus-latest.zip](https://d2s8p88vqu9w66.cloudfront.net/releases/greengrass-nucleus-latest.zip)

    Greengrass nucleus JAR ファイル (`Greengrass.jar`) は、ZIP ファイル内の `lib` フォルダにあります。この JAR ファイルをプロジェクトに追加します。
  + Maven プロジェクトで Greengrass nucleus を使用するには、`com.aws.greengrass` グループ内の `nucleus` アーティファクトに依存関係を追加します。また、Greengrass nucleus は Maven Central リポジトリでは利用できないため、`greengrass-common` レポジトリも追加する必要があります。

    ```
    <project ...>
        ...
        <repositories>
            <repository>
                <id>greengrass-common</id>
                <name>greengrass common</name>
                <url>https://d2jrmugq4soldf.cloudfront.net/snapshots</url>
            </repository>
        </repositories>
        ...
        <dependencies>
            <dependency>
                <groupId>com.aws.greengrass</groupId>
                <artifactId>nucleus</artifactId>
                <version>2.5.0-SNAPSHOT</version>
                <scope>provided</scope>
            </dependency>
        </dependencies>
    </project>
    ```

### DeviceIdentityInterface インターフェイス
<a name="device-identity-interface-shape"></a>

`com.aws.greengrass.provisioning.DeviceIdentityInterface` インターフェイスには、次のシェイプがあります。

**注記**  
これらのクラスは、GitHub にある [Greengrass nucleus source code](https://github.com/aws-greengrass/aws-greengrass-nucleus) の [com.aws.greengrass.provisioning package](https://github.com/aws-greengrass/aws-greengrass-nucleus/tree/main/src/main/java/com/aws/greengrass/provisioning) でも確認できます。

```
public interface com.aws.greengrass.provisioning.DeviceIdentityInterface {
    ProvisionConfiguration updateIdentityConfiguration(ProvisionContext context)
            throws RetryableProvisioningException, InterruptedException;

    // Return the name of the plugin.
    String name(); 
}

com.aws.greengrass.provisioning.ProvisionConfiguration {
    SystemConfiguration systemConfiguration;
    NucleusConfiguration nucleusConfiguration    
}

com.aws.greengrass.provisioning.ProvisionConfiguration.SystemConfiguration {
    String certificateFilePath;
    String privateKeyPath;
    String rootCAPath;
    String thingName;
}

com.aws.greengrass.provisioning.ProvisionConfiguration.NucleusConfiguration {
    String awsRegion;
    String iotCredentialsEndpoint;
    String iotDataEndpoint;
    String iotRoleAlias;
}

com.aws.greengrass.provisioning.ProvisioningContext {
    Map<String, Object> parameterMap;
    String provisioningPolicy;  // The policy is always "PROVISION_IF_NOT_PROVISIONED".
}
   
com.aws.greengrass.provisioning.exceptions.RetryableProvisioningException {}
```

 AWS IoT Greengrass Core ソフトウェアをインストールするには、 `SystemConfiguration`および の各設定値`NucleusConfiguration`が必要ですが、 を返すことができます`null`。カスタムプロビジョニングプラグインが設定値`null`に対して を返す場合は、 AWS IoT Greengrass Core ソフトウェアインストーラに提供する `config.yaml` ファイルを作成するときに、システムまたは nucleus 設定でその値を指定する必要があります。`config.yaml` で定義したオプションに対して、カスタムプロビジョニングプラグインが NULL 以外の値を返した場合、インストーラは `config.yaml` の値をプラグインから返された値に置き換えます。