nginx-proxyでの 413 Request Entity Too Large エラーの対処法

概要 EC2上にDockerをインストールし、nginx-proxyとnginx-proxy-lets-encryptを利用してSSL化を行いました。 上記の設定で問題なく使用できていましたが、比較的大きなサイズのファイルをPOSTするアプリを作成した際、以下のエラーが発生してアップロードできませんでした。 nginx-proxy 413 (Payload Too Large) Nginxのclient_max_body_sizeを上げる必要がありました。 方法 ChatGPT4に教えていただいた以下の対応により、解決することができました。 413 Request Entity Too Large エラーは、クライアントがサーバーに送信しようとしているリクエストのペイロード(つまり、アップロードするファイルのサイズなど)がサーバーで設定された制限を超えている場合に発生します。このエラーを解決するためには、Nginx の設定でクライアントリクエストの最大サイズを増やす必要があります。 nginx-proxy コンテナでこの設定を調整するには、client_max_body_size ディレクティブの値を増やすことで、受け入れ可能なリクエストサイズの上限を上げることができます。しかし、jwilder/nginx-proxy イメージを使用している場合、直接 Nginx の設定ファイルを編集するのではなく、カスタム設定を適用する方法が推奨されます。 以下は、client_max_body_size を増やすために必要な手順です。 カスタム設定ファイルを作成する: ローカルに client_max_body_size ディレクティブを含むカスタム Nginx 設定ファイルを作成します。例えば、この設定を 100M (100メガバイト)に設定したい場合、次の内容を含むファイルを作成します。 my_custom_proxy_settings.conf: client_max_body_size 100M; カスタム設定ファイルを Docker コンテナにマウントする: nginx-proxy サービスの定義に、このカスタム設定ファイルを /etc/nginx/conf.d ディレクトリにマウントする設定を追加します。これにより、Nginx が起動する際にこの設定が適用されます。 修正された docker-compose.yml の例: services: nginx-proxy: image: jwilder/nginx-proxy container_name: nginx-proxy ports: - "80:80" - "443:443" volumes: - html:/usr/share/nginx/html - dhparam:/etc/nginx/dhparam - vhost:/etc/nginx/vhost.d - certs:/etc/nginx/certs:ro - /var/run/docker.sock:/tmp/docker.sock:ro - /srv/docker/nginx-proxy-with-encrypt/log:/var/log/nginx - ./my_custom_proxy_settings.conf:/etc/nginx/conf.d/my_custom_proxy_settings.conf:ro # この行を追加 labels: - "com.github.jrcs.letsencrypt_nginx_proxy_companion.nginx_proxy" restart: always Docker コンテナを再起動する: 変更を適用するために、docker-compose を使って nginx-proxy コンテナを再起動します。 ...

2024年2月4日 · 1 分 · Nakamura

Docker版Cantaloupeを使用して、S3バケットにアクセスしSSL通信を行う方法

概要 Docker版のCantaloupeの使い方を以下で紹介しました。 このDocker版Cantaloupeを(大規模ではない)production環境で使用するには、Amazon S3との接続や、SSL対応が求められます。その方法を一例を紹介します。 Amazon S3との接続 公式では以下で紹介されています。 https://cantaloupe-project.github.io/manual/5.0/sources.html#S3Source 日本語の記事として以下があります。 また、今回扱うDocker版では、以下に記載がありました。 https://github.com/Islandora-Devops/isle-buildkit/blob/main/cantaloupe/README.md#settings そこで、S3と最低限の接続を行うためのリポジトリを作成しました。 https://github.com/nakamura196/docker_cantaloupe_s3 .env.exampleを.envにリネームまたはコピーして、必要な値を入力します。 SSL対応 以下の記事を参考にしました。EC2上にDockerをインストールし、nginx-proxyとnginx-proxy-lets-encryptを利用してSSL化を行いました。 https://qiita.com/atsuya/items/7cb6e0ccee63d751d41f version: '3' # proxy services: nginx-proxy: image: jwilder/nginx-proxy container_name: nginx-proxy ports: - "80:80" - "443:443" volumes: - html:/usr/share/nginx/html - dhparam:/etc/nginx/dhparam - vhost:/etc/nginx/vhost.d - certs:/etc/nginx/certs:ro - /var/run/docker.sock:/tmp/docker.sock:ro - /srv/docker/nginx-proxy-with-encrypt/log:/var/log/nginx labels: - "com.github.jrcs.letsencrypt_nginx_proxy_companion.nginx_proxy" restart: always letsencrypt: image: jrcs/letsencrypt-nginx-proxy-companion container_name: nginx-proxy-lets-encrypt depends_on: - "nginx-proxy" volumes: - certs:/etc/nginx/certs:rw - vhost:/etc/nginx/vhost.d - html:/usr/share/nginx/html - /var/run/docker.sock:/var/run/docker.sock:ro volumes: certs: html: vhost: dhparam: networks: default: external: name: common_link services: cantaloupe: image: islandora/cantaloupe:2.0.10 environment: CANTALOUPE_ENDPOINT_ADMIN_ENABLED: false CANTALOUPE_ENDPOINT_ADMIN_SECRET: my_admin_pass CANTALOUPE_SOURCE_STATIC: S3Source CANTALOUPE_S3SOURCE_ACCESS_KEY_ID: ${CANTALOUPE_S3SOURCE_ACCESS_KEY_ID} CANTALOUPE_S3SOURCE_SECRET_KEY: ${CANTALOUPE_S3SOURCE_SECRET_KEY} CANTALOUPE_S3SOURCE_REGION: ${CANTALOUPE_S3SOURCE_REGION} CANTALOUPE_S3SOURCE_BASICLOOKUPSTRATEGY_BUCKET_NAME: ${CANTALOUPE_S3SOURCE_BASICLOOKUPSTRATEGY_BUCKET_NAME} CANTALOUPE_S3SOURCE_LOOKUP_STRATEGY: BasicLookupStrategy # Or another strategy if needed VIRTUAL_HOST: <カスタムドメイン> LETSENCRYPT_HOST: <カスタムドメイン> LETSENCRYPT_EMAIL: <メールアドレス> restart: always networks: default: external: name: common_link まとめ IIIF画像サーバの小中規模の利用にあたっては、上記のような形が比較的容易な導入方法の一つに当たるかと思います。 ...

