GeekFactory

int128.hatenablog.com

スクリプトコンソール上でSlaveでコマンドを実行する

Jenkinsのスクリプトコンソールを利用すると、Slaveで任意のコマンドを実行できます。具体的には、 RemotingDiagnostics.executeGroovy() メソッドを利用してSlaveでGroovyスクリプトを実行します。

import hudson.util.RemotingDiagnostics

// Slaveノード名
def node = 'node-name'

// 実行したいコマンド
def command = 'uname -a'

println RemotingDiagnostics.executeGroovy("""
def p = '$command'.execute()
p.waitFor()
println p.in.text
""", Jenkins.instance.slaves.find { it.name == node }.channel)

宣言的APIクライアントSpring Cloud Feignを使ってみる

Spring Cloud Feignを利用すると、Spring MVCと同じアノテーション(@RequestMapping)を使ってAPIクライアントを定義できます。同じアノテーションが使えるので学習コストを抑えられるメリットがあるでしょう。また、APIサーバとAPIクライアントの仕様が同じ場合は共通の宣言が使えます。APIレスポンスを加工して返すといった単純な場合に役立ちそうです。

GitHub APIクライアントの例を以下に示します。

import org.springframework.cloud.netflix.feign.FeignClient
import org.springframework.web.bind.annotation.PathVariable
import org.springframework.web.bind.annotation.RequestMapping
import org.springframework.web.bind.annotation.RequestMethod

@FeignClient(name = 'github', url = 'https://api.github.com')
interface GitHubClient {

    @RequestMapping(method = RequestMethod.GET, value = '/users/{userName}/events')
    List<GHEvent> findUserEvents(@PathVariable('userName') String userName)

}

@FeignClientを付けるとHystrixも有効になります。デフォルトのタイムアウト(1秒)は以下の設定で変更できます。

# application.yml
hystrix:
  command:
    default:
      execution:
        isolation:
          thread:
            timeoutInMilliseconds: 60000

以下の依存関係を追加するとFeignが利用できるようになります。

// build.gradle
dependencies {
    compile 'org.springframework.cloud:spring-cloud-starter-feign:1.2.1.RELEASE'
}

Spring Cloud Feignの詳細は下記のドキュメントを参照してください。

http://cloud.spring.io/spring-cloud-static/spring-cloud-netflix/1.2.1.RELEASE/#spring-cloud-feign

参考までに、サンプルプロジェクトを少しずつ作ってたりします。

github.com

ACMのドメイン所有確認メールをSESで受信

ACMAmazon Certificate Manager)でSSL証明書を発行するには、ドメイン管理者に送付されるメールで承認をクリックする必要があります。ドメインの管理組織が異なる場合やメールサーバを用意していない場合は、ドメイン管理者へのメールをSESで受け取ることも可能です。

以下のフローでメールを受信します。

  1. ACM(メール送信)
  2. Route53(MXレコード参照)
  3. SES(メール受信)
  4. S3(メール格納)

具体的なオペレーションは以下を参照してください。

dev.classmethod.jp

S3には生のメールが格納されます。承認用のURLを見つけて開けばOKです。

参考までに、ACMから送付されるメールはマルチパートなので以下の形式になっています。

  • ヘッダ
  • マルチパートのヘッダ
  • テキスト形式
  • マルチパートのヘッダ
  • HTML形式

メールの一部を抜粋します。

Return-Path: <****@bounces.certificates.amazon.com>
Received: from a11-104.smtp-out.amazonses.com (a11-104.smtp-out.amazonses.com [54.240.11.104])
 by inbound-smtp.us-east-1.amazonaws.com with SMTP id ****
 for webmaster@****;
 Sat, 22 Oct 2016 03:52:16 +0000 (UTC)
X-SES-Spam-Verdict: PASS
X-SES-Virus-Verdict: PASS
Received-SPF: pass (spfCheck: domain of bounces.certificates.amazon.com designates 54.240.11.104 as permitted sender) client-ip=54.2
40.11.104; envelope-from=****@bounces.certificates.amazon.com; helo=a11-104.
smtp-out.amazonses.com;
(中略)

------=_Part_53514382_216701969.1477108335332
Content-Type: text/plain; charset=utf-8
Content-Transfer-Encoding: 7bit

Greetings from Amazon Web Services,

We received a request to issue an SSL/TLS certificate for ****.

Verify that the domain, AWS account ID, and certificate identifier
below correspond to a request from you or someone in your organization.

Domain: ****
AWS account number: ****
AWS Region name: ****
Certificate identifier: ****

To approve this request, go to Amazon Certificate Approvals at
https://certificates.amazon.com/approvals?code=****&context=****
and follow the instructions on the page.

If you choose not to approve this request, you do not need to do anything.
(中略)
------=_Part_53514382_216701969.1477108335332
Content-Type: text/html; charset=utf-8
Content-Transfer-Encoding: quoted-printable

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.=
w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns=3D"http://www.w3.org/1999/xhtml">
(中略)
------=_Part_53514382_216701969.1477108335332--