package main

import (
	"os"

	"github.com/remind101/empire/pkg/heroku"
)

var cmdCertAttach = &Command{
	Run:      runCertAttach,
	Usage:    "cert-attach <aws_cert_arn>",
	NeedsApp: true,
	Category: "certs",
	Short:    "attach a certificate to an app",
	Long: `
Attaches an SSL certificate to an applications web process. When using the ECS backend, this will attach an IAM server certificate to the applications ELB.

Before running this command, you should upload your SSL certificate and key to IAM using the AWS CLI.

Examples:

    $ aws iam upload-server-certificate --server-certificate-name myServerCertificate --certificate-body file://public_key_cert_file.pem --private-key file://my_private_key.pem --certificate-chain file://my_certificate_chain_file.pem
	# ^^ The above command will return the ARN of the certificate, you'll need that for the command below
	# Say it returns the arn arn:aws:iam::123456789012:server-certificate/myServerCertificate, you'd use that like this:
	$ emp cert-attach arn:aws:iam::123456789012:server-certificate/myServerCertificate -a myapp
`,
}

func runCertAttach(cmd *Command, args []string) {
	if len(args) == 0 {
		cmd.PrintUsage()
		os.Exit(2)
	}

	cert := args[0]

	_, err := client.AppUpdate(mustApp(), &heroku.AppUpdateOpts{
		Cert: &cert,
	})
	must(err)
}

package main

import (
	"os"

	"github.com/remind101/empire/pkg/heroku"
)

var cmdCertAttach = &Command{
	Run:      runCertAttach,
	Usage:    "cert-attach <aws_cert_name>",
	NeedsApp: true,
	Category: "certs",
	Short:    "attach a certificate to an app",
	Long: `
Attaches an SSL certificate to an applications web process. When using the ECS backend, this will attach an IAM server certificate to the applications ELB.

Before running this command, you should upload your SSL certificate and key to IAM using the AWS CLI.

Examples:

    $ aws iam upload-server-certificate --server-certificate-name myServerCertificate --certificate-body file://public_key_cert_file.pem --private-key file://my_private_key.pem --certificate-chain file://my_certificate_chain_file.pem
    $ emp cert-attach myServerCertificate -a myapp
`,
}

func runCertAttach(cmd *Command, args []string) {
	if len(args) == 0 {
		cmd.PrintUsage()
		os.Exit(2)
	}

	cert := args[0]

	_, err := client.AppUpdate(mustApp(), &heroku.AppUpdateOpts{
		Cert: &cert,
	})
	must(err)
}

--- 
+++ 
@@ -8,7 +8,7 @@
 
 var cmdCertAttach = &Command{
 	Run:      runCertAttach,
-	Usage:    "cert-attach <aws_cert_name>",
+	Usage:    "cert-attach <aws_cert_arn>",
 	NeedsApp: true,
 	Category: "certs",
 	Short:    "attach a certificate to an app",
@@ -20,7 +20,9 @@
 Examples:
 
     $ aws iam upload-server-certificate --server-certificate-name myServerCertificate --certificate-body file://public_key_cert_file.pem --private-key file://my_private_key.pem --certificate-chain file://my_certificate_chain_file.pem
-    $ emp cert-attach myServerCertificate -a myapp
+	# ^^ The above command will return the ARN of the certificate, you'll need that for the command below
+	# Say it returns the arn arn:aws:iam::123456789012:server-certificate/myServerCertificate, you'd use that like this:
+	$ emp cert-attach arn:aws:iam::123456789012:server-certificate/myServerCertificate -a myapp
 `,
 }
 
Update to indicate the ARN is used