2024年1月27日 · 1 分 · Nakamura

File Information Tool Set (FITS)を試す

概要 Archivematicaの調査にあたり、File Information Tool Set (FITS)の挙動について確認したい点があり、Dockerを使って試してみましたので、その備忘録です。 https://github.com/harvard-lts/fits インストール 以下にDockerを用いたインストール方法が記載されています。 https://github.com/harvard-lts/fits?tab=readme-ov-file#docker-installation ただ、マニュアルに記載のある以下のページにアクセスしても、Dockerfileが含まれる最新のリリース(1.6.0)はダウンロードできませんでした。 https://projects.iq.harvard.edu/fits/downloads 代わりに、GitHubの以下のリリースページで、最新版のzipファイルをダウンロードできました。 https://github.com/harvard-lts/fits/releases/tag/1.6.0 あとは、READMEの記載の通りに展開、およびビルドを行いました。 ただし、M1 Macの場合、手順通りに実行したところ、以下のエラーが発生しました。 % docker run --rm -v `pwd`:/work fits -i fits.sh 2024-01-26 11:41:10 - ERROR - MediaInfo:95 - Error loading native library for this operating system for tool: MediaInfo. ostype=[Linux] -- jvmModel=[64] -- nativeLibPath=[/opt/fits/tools/mediainfo/linux] -- No native MediaInfo library for this OS java.lang.UnsatisfiedLinkError: Unable to load library 'mediainfo': libmediainfo.so: cannot open shared object file: No such file or directory libmediainfo.so: cannot open shared object file: No such file or directory /opt/fits/tools/mediainfo/linux/libmediainfo.so.0: cannot open shared object file: No such file or directory ... これに対して、ChatGPT 4に確認した結果、Dockerfileに以下の追記を行う指示がありました。 ...

2024年1月26日 · 3 分 · Nakamura

GitHub Actionsの処理結果をメールで通知する: Gmailの使用

概要 GitHub Actionsの処理結果をメールで通知する機会がありましたので、その備忘録です。 今回はGmailを使います。以下が参考になりました。 https://stackoverflow.com/questions/69947109/sending-email-with-github-actions Gmailの設定 以下に記載があります。2段階認証を有効にして、アプリパスワードを作成します。 https://github.com/dawidd6/action-send-mail?tab=readme-ov-file#gmail アプリパスワードの設定例は以下です。 ローカルでの動作確認 actを使って、ローカル環境でGitHub Actionsを実行します。 https://github.com/nektos/act あるリポジトリで以下のようなファイルを作成します。 name: Notification Workflow on: [push] jobs: send-mail: runs-on: ubuntu-latest steps: - name: Send mail if: success() # この行はデプロイが成功した場合にのみメールを送信するようにします uses: dawidd6/action-send-mail@v3 with: server_address: smtp.gmail.com server_port: 465 username: ${{secrets.MAIL_USERNAME}} password: ${{secrets.MAIL_PASSWORD}} subject: Deployment Completed - ${{ github.repository }} to: ${{secrets.MAIL_TO}} from: ${{ secrets.MAIL_FROM }} body: | Hello, The deployment process for the repository ${{ github.repository }} has been successfully completed. Commit: ${{ github.sha }} Commit link: https://github.com/${{ github.repository }}/commit/${{ github.sha }} Branch: ${{ github.ref }} Best regards, ${{ secrets.MAIL_FROM }} 以下のようなコマンドでシークレットを使うことができました。 ...

2024年1月20日 · 2 分 · Nakamura

デジタル源氏物語における校異源氏物語と現代語訳の対応づけ

