# CSVテンプレートの使用

### 変換手順 <a href="#conversion-process" id="conversion-process"></a>

CSVからJSONへの変換には、主に以下の2とおりの方法があります。

1. CSVファイルのみで進める

   CSVに `pamDirectory`、`pamMachine`、`pamUser` の各オブジェクトをすべて記述します。
2. 列を最小限にしたCSVと、デフォルト属性を補うJSONテンプレートを併用する

   CSVには `pamMachine` および `pamUser` に固有の情報だけを記載し、その他のデータはJSONテンプレートから取り込みます。

### 1 – CSVのみを利用する <a href="#id-1-working-exclusively-from-csv" id="id-1-working-exclusively-from-csv"></a>

#### 必須項目 <a href="#required-fields" id="required-fields"></a>

CSVに最低限必要な列は以下のとおりです。

| hostname          | username      | user\_path        |
| ----------------- | ------------- | ----------------- |
| DESKTOP-001.local |               |                   |
|                   | Administrator | DESKTOP-001.local |

`user_path` 列は、ユーザーを紐づけるリソースを示します。この例では、以下のようなJSONオブジェクトが生成されます。

```json
{
        "title": "DESKTOP-001.local",
        "type": "pamMachine",
        "host": "DESKTOP-001.local",
        "pam_settings": {
          "options": {
            "rotation": "off",
            "connections": "on",
            "tunneling": "off",
            "graphical_session_recording": "on"
          },
          "connection": {}
        },
        "users": [
          {
            "title": "DESKTOP-001.local - Administrator",
            "login": "Administrator",
            "password": "",
            "type": "pamUser",
            "rotation_settings": {}
          }
        ]
      }
```

#### 名前付きフィールド <a href="#named-fields" id="named-fields"></a>

上記の必須項目に加え、以下の名前付きフィールドが使えます。

<table data-full-width="true"><thead><tr><th width="122">folder_path</th><th width="75">title</th><th width="113">hostname</th><th>type</th><th width="115">username</th><th width="113">password</th><th width="120">user_path</th></tr></thead><tbody><tr><td>SF/AD</td><td>AD</td><td>dc.com</td><td>pamDirectory</td><td></td><td></td><td></td></tr><tr><td>SF/Users</td><td>Admin</td><td></td><td></td><td>admin</td><td>pwd123</td><td>AD</td></tr></tbody></table>

列には、すべてのオブジェクトに共通するもの (例: `title`) と、オブジェクトの種類に応じて自動適用されるもの (例: `password` は `pamUser` にのみ適用) があります。

* `type` 列は、`hostname` を含む行ではデフォルトで `pamMachine` になり、`username` と `user_path` を含む行では `pamUser` になります。
* `folder_path` 列は `pam project extend` コマンドにのみ適用され、`pam project import` では無視されます。詳細は [既存のモデルへのPAMリソースの追加](/keeperpam/jp/privileged-access-manager/references/importing-pam-resources/adding-pam-resources-to-an-existing-model.md)をご参照ください。

#### 高度なフィールド <a href="#advanced-fields" id="advanced-fields"></a>

リソースオブジェクトまたはユーザーオブジェクトに関するフィールドは、接頭辞 `rs` および `usr` を付けて指定できます。

リソースの例は次のとおりです。

`rs.port`、`rs.operating_system`、`rs.pam_settings.connection.protocol`、`rs.pam_settings.connection.administrative_credentials`

ユーザーの例は次のとおりです。

`usr.distinguished_name`、`usr.rotation_settings.enabled`

### 2 - JSONテンプレートとCSVファイルを併用する <a href="#id-2-using-a-csv-file-with-a-json-template" id="id-2-using-a-csv-file-with-a-json-template"></a>

この方法では、追加のJSONファイルでプロジェクト設定、`pamDirectory` レコード、`pamMachine` レコードのデフォルト項目を定義します。CSVの各行について、JSON内の `pamMachine` テンプレートに沿ってリソースを、`pamUser` テンプレートに沿ってユーザーを生成します。

例として、`import_template.json` を作成し、次の内容を記述します。

{% code expandable="true" %}

