Ruby言語で作られたプログラムのパッケージ「RubyGem」。
RubyGems.orgで無料かつ比較的簡単に作成したgemを公開することができるので、自分も自作のgemをいくつか公開している。
- imagetools 画像処理ツール。
- qdumpfs pdumpfs改造版。
- diskcatalog ディスクカタログツール。
しかし今回、プライベートで使用するために作成していたgemをうっかりRubyGems.orgで公開しそうになった。一回公開してしまうと、取り消しがやっかいらしいので(gem yank
すればよいらしいが、ファイルが残ったりするらしい)、再発対策を探した。
allowed_push_hostを生かしておく。
結局答えは簡単で、.gemspecの雛形にある以下の部分のコメントを外して有効にしておけばよい。
# Prevent pushing this gem to RubyGems.org. To allow pushes either set the 'allowed_push_host'
# to allow pushing to a single host or delete this section to allow pushing to any host.
if spec.respond_to?(:metadata)
spec.metadata["allowed_push_host"] = "TODO: Set to 'http://mygemserver.com'"
else
raise "RubyGems 2.0 or newer is required to protect against " \
"public gem pushes."
end
これでallowed_push_hostに指定したホスト以外にはpushできないので、RubyGemsへpushできなくなる(TODO以下のホストは存在しないので)。
この状態で実行すると以下のようなエラーが表示された。
Pushing gem to TODO: Set to 'http://mygemserver.com'...
ERROR: While executing gem ... (URI::InvalidURIError)
bad URI(is not URI?): "TODO: Set to 'http://mygemserver.com'"
これで極秘gemを全世界に公開といった悲劇は防げるはず…