概要 「デジタル源氏物語」は『源氏物語』に関する様々な関連データを収集・作成し、それらを結びつけることで、『源氏物語』研究はもちろん、古典籍を利用した教育・研究活動の一助となる環境の提案を目指したサイトです。 https://genji.dl.itc.u-tokyo.ac.jp/ 本サイトが提供する機能の一つとして、「校異源氏物語と現代語訳の対応づけ」があります。以下のように、「校異源氏物語」と青空文庫で公開されている与謝野晶子訳の対応箇所がハイライト表示されます。 この記事では、上記の機能を実現するための手順について説明します。 データ 以下のようなデータを作成します。 https://genji.dl.itc.u-tokyo.ac.jp/data/tei/koui/54.xml 「校異源氏物語」のテキストデータに対して、anchorタグを使って、与謝野晶子訳のファイルとIDのペアを対応付ます。 <text> <body> <p> <lb/> <pb facs="#zone_2055" n="2055"/> <lb/> <seg corresp="https://w3id.org/kouigenjimonogatari/api/items/2055-01.json"> <anchor corresp="https://genji.dl.itc.u-tokyo.ac.jp/api/items/tei/yosano/56.xml#YG5600000300"/> やまにおはしてれいせさせ給やうに経仏なとくやうせさせ給 <anchor corresp="https://genji.dl.itc.u-tokyo.ac.jp/api/items/tei/yosano/56.xml#YG5600000400"/> 又の日はよかはに </seg> <lb/> ... このデータの作成にあたっては、以下のツールを開発して使用しました。 https://github.com/tei-eaj/parallel_text_editor 残念ながら2024-01-07時点では動作しませんが、動作イメージは以下をご確認ください。今後、本ツールの改修を行いたいと思います。 https://youtu.be/hOp_PxYUrZk 上記の作業の結果、以下のようなGoogleドキュメントが作成されます。 https://docs.google.com/document/d/1DxKItyugUIR3YYUxlwH5-SRVA_eTj7Gh_LJ4A0mzCg8/edit?usp=sharing 「校異源氏物語」の各行について、対応する与謝野晶子訳のIDを\[YG(\d+)\]の形で挿入されます。 2055-01 [YG5600000300]やまにおはしてれいせさせ給やうに経仏なとくやうせさせ給[YG5600000400]又の日はよかはに 2055-02 おはしたれはそうつおとろきかしこまりきこえ給[YG5600000500]としころ御いのりなとつけか 2055-03 たらひたまひけれとことにいとしたしきことはなかりけるをこのたひ一品の宮 2055-04 の御心ちのほとにさふらひ給へるにすくれたまへるけん物し給けりとみたまひ 2055-05 てよりこよなうたうとひたまひていますこしふかきちきりくはへ給てけれはお 2055-06 も〱しくおはするとのゝかくわさとおはしましたることゝもてさはきゝこえ 2055-07 給[YG5600000600]御物かたりなとこまやかにしておはすれは御ゆつけなとまいり給[YG5600000700]すこし人 2055-08 〱しつまりぬるに[YG5600000800]をのゝわたりにしり給へるやとりや侍とゝひ給へはしか侍 ... 源氏物語の冊毎のGoogleドキュメントがGoogleドライブに保存されます。 https://drive.google.com/drive/folders/1QgS4z_5vk8AEz95iA3q7j41-U3oDdfpx 処理 Googleドライブからのファイル名とIDの一覧を取得 Googleドライブとの接続 #| export import os.path from google.auth.transport.requests import Request from google.oauth2.credentials import Credentials from google_auth_oauthlib.flow import InstalledAppFlow from googleapiclient.discovery import build from googleapiclient.errors import HttpError #| export class GoogleDriveClient: def __init__(self, credential_path): # If modifying these scopes, delete the file token.json. SCOPES = [ "https://www.googleapis.com/auth/drive.metadata.readonly" ] creds = None # The file token.json stores the user's access and refresh tokens, and is # created automatically when the authorization flow completes for the first # time. if os.path.exists("token.json"): creds = Credentials.from_authorized_user_file("token.json", SCOPES) # If there are no (valid) credentials available, let the user log in. if not creds or not creds.valid: if creds and creds.expired and creds.refresh_token: creds.refresh(Request()) else: flow = InstalledAppFlow.from_client_secrets_file( credential_path, SCOPES ) creds = flow.run_local_server(port=0) # Save the credentials for the next run with open("token.json", "w") as token: token.write(creds.to_json()) try: service = build('drive', 'v3', credentials=creds) self.drive_service = service except HttpError as e: print(e) print("Error while creating API client") raise e 一覧の取得 ...

2024年1月7日 · 2 分 · Nakamura

ro-crate-pyを試す

概要 ro-crate-pyは、Research Object Crates (RO-Crate)を作成および利用するためのPythonライブラリです。 https://doi.org/10.5281/zenodo.3956493 ro-crate-py is a Python library to create and consume Research Object Crates. It currently supports the RO-Crate 1.1 specification. ゴール 以下に示すようなページを作成することを目指します。 https://nakamura196.github.io/rocrate_demo/crate/test/data/ro-crate-preview.html データセットのページ 特定のアイテムのページ JSONデータ 以下のようなJSONデータを作成します。 https://nakamura196.github.io/rocrate_demo/crate/test/data/ro-crate-metadata.json アイテムのIDとしては、以下のOAI-PMHのレコードを使用します。 https://da.dl.itc.u-tokyo.ac.jp/portal/oai?verb=GetRecord&metadataPrefix=dcndl_simple&identifier=oai:da.dl.itc.u-tokyo.ac.jp:fbd0479b-dbb4-4eaa-95b8-f27e1c423e4b アイテムの作成者として、ダミーの値ですが、ORCIDのIDを指定します。 https://orcid.org/0000-0001-8245-7925 データの公開者としては、東京大学のResearch Organization Registry (ROR) を指定します。 https://ror.org/057zh3y96 ライブラリのインストール bagitはrocrateに必須ではありませんが、今回は最終出力をbagit形式にするために使用します。 pip install rocrate pip install bagit from rocrate.rocrate import ROCrate from rocrate.model.person import Person from rocrate.model.contextentity import ContextEntity import os import bagit import shutil import json データ dataset_name = "百鬼夜行図コレクション" dataset_description = "百鬼夜行図(ひやつきやぎうず) 蔭山源広迢写 百鬼夜行は今昔物語などの説話にでてくる言葉で、京の大路を夜な夜な化け物たちが練り歩く様子を表している。" dataset_license = "https://www.lib.u-tokyo.ac.jp/ja/library/contents/archives-top/reuse" item_id = "https://da.dl.itc.u-tokyo.ac.jp/portal/oai?verb=GetRecord&metadataPrefix=dcndl_simple&identifier=oai:da.dl.itc.u-tokyo.ac.jp:fbd0479b-dbb4-4eaa-95b8-f27e1c423e4b" item_name = "百鬼夜行図" item_description = "OAI-PMH(Open Archives Initiative Protocol for Metadata Harvesting)" item_license = "https://www.lib.u-tokyo.ac.jp/ja/library/contents/archives-top/reuse" person_id = "https://orcid.org/0000-0001-8245-7925" person_name = "Satoru Nakamura" org_id = "https://ror.org/057zh3y96" org_name = "The University of Tokyo" ROCrateインスタンスの作成 gen_preview=Trueとすることで、保存時にpreview.htmlを合わせて作成してくれます。 ...