```json
{
    "project": "XXX:Example Project",
    "shared_folder_users": {
        "manage_users": true,
        "manage_records": true,
        "can_edit": true,
        "can_share": true
    },
    "shared_folder_resources": {
        "manage_users": true,
        "manage_records": true,
        "can_edit": true,
        "can_share": true
    },
    "pam_configuration": {
        "environment": "local",
        "connections": "on",
        "rotation": "on",
        "graphical_session_recording": "on"
    },
    "pam_data": {
        "resources": [
            {
                "_comment1": "Every key that starts with '_' is a comment and can be ignored or deleted",
                "_comment2": "Every value that starts with uppercase 'XXX:' must be replaced with actual value (removed if not required)",
                "_comment3": "Every value that starts with lowercase 'xxx:' is just a placeholder - can be replaced with anything but must be present",
                "type": "pamDirectory",
                "title": "XXX:Example AD",
                "directory_type": "XXX:active_directory|ldap",
                "host": "XXX:demo.local",
                "port": "XXX:636",
                "use_ssl": true,
                "domain_name": "XXX:demo.local",
                "pam_settings": {
                    "options": {
                        "rotation": "on",
                        "connections": "on",
                        "tunneling": "on",
                        "graphical_session_recording": "on"
                    },
                    "connection": {
                        "protocol": "rdp",
                        "port": "XXX:3389",
                        "security": "XXX:any",
                        "ignore_server_cert": true,
                        "_comment_administrative_credentials": "Must match the unique title of one of the users below",
                        "administrative_credentials": "XXX:DomainAdmin"
                    }
                },
                "users": [
                    {
                        "type": "pamUser",
                        "_comment_title": "Must match administrative_credentials above if this is the admin user",
                        "title": "XXX:DomainAdmin",
                        "_comment_login_password": "Must provide valid credentials but delete sensitive data/json after import",
                        "login": "XXX:administrator@demo.local",
                        "password": "XXX:P4ssw0rd_123",
                        "rotation_settings": {
                            "rotation": "general",
                            "enabled": "on",
                            "schedule": {
                                "type": "on-demand"
                            }
                        }
                    }
                ]
            },
            {
                "_comment4": "While pamDirectory section above is static, the pamMachine section below is dynamicly generated",
                "_comment5": "One pamMachine with one pamUser will be generated per each line from the CSV file",
                "_comment6": "Only one pamMachine is needed and it will be used as a template for all CSV rows",
                "_comment7": "Please do NOT edit lines with xxx: in them - these are placeholders",
                "_comment8": "Any other line that don't contain xxx: can be altered/added/deleted in the template",
                "_comment9": "CSV Format: server_name,username,password",
                "type": "pamMachine",
                "_comment_title_and_host": "server value from CSV",
                "title": "xxx:server1",
                "host": "xxx:server1",
                "port": "5986",
                "ssl_verification": true,
                "operating_system": "Windows",
                "pam_settings": {
                    "options": {
                        "rotation": "on",
                        "connections": "on",
                        "tunneling": "on",
                        "graphical_session_recording": "on"
                    },
                    "connection": {
                        "protocol": "rdp",
                        "port": "3389",
                        "security": "any",
                        "ignore_server_cert": true,
                        "_comment_administrative_credentials": "Format: pamDirectory#title.pamDirectory#administrative_credentials - exact match needed",
                        "administrative_credentials": "XXX:Project1 AD.DomainAdmin"
                    }
                },
                "users": [
                    {
                        "type": "pamUser",
                        "_comment_title": "username value from CSV or server-username if --prefix-names option is used",
                        "title": "xxx:admin",
                        "_comment_login": "username value from CSV",
                        "login": "xxx:Administrator",
                        "_comment_password": "password value from CSV",
                        "password": "xxx:P4ssw0rd_123",
                        "rotation_settings": {
                            "rotation": "general",
                            "enabled": "on",
                            "schedule": {
                                "type": "on-demand"
                            }
                        }
                    }
                ]
            }
        ]
    }
}
```

{% endcode %}

上記のテンプレートでは、`XXX` の付いた項目を、実際に使う固定の値に置き換えます。`xxx` の付いた項目は、スクリプトがCSVの値で置き換えます。

CSVに `pamDirectory` のリソースとユーザーは含めません。その他のリソースとユーザーの行だけを記載します。テンプレートのデフォルト値は、CSVの列で上書きできます。

| hostname    | username     | user\_path  | password |
| ----------- | ------------ | ----------- | -------- |
| DESKTOP-001 |              |             |          |
|             | Domain Admin | Example AD  | pwd123   |
|             | Local Admin  | DESKTOP-001 | pwd123   |

### 変換の実行 <a href="#run-the-conversion" id="run-the-conversion"></a>

スクリプトは [こちら](https://github.com/Keeper-Security/Commander/blob/master/examples/pam_import_generator_v2.py)からダウンロードし、作業用のローカルフォルダに保存してください。

コマンド実行を簡単にするため、同じフォルダに次のファイルを置きます。

* `servers_to_import.csv`
* `import_template.json` (CSVとJSONの両方を使って変換する場合のみ必要)

CSVファイルのみで変換するときは、次のコマンドを実行します。

```bash
python3 pam_import_generator.py
```

CSVとJSONテンプレートの両方を使うときは、次のコマンドを実行します。

```bash
python3 pam_import_generator.py --template-file import_template.json --prefix-names
```

ファイルパスや出力先を変えるときは、次の引数を使います。

* `--input-file` … CSVファイルのパス
* `--template-file` … JSONテンプレートファイルのパス
* `--output-file` … 出力するJSONのパス

指定しない場合は、同じフォルダに `pam_import.json` が出力され、Keeperへインポートする対象のすべてのリソース定義が書き込まれます。


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.keeper.io/keeperpam/jp/privileged-access-manager/references/importing-pam-resources/using-a-csv-template.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
