ドメインAPI
GitLab PagesでカスタムドメインとTLS証明書を接続するためのエンドポイントです。
これらのエンドポイントを使用するには、GitLab Pages機能が有効になっている必要があります。機能の管理と 使用についての詳細をご覧ください。
全てのPagesドメインをリストアップ
前提条件
- インスタンスへの管理者アクセス権が必要です。
すべての Pages ドメインのリストを取得します。
GET /pages/domains
curl --header "PRIVATE-TOKEN: <your_access_token>" "https://gitlab.example.com/api/v4/pages/domains"
[
  {
    "domain": "ssl.domain.example",
    "url": "https://ssl.domain.example",
    "project_id": 1337,
    "auto_ssl_enabled": false,
    "certificate": {
      "expired": false,
      "expiration": "2020-04-12T14:32:00.000Z"
    }
  }
]
Pagesドメインの一覧
プロジェクトPagesドメインのリストを取得します。ユーザーにはPagesドメインを表示する権限が必要です。
GET /projects/:id/pages/domains
| 属性 | 種類 | 必須 | 説明 | 
|---|---|---|---|
| id | 整数/文字列 | yes | 認証ユーザーが所有するプロジェクトのIDまたはURLエンコードされたパス | 
curl --header "PRIVATE-TOKEN: <your_access_token>" "https://gitlab.example.com/api/v4/projects/5/pages/domains"
[
  {
    "domain": "www.domain.example",
    "url": "http://www.domain.example"
  },
  {
    "domain": "ssl.domain.example",
    "url": "https://ssl.domain.example",
    "auto_ssl_enabled": false,
    "certificate": {
      "subject": "/O=Example, Inc./OU=Example Origin CA/CN=Example Origin Certificate",
      "expired": false,
      "certificate": "-----BEGIN CERTIFICATE-----\n … \n-----END CERTIFICATE-----",
      "certificate_text": "Certificate:\n … \n"
    }
  }
]
単一ページドメイン
単一プロジェクトのPagesドメインを取得します。ユーザーにはPagesドメインを表示する権限が必要です。
GET /projects/:id/pages/domains/:domain
| 属性 | 種類 | 必須 | 説明 | 
|---|---|---|---|
| id | 整数/文字列 | yes | 認証ユーザーが所有するプロジェクトのIDまたはURLエンコードされたパス | 
| domain | 文字列です。 | yes | ユーザーが指定したカスタムドメイン | 
curl --header "PRIVATE-TOKEN: <your_access_token>" "https://gitlab.example.com/api/v4/projects/5/pages/domains/www.domain.example"
{
  "domain": "www.domain.example",
  "url": "http://www.domain.example"
}
curl --header "PRIVATE-TOKEN: <your_access_token>" "https://gitlab.example.com/api/v4/projects/5/pages/domains/ssl.domain.example"
{
  "domain": "ssl.domain.example",
  "url": "https://ssl.domain.example",
  "auto_ssl_enabled": false,
  "certificate": {
    "subject": "/O=Example, Inc./OU=Example Origin CA/CN=Example Origin Certificate",
    "expired": false,
    "certificate": "-----BEGIN CERTIFICATE-----\n … \n-----END CERTIFICATE-----",
    "certificate_text": "Certificate:\n … \n"
  }
}
新しいPagesドメインを作成
新しいPagesドメインを作成します。ユーザーには、新しいPagesドメインを作成する権限が必要です。
POST /projects/:id/pages/domains
| 属性 | 種類 | 必須 | 説明 | 
|---|---|---|---|
| id | 整数/文字列 | yes | 認証ユーザーが所有するプロジェクトのIDまたはURLエンコードされたパス | 
| domain | 文字列です。 | yes | ユーザーが指定したカスタムドメイン | 
| auto_ssl_enabled | boolean | いいえ | カスタムドメインのLet’s Encryptが発行するSSL証明書の自動生成を有効にします。 | 
| certificate | ファイル/文字列 | いいえ | 最も特定的なものから最も特定的でないものの順に中間体が続く PEM 形式の証明書。 | 
| key | ファイル/文字列 | いいえ | PEM形式の証明書キー。 | 
.pem ファイルから証明書を使用して新しい Pages ドメインを作成します:
curl --request POST --header "PRIVATE-TOKEN: <your_access_token>" \
     --form "domain=ssl.domain.example" --form "certificate=@/path/to/cert.pem" \
     --form "key=@/path/to/key.pem" "https://gitlab.example.com/api/v4/projects/5/pages/domains"