2024年1月2日 · 2 分 · Nakamura

GitHubのリポジトリをZenodoと連携する

概要 先日、Mirador3でアノテーションを比較するためのプラグインを公開しました。 https://github.com/nakamura196/mirador-compare-plugin 今回は、このリポジトリをZenodoと接続してみます。 結果、releaseを行うたびに、自動的にDOIが付与されるようになりました。 https://zenodo.org/doi/10.5281/zenodo.10449856 Zenodoでの設定 以下にアクセスして、連携対象のGitHubリポジトリを選択します。 /account/settings/github/ GitHub 以下、必須ではありませんが、Zenodoとの連携に向けて、GitHubリポジトリ上で必要な準備を行います。 CITATION.cffの作成 これを作成することにより、Creators にORCIDのIDが表示されるようでした。 具体的には、以下のようなファイルを作成します。 https://github.com/nakamura196/mirador-compare-plugin/blob/main/CITATION.cff cff-version: 1.1.0 message: "Cite as" authors: - family-names: Nakamura given-names: Satoru orcid: https://orcid.org/0000-0001-8245-7925 affiliation: "The University of Tokyo" website: https://researchmap.jp/nakamura.satoru?lang=en title: "mirador-compare-plugin" doi: 10.5281/zenodo.10449856 上記により、GitHubリポジトリ上にも「Cite this repository」が表示されるようになりました。 バッジの表示 以下が参考になりました。 https://gist.github.com/seignovert/ae6771f400ca464d294261f42900823a 以下のURLにアクセスして、idを取得します。今回は、664611010でした。 https://api.github.com/repos/nakamura196/mirador-compare-plugin このidを使用して、README.mdに以下を追加します。 [![DOI](https://zenodo.org/badge/664611010.svg)](https://zenodo.org/badge/latestdoi/664611010) 結果、以下のようにバッジが表示されました。 READEME.mdへのCite asの追加 ResearchObject/ro-crate-py を参考に、READEME.mdへCite asを追加してみます。 この時、以下に記載があるIDを用いることで、最新のバージョンに遷移するURLを作成することができました。 具体的には、今回は10449856というIDを使って、READMEに追記する内容を作成しました。 [![DOI](https://zenodo.org/badge/664611010.svg)](https://zenodo.org/badge/latestdoi/664611010) The above DOI corresponds to the latest versioned release as [published to Zenodo](https://zenodo.org/records/10449856), where you will find all earlier releases. To cite `mirador-compare-plugin` independent of version, use https://doi.org/10.5281/zenodo.10449856, which will always redirect to the latest release. リリースの作成 プルリクエストとマージ ブランチの作成 ...

2024年1月2日 · 1 分 · Nakamura

Drupalのsimple_oauthモジュールを用いたRESTリソースのoauth2認証を試す

