Skip to content

Latest commit

 

History

History
145 lines (114 loc) · 4.39 KB

File metadata and controls

145 lines (114 loc) · 4.39 KB

grdm CLI

CLI tool for interacting with GRDM (GakuNin RDM).

Environment Variables

  • GRDM_TOKEN: Personal Access Token for GRDM API
  • GRDM_PROFILE: Server profile name (optional)

Configuration

Server profiles can be configured in ~/.grdm/config.toml:

[staging2]
api_url = "https://api.staging2.rdm.nii.ac.jp/v2"
web_url = "https://staging2.rdm.nii.ac.jp/"
files_url = "https://files.staging2.rdm.nii.ac.jp/"

Use -profile flag or GRDM_PROFILE environment variable to select a profile:

grdm -profile staging2 metadata list -project <id>
GRDM_PROFILE=staging2 grdm metadata list -project <id>

Without a profile, the default production server (rdm.nii.ac.jp) is used.

Commands

metadata

grdm metadata list -project <id>                  # List draft registrations
grdm metadata fetch -draft <id>                   # Fetch draft registration
grdm metadata create -project <id> -schema <name> # Create draft registration from stdin
grdm metadata update -draft <id>                  # Update draft registration from stdin
grdm metadata delete -draft <id>                  # Delete draft registration
grdm metadata schemas                             # List registration schemas

file

grdm file list -project <id>                      # List storages
grdm file list -project <id> /osfstorage          # List files in storage root
grdm file list -project <id> /osfstorage/path     # List files in folder
grdm file list -l -project <id> /osfstorage       # List with size
grdm file fetch -project <id> /osfstorage/file    # Download file to stdout
grdm file upload -project <id> /osfstorage/file   # Upload file from stdin
grdm file metadata fetch -project <id> -schema <name> <path>   # Fetch file metadata
grdm file metadata update -project <id> -schema <name> <path>  # Update file metadata from stdin
grdm file bulk fetch -project <id> -schema <name> <path>       # Fetch tree with metadata/content
grdm file bulk update -project <id> -schema <name> <path>      # Update tree from stdin

bulk format

bulk fetch / bulk update で使用する JSON 形式:

{
  "name": "osfstorage",
  "metadata": [
    { "active": true, "data": { "grdm-file:title-en": { "value": "Root" } } }
  ],
  "children": [
    {
      "name": "folder1",
      "metadata": [],
      "children": [
        {
          "name": "data.csv",
          "metadata": [
            { "active": true, "data": { "grdm-file:title-en": { "value": "Data" } } }
          ],
          "content": {
            "mimetype": "text/csv",
            "payload": "id,name\n1,Alice\n2,Bob"
          }
        },
        {
          "name": "image.png",
          "metadata": [],
          "content": {
            "mimetype": "image/png",
            "payload": "iVBORw0KGgo...base64..."
          }
        }
      ]
    }
  ]
}
  • metadata: ファイルメタデータ (スキーマでフィルタ済み)
  • content: ファイル内容 (text/* は生テキスト、それ以外は base64)
  • children: 子要素 (フォルダのみ)

fetch オプション:

  • -no-content: コンテンツ取得をスキップ

API

Base URL: https://api.rdm.nii.ac.jp/v2

metadata

Operation Method Endpoint
List GET /nodes/{nodeId}/draft_registrations/
Fetch GET /draft_registrations/{draftId}/
Create POST /nodes/{nodeId}/draft_registrations/
Update PATCH /draft_registrations/{draftId}/
Delete DELETE /draft_registrations/{draftId}/
Schemas GET /schemas/registrations/?filter[active]=true

file

Operation Method Endpoint
List storages GET /nodes/{nodeId}/files/
List files GET {filesUrl} (from storage/folder response)
Upload PUT {uploadUrl}?name={filename}
Create folder PUT {newFolderUrl}&name={name}

file metadata (v1 API)

Base URL: https://rdm.nii.ac.jp/api/v1

Operation Method Endpoint
Fetch GET /project/{nodeId}/metadata/files/{path}
Update PATCH /project/{nodeId}/metadata/files/{path}

Usage with getmetadata

# Create new draft registration
getmetadata -format mebyo ./data | grdm metadata create -project <project-id> -schema <schema-name>

# Update existing draft registration
getmetadata -format mebyo ./data | grdm metadata update -draft <draft-id>