証明書を含む変数を使用して、新しいPagesドメインを作成します:
curl --request POST --header "PRIVATE-TOKEN: <your_access_token>" \
     --form "domain=ssl.domain.example" --form "certificate=$CERT_PEM" \
     --form "key=$KEY_PEM" "https://gitlab.example.com/api/v4/projects/5/pages/domains"
自動証明書を使用して新しいPagesドメインを作成します:
curl --request POST --header "PRIVATE-TOKEN: <your_access_token>" --form "domain=ssl.domain.example" \
     --form "auto_ssl_enabled=true" "https://gitlab.example.com/api/v4/projects/5/pages/domains"
{
  "domain": "ssl.domain.example",
  "url": "https://ssl.domain.example",
  "auto_ssl_enabled": true,
  "certificate": {
    "subject": "/O=Example, Inc./OU=Example Origin CA/CN=Example Origin Certificate",
    "expired": false,
    "certificate": "-----BEGIN CERTIFICATE-----\n … \n-----END CERTIFICATE-----",
    "certificate_text": "Certificate:\n … \n"
  }
}
Pagesドメインの更新
既存のプロジェクトのPagesドメインを更新します。ユーザーには既存のPagesドメインを変更する権限が必要です。
PUT /projects/:id/pages/domains/:domain
| 属性 | 種類 | 必須 | 説明 | 
|---|---|---|---|
| id | 整数/文字列 | yes | 認証ユーザーが所有するプロジェクトのIDまたはURLエンコードされたパス | 
| domain | 文字列です。 | yes | ユーザーが指定したカスタムドメイン | 
| auto_ssl_enabled | boolean | いいえ | カスタムドメインのLet’s Encryptが発行するSSL証明書の自動生成を有効にします。 | 
| certificate | ファイル/文字列 | いいえ | 最も特定的なものから最も特定的でないものの順に中間体が続く PEM 形式の証明書。 | 
| key | ファイル/文字列 | いいえ | PEM形式の証明書キー。 | 
証明書の追加
.pem ファイルから Pages ドメインの証明書を追加します:
curl --request PUT --header "PRIVATE-TOKEN: <your_access_token>" --form "certificate=@/path/to/cert.pem" \
     --form "key=@/path/to/key.pem" "https://gitlab.example.com/api/v4/projects/5/pages/domains/ssl.domain.example"
証明書を含む変数を使用して、Pagesドメインの証明書を追加します:
curl --request PUT --header "PRIVATE-TOKEN: <your_access_token>" --form "certificate=$CERT_PEM" \
     --form "key=$KEY_PEM" "https://gitlab.example.com/api/v4/projects/5/pages/domains/ssl.domain.example"
{
  "domain": "ssl.domain.example",
  "url": "https://ssl.domain.example",
  "auto_ssl_enabled": false,
  "certificate": {
    "subject": "/O=Example, Inc./OU=Example Origin CA/CN=Example Origin Certificate",
    "expired": false,
    "certificate": "-----BEGIN CERTIFICATE-----\n … \n-----END CERTIFICATE-----",
    "certificate_text": "Certificate:\n … \n"
  }
}
PagesカスタムドメインのLet’s Encryptインテグレーションを有効にします。
curl --request PUT --header "PRIVATE-TOKEN: <your_access_token>" \
     --form "auto_ssl_enabled=true" "https://gitlab.example.com/api/v4/projects/5/pages/domains/ssl.domain.example"
{
  "domain": "ssl.domain.example",
  "url": "https://ssl.domain.example",
  "auto_ssl_enabled": true
}
証明書の削除
Pagesドメインに接続されているSSL証明書を削除するには、以下を実行します:
curl --request PUT --header "PRIVATE-TOKEN: <your_access_token>" --form "certificate=" \
     --form "key=" "https://gitlab.example.com/api/v4/projects/5/pages/domains/ssl.domain.example"
{
  "domain": "ssl.domain.example",
  "url": "https://ssl.domain.example",
  "auto_ssl_enabled": false
}
Pagesドメインの削除
既存のプロジェクトPagesドメインを削除します。
DELETE /projects/:id/pages/domains/:domain
| 属性 | 種類 | 必須 | 説明 | 
|---|---|---|---|
| id | 整数/文字列 | yes | 認証ユーザーが所有するプロジェクトのIDまたはURLエンコードされたパス | 
| domain | 文字列です。 | yes | ユーザーが指定したカスタムドメイン | 
curl --request DELETE --header "PRIVATE-TOKEN: <your_access_token>" "https://gitlab.example.com/api/v4/projects/5/pages/domains/ssl.domain.example"