概要 DrupalのSimple OAuth (OAuth2) & OpenID ConnectモジュールはOAuth 2.0認証フレームワークRFCの実装と説明されています。 https://www.drupal.org/project/simple_oauth 関連する記事として、cookie認証の例や、jwt認証の例も参考にしてください。 インストール simple_oauthモジュールには、5系と6系があるようですが、今回は5系を使用します。以下でインストールします。 composer.phar require 'drupal/simple_oauth:^5.2' ただし、さくらレンタルサーバを使用している場合、以下のエラーが発生しました。PHP's sodium extensionが必要でした。 composer.phar require 'drupal/simple_oauth:^5.2' ./composer.json has been updated Running composer update drupal/simple_oauth Loading composer repositories with package information Updating dependencies Your requirements could not be resolved to an installable set of packages. Problem 1 - steverhoades/oauth2-openid-connect-server v2.4.0 requires lcobucci/jwt 4.1.5 -> satisfiable by lcobucci/jwt[4.1.5]. - steverhoades/oauth2-openid-connect-server[v2.6.0, ..., v2.6.1] require lcobucci/jwt 4.1.5|^4.2|^4.3|^5.0 -> satisfiable by lcobucci/jwt[4.1.5, ..., 4.4.x-dev, 5.0.0, ..., 5.3.x-dev]. - steverhoades/oauth2-openid-connect-server v2.5.0 requires lcobucci/jwt 4.1.5|^4.2 -> satisfiable by lcobucci/jwt[4.1.5, ..., 4.4.x-dev]. - drupal/simple_oauth[5.2.0, ..., 5.x-dev] require drupal/core ^8 || ^9 -> found drupal/core[8.0.0-beta6, ..., 8.9.x-dev, 9.0.0-alpha1, ..., 9.5.x-dev] but the package is fixed to 10.2.0 (lock file version) by a partial update and that version does not match. Make sure you list it as an argument for the update command. - lcobucci/jwt[4.1.5, ..., 4.4.x-dev, 5.0.0, ..., 5.3.x-dev] require ext-sodium * -> it is missing from your system. Install or enable PHP's sodium extension. - drupal/simple_oauth[5.2.3, ..., 5.2.x-dev] require steverhoades/oauth2-openid-connect-server ^2.4 -> satisfiable by steverhoades/oauth2-openid-connect-server[v2.4.0, v2.5.0, v2.6.0, v2.6.1]. - Root composer.json requires drupal/simple_oauth ^5.2 -> satisfiable by drupal/simple_oauth[5.2.0, ..., 5.x-dev]. To enable extensions, verify that they are enabled in your .ini files: - /usr/local/php/8.1/etc/php.ini - /usr/local/php/8.1/etc/conf.d/apcu.ini - /usr/local/php/8.1/etc/conf.d/imagick.ini - /usr/local/php/8.1/etc/conf.d/mcrypt.ini - /usr/local/php/8.1/etc/conf.d/opcache.ini You can also run `php --ini` in a terminal to see which files are used by PHP in CLI mode. Alternatively, you can run Composer with `--ignore-platform-req=ext-sodium` to temporarily ignore these required extensions. Use the option --with-all-dependencies (-W) to allow upgrades, downgrades and removals for packages currently locked to specific versions. Installation failed, reverting ./composer.json and ./composer.lock to their original content. そこで、以下のサイトを参考に、PHP-sodium 拡張を追加しました。 ...

2024年1月2日 · 3 分 · Nakamura

Postmanを使って、DrupalのRESTリソースのcookie認証を試す

概要 以下の記事で、JWTモジュールを使ったJWT認証を試しました。 今回は、cookie認証を試します。 インストール restuiモジュールをインストールしていない場合には、以下のようなコマンドをインストールと有効化を行います。 composer.phar require 'drupal/restui:^1.21' vendor/bin/drush en restui 設定 今回は、以下のように、cookie認証を使用します。設定方法の詳細については、冒頭の関連記事をご確認ください。 Postman ログイン POST /user/login Body > x-www-form-urlencoded Key Value name {ユーザー名} pass {パスワード} form_id user_login_form ログインに成功すると、Cookieが発行されます。 セッショントークンの取得 GET /session/token Headersタブをみると、先に発行したCookieが設定されていることが確認できます。また、結果としてセッショントークンが取得できています。 コンテンツの作成 POST /node?_format=json Headersタブで、上記で取得したセッショントークンをX-CSRF-TokenKeyのValueとして設定します。 Bodyの値は、以下を例として使用しました。 { "type": [ { "target_id": "article" } ], "title": [ { "value": "新しい記事のタイトル" } ] } なお、誤ったセッショントークンを入力して試してみると、以下が返却されました。 { "message": "X-CSRF-Token request header is invalid" } 参考:ログアウト GET /user/logout 上記により、発行されたセッションクッキーが削除されました。 まとめ DrupalのRESTリソースのcookie認証を試しました。誤っている点があるかと思いますが、参考になりましたら幸いです。

2024年1月1日 · 1 分 · Nakamura

Drupal JSON Web Token Authenticationモジュールを試す

概要 DrupalのJSON Web Token Authenticationモジュールを試してみます。 https://www.drupal.org/project/jwt 以下のページを参考にしました。 https://preston.so/writing/decoupled-drupal-authentication-with-json-web-tokens/ なお、類似するモジュールとして、以下があるようです。 https://www.drupal.org/project/rest_api_authentication 上記モジュールを使ったjwt認証は以下で説明されています。 https://www.drupal.org/docs/contributed-modules/api-authentication/jwt-authentication しかし、以下の記事に記載したように、上記モジュールでjwt認証を使用するには有料プランに加入する必要があるようでした。 そこで、今回は、jwtモジュールのほうを試してみます。 インストールと有効化 jwtモジュール 注意点として、jwtだけでなく、jwt_auth_consumerやjwt_auth_issuerも有効化する必要がありました。 composer.phar require 'drupal/jwt:^2.0' vendor/bin/drush en jwt jwt_auth_consumer jwt_auth_issuer restuiモジュール composer.phar require 'drupal/restui:^1.21' vendor/bin/drush en restui 設定 以下にアクセスして、キーを作成します。 /admin/config/system/keys Key typeとしてJWT HMAC Keyを選択して、JWT AlgorithmとしてSHA-256を選択しました。 次に、以下にアクセスして、JWTの設定を行います。 AlgorithmとしてデフォルトのSHA-256を選択して、Secretとして先ほど作成したキー(ここではjwt)を選択します。 その後、ログインした状態で、以下にアクセスしてみます。 /jwt/token すると、以下のようなトークンが得られます。 参考までに、このトークンをjwt.ioで検証してみます。 https://jwt.io/ PAYLOADの箇所を見てみると、iat(Issued A: トークンが発行された時刻)やDrupalの「User ID」を確認することができます。 RESTリソースの設定 以下にアクセスします。 /admin/config/services/rest ここでは、コンテンツに対して、POSTを有効化し、認証プロバイダとしてjwt_authを選択します。 Postman Postmanを使って、コンテンツの作成を試してみます。 まず、Authorizationを指定せずに、コンテンツの作成試してみます。 Bodyはrawを選択して、フォーマットをJSONとします。以下の最低限のデータで、articleタイプのコンテンツの作成してみます。 { "type": [ { "target_id": "article" } ], "title": [ { "value": "新しい記事のタイトル" } ] } POST先のURLは以下です。 ...

