前回の記事でSpring Cloud GCP でSecret Manager に登録した秘密情報を取得する方法を調べたが、みるべきドキュメントのバージョンが違っていた
パッチバージョンの違いなので問題ないと思っていたが、かなり大きな変更があって実装も変更する必要があったので改めてやり方を調査する
1.2.3.RELEASEの場合
Dependencyの設定は変わらず必要
<dependency> <groupId>org.springframework.cloud</groupId> <artifactId>spring-cloud-gcp-starter-secretmanager</artifactId> </dependency>
しかし、1.2.3.RELEASEではbootstrap.yml
内でspring.cloud.gcp.secretmanager.bootstrap.enabled
をspring.cloud.gcp.secretmanager.secret-name-prefix
をあえて指定する必要がなくなった
さらに、bootstrap.yml
またはapplication.yml
内で以下のシンタックスを使用してシークレットを指定することができるようになった
# 1. Long form - specify the project ID, secret ID, and version sm://projects/<project-id>/secrets/<secret-id>/versions/<version-id>} # 2. Long form - specify project ID, secret ID, and use latest version sm://projects/<project-id>/secrets/<secret-id> # 3. Short form - specify project ID, secret ID, and version sm://<project-id>/<secret-id>/<version-id> # 4. Short form - default project; specify secret + version # # The project is inferred from the spring.cloud.gcp.secretmanager.project-id setting # in your bootstrap.properties (see Configuration) or from application-default credentials if # this is not set. sm://<secret-id>/<version> # 5. Shortest form - specify secret ID, use default project and latest version. sm://<secret-id>
1.2.2.RELEASEの場合はsecret.
というprefixを用意し、@ConfigurationProperties("secrets")
で受け取るConfigurationPropertiesクラスを新たに用意する必要があったが、既に利用していたapplication.yml内で以下のように指定することができるようになった
... service: oauth2: id: ${sm://my-secret-oauth2-id} secret: ${sm://my-secret-oauth2-password} ...
結果的に1.2.3.RELEASE のバージョンアップで簡単に使えるようになったのでよかった