2023年12月31日 · 2 分 · Nakamura

さくらレンタルサーバ上のDrupalを更新する

概要 さくらレンタルサーバ上のDrupalを更新する機会がありましたので、手順のメモです。 まず、以下のサイトを参考にしました。 https://www.drupal.org/docs/updating-drupal/updating-drupal-core-via-drush ただし、以下のような記載がありました。 Use Composer to manage Drupal dependencies. Drush 9 and newer no longer supports updating Drupal. そこで、以下も参考にさせていただきました。 https://drupalfan.com/drupal10を最新版にアップデートする/ 手順 ! 間違った手順や不要な手順が含まれているかもしれませんので、参考程度ご確認ください。 Drupalをダウンロードしたディレクトリに移動 cd ~/www/{project_name} 準備(インストール済みの場合は不要) composer composer.pharというファイルしかない場合、composerを作成する。(mvでもよいかと思います。) cp composer.phar composer drush composer require --dev drush/drush メンテナンスモードの有効化 ./vendor/bin/drush state-set system.maintenance_mode 1 キャッシュのクリア ./vendor/bin/drush cr バックアップ バックアップ用のディレクトリの作成 mkdir ~/bk sqlのバックアップ ./vendor/bin/drush sql:dump --extra-dump=--no-tablespaces > ~/bk/dump.sql 参考 以下のように、--extra-dump=--no-tablespacesを指定しないと、エラーがメッセージが表示されました。 ./vendor/bin/drush sql:dump > ~/bk/dump.sql > mysqldump: Error: 'Access denied; you need (at least one of) the PROCESS privilege(s) for this operation' when trying to dump tablespaces ファイルのバックアップ tar cvzf ~/bk/web.zip . 更新 事前確認 composer update "drupal/core-*" --with-all-dependencies --dry-run 更新 composer update "drupal/core-*" --with-all-dependencies コントリビュートモジュールのアップデート composer update データベースの更新 ./vendor/bin/drush updatedb メンテナンスモードの無効化 ./vendor/bin/drush state-set system.maintenance_mode 0 キャッシュのクリア ./vendor/bin/drush cr 更新後にキャッシュのクリアを行わないと、表示が崩れることがありました。 ...

2023年12月22日 · 1 分 · Nakamura

lando start時のエラー対応

ローカル開発環境構築ツールの一つであるLandoを使用してDrupalやOmekaのモジュール開発を行っていた際、以下のエラーが生じることがありました。 lando start __ __ __ __ ___ _ __ __ __ ______ / / / /__ ___/ /__ _/ /____ / _ |_ _____ _(_) /__ _/ / / /__ / / / / / /_/ / _ \/ _ / _ `/ __/ -_) / __ | |/ / _ `/ / / _ `/ _ \/ / -_)_/_/_/ \____/ .__/\_,_/\_,_/\__/\__/ /_/ |_|___/\_,_/_/_/\_,_/_.__/_/\__(_|_|_) /_/ Updating helps us provide the best support and saves us tons of time Use the link below to get the latest and greatest https://github.com/lando/lando/releases/tag/v3.20.8 Lando is FREE and OPEN SOURCE software that relies on contributions from developers like you! If you like Lando then help us spend more time making, updating and supporting it by contributing at the link below https://github.com/sponsors/lando If you would like to customize the behavior of this message then check out: https://docs.lando.dev/config/releases.html Let's get this party started! Starting app my-lando-app... ERROR ==> connect ENOENT /var/run/docker.sock ██╗ ██╗██╗ ██╗ ██████╗ ██╗ ██╗██╗ ██║ ██║██║ ██║ ██╔═══██╗██║ ██║██║ ██║ ██║███████║ ██║ ██║███████║██║ ██║ ██║██╔══██║ ██║ ██║██╔══██║╚═╝ ╚██████╔╝██║ ██║ ╚██████╔╝██║ ██║██╗ ╚═════╝ ╚═╝ ╚═╝ ╚═════╝ ╚═╝ ╚═╝╚═╝ An error occurred while starting up your app! Here are a few things you can try to get back into a good state: ■ Try running lando rebuild ■ Try restarting in debug mode lando restart -vvv ■ Try checking the logs with lando logs If those fail then consult the troubleshooting materials: ■ https://docs.lando.dev/help/logs.html ■ https://docs.lando.dev/help/updating.html Or post your issue to Slack or GitHub ■ Slack - https://launchpass.com/devwithlando ■ GitHub - https://github.com/lando/lando/issues/new/choose ERROR ==> connect ENOENT /var/run/docker.sock 本件について、以下のIssueで言及されていました。 ...

2023年12月21日 · 2 分 · Nakamura

drushのコマンドの備忘録

概要 Drupalのモジュールの開発において、使用頻度が高かったコマンドのメモです。 キャッシュのクリア drush cr 翻訳ファイルのインポート 以下は、itaijiというモジュールの日本語ファイルをインポートしている例です。 drush locale:import ja /app/web/modules/custom/Drupal-module-itaiji/translations/itaiji.ja.po モジュールの再インストール drush pm-uninstall itaiji && drush en itaiji

2023年12月20日 · 1 分 · Nakamura

Oxygen XML Editorのイメージマップエディタの使用例

概要 Oxygen XML Editorのイメージマップエディタの使用方法に関する説明です。 動画 https://youtu.be/9dZQ1v0Rky0?si=8EhAZdVsLqgPz2Rf 使用方法 以下のようなTEI/XMLファイルを用意します。<graphic>のurlの値は、当該ファイルからの相対パスや、PC上の絶対パス、およびインターネット上で公開されているURLを指定します。 以下の例では、TEI/XMLファイルと同じフォルダに格納されているdigidepo_3437686_pn_null_9c48d89b-e2ec-4593-8d00-6fbc1d29d1bd.jpgというファイルを参照しています。 <?xml version="1.0" ?> <?xml-model href="http://www.tei-c.org/release/xml/tei/custom/schema/relaxng/tei_all.rng" type="application/xml" schematypens="http://relaxng.org/ns/structure/1.0"?> <TEI xmlns="http://www.tei-c.org/ns/1.0"> <teiHeader> <fileDesc> <titleStmt> <title>Sample</title> </titleStmt> <publicationStmt> <ab/> </publicationStmt> <sourceDesc> <ab/> </sourceDesc> </fileDesc> </teiHeader> <facsimile> <surface> <graphic url="digidepo_3437686_pn_null_9c48d89b-e2ec-4593-8d00-6fbc1d29d1bd.jpg"/> </surface> </facsimile> </TEI> 画面下部の「作者」というボタンをクリックすると、以下のように「イメージマップエディタ」が表示されます。上記の動画を参考に、アノテーションを付与します。 結果、以下のようにzoneタグが自動的に追加されます。 <?xml version="1.0" ?> <?xml-model href="http://www.tei-c.org/release/xml/tei/custom/schema/relaxng/tei_all.rng" type="application/xml" schematypens="http://relaxng.org/ns/structure/1.0"?> <TEI xmlns="http://www.tei-c.org/ns/1.0"> <teiHeader> <fileDesc> <titleStmt> <title>Sample</title> </titleStmt> <publicationStmt> <ab/> </publicationStmt> <sourceDesc> <ab/> </sourceDesc> </fileDesc> </teiHeader> <facsimile> <surface> <graphic url="digidepo_3437686_pn_null_9c48d89b-e2ec-4593-8d00-6fbc1d29d1bd.jpg"/> <zone xml:id="zone_z3p_zll_szb" change="#ch1" lry="3960" lrx="2705" uly="730" ulx="2590"/> <zone xml:id="zone_fmm_xnv_szb" change="#ch2" lry="4038" lrx="1025" uly="700" ulx="850"/> </surface> </facsimile> </TEI> まとめ Oxygen XML Editorの利用に際して、参考になりましたら幸いです。 ...

2023年12月12日 · 1 分 · Nakamura

Nuxt3 x Vuetify x Cesium

概要 Nuxt3とVuetifyとCesiumを使用したサンプルリポジトリを作成しました。 ソースコード vue-cesiumを使用しています。 https://github.com/zouyaoji/vue-cesium GitHubリポジトリは以下です。 https://github.com/nakamura196/nuxt3-vuetify-cesium デモサイト https://nakamura196.github.io/nuxt3-vuetify-cesium/ まとめ 参考になりましたら幸いです。

2023年11月30日 · 1 分 · Nakamura

Nuxt 3とDecap CMSを試す

概要 Nuxt 3とDecap CMSを試してみましたので、その備忘録です。 https://decapcms.org/ Nuxt3プロジェクトの用意 既存のサイトにDecap CMSを追加する以下を参考にしました。 https://decapcms.org/docs/add-to-your-site/ まず、nuxt/contentモジュールを含む、Nuxt3のプロジェクトを用意します。 ソースコードの例はこちらです。 https://github.com/nakamura196/nuxt3-decapcms 以下の2つのファイルを作成しました。 # when using the default proxy server port local_backend: true # This line should *not* be indented publish_mode: editorial_workflow backend: name: git-gateway branch: main # Branch to update (optional; defaults to master) media_folder: public/img public_folder: /img collections: - name: 'blog' label: 'Blog' folder: 'content/blog' format: 'frontmatter' create: true slug: '{{year}}-{{month}}-{{day}}-{{slug}}' fields: - { label: 'Title', name: 'title', widget: 'string' } - { label: 'Publish Date', name: 'date', widget: 'datetime' } - { label: 'Description', name: 'description', widget: 'string' } - { label: 'Body', name: 'body', widget: 'markdown' } <!DOCTYPE html> <html> <head> <meta charset="utf-8" /> <meta name="viewport" content="width=device-width, initial-scale=1.0" /> <title>Content Manager</title> <!-- Include the script that enables Netlify Identity on this page. --> <script src="https://identity.netlify.com/v1/netlify-identity-widget.js"></script> </head> <body> <!-- Include the script that builds the page and powers Decap CMS --> <script src="https://unpkg.com/decap-cms@^3.0.0/dist/decap-cms.js"></script> </body> </html> そして、GitHubにpushしました。 ...

2023年11月30日 · 1 分 · Nakamura

AttributeError: 'ImageDraw' object has no attribute 'textsize'への対応

PythonのPillowで以下を使用していた際、 textsize = 14 font = ImageFont.truetype("Arial Unicode.ttf", size=textsize) txw, txh = draw.textlength(label, font=font) 以下のエラーが発生しました。 AttributeError: ‘ImageDraw’ object has no attribute ’textsize’ この対処法として、以下が参考になりました。 https://stackoverflow.com/questions/77038132/python-pillow-pil-doesnt-recognize-the-attribute-textsize-of-the-object-imag 具体的には、以下のように書き直しました。 textsize = 14 font = ImageFont.truetype("Arial Unicode.ttf", size=textsize) txw = draw.textlength(label, font=font) txh = textsize 参考になりましたら幸いです。

2023年11月26日 · 1 分 · Nakamura

Amazon SNSを用いたEC2上のVirtuosoの再起動

概要 以下の記事で、ヘルスチェックを行う方法について記述しました。 また、Virtuosoが停止した際の再起動のためのコマンドを以下に記述しました。 今回は、Amazon SNSを用いた通知に合わせて、Virtuosoを再起動してみます。 方法 EC2インスタンスにsudo rm -rf /usr/local/var/lib/virtuoso/db/virtuoso.lck && ...のようなコマンドを送信するには、SSM(AWS Systems Manager)に関する設定が必要でした。 IAMロールとポリシー IAMロールを新規に作成して、AmazonSSMFullAccessというポリシーを許可しました。はじめ、AmazonSSMManagedInstanceCoreというポリシーを許可していましたが、後述するlambda実行時に以下のようなエラーが発生して、うまく動作させることができませんでした。 An error occurred (InvalidInstanceId) when calling the SendCommand operation: Instances [[i-xxxxxx]] not in a valid state for account xxxxxx EC2インスタンスの「IAMロールを変更」から、作成したIAMロールを選択して更新しました。 AWS SAM: lamda関数の作成 AWS SAMを用いました。以下でのプロジェクトを作成します。 sam init hello_world/app.pyを以下のように作成しました。instance_idの部分には、要修正です。 import boto3 import time def lambda_handler(event, context): # EC2クライアントの初期化 ec2 = boto3.client('ec2') # 特定のEC2インスタンスIDを指定 instance_id = 'i-xxxxxxxx' # EC2インスタンスのステータスチェック response = ec2.describe_instance_status(InstanceIds=[instance_id]) if len(response['InstanceStatuses']) == 0: print(f"インスタンス {instance_id} は停止中です。") return # Define the command to be executed on the instance (e.g., restart software) command = 'sudo rm -rf /usr/local/var/lib/virtuoso/db/virtuoso.lck && sudo /usr/local/bin/virtuoso-t +configfile /usr/local/var/lib/virtuoso/db/virtuoso.ini' # SSMを通じてEC2インスタンスにコマンドを送信 ssm_client = boto3.client('ssm') response = ssm_client.send_command( InstanceIds=[instance_id], DocumentName='AWS-RunShellScript', Parameters={'commands': [command]} ) time.sleep(1.0) command_id = response['Command']['CommandId'] output = ssm_client.get_command_invocation( CommandId=command_id, InstanceId=instance_id, ) print("コマンドを実行しました。") # Extract only the necessary information from the output simplified_response = { "Output": output['StandardOutputContent'], "Error": output['StandardErrorContent'], } return simplified_response また、hello_word/requirements.txtにboto3を追記しました。 ...

2023年11月24日 · 2 分 · Nakamura

samでError: Running AWS SAM projects locally requires Docker...への対応

概要 AWS SAMを使ってsam local invokeを試した際、以下のメッセージが表示されました。 Error: Running AWS SAM projects locally requires Docker. Have you got it installed and running? 環境はMacで、Dockerも動作していました。 対処法 以下を実行することで、解決しました。 sudo ln -s ~/.docker/run/docker.sock /var/run/docker.sock 以下を参考にしました。 https://github.com/lando/lando/issues/3533 まとめ 同様の事象でお困りの方の参考になりましたら幸いです。

2023年11月24日 · 1 分 · Nakamura

Nuxt 3 x Composition APIでLeaflet Marker Clusterを試す

概要 以下の記事で、Nuxt 3でLeaflet Marker Clusterを試す方法を紹介しました。今回は、Composition APIを使った書き方に更新したので、その備忘録です。 インストール 以下をインストールします。 npm i leaflet leaflet.markercluster @vue-leaflet/vue-leaflet npm i -D @types/leaflet @types/leaflet.markercluster ソースコード 以下を参考にしてください。 https://github.com/nakamura196/nuxt3-demo/blob/main/components/map/MarkerCluster.vue まとめ TypeScriptに一部対応できていない点がありますが、参考になりましたら幸いです。

2023年11月24日 · 1 分 · Nakamura