This repository has been archived by the owner on May 30, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 7
/
eni.clj
34 lines (31 loc) · 1.48 KB
/
eni.clj
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
(ns bastion.eni
(:require [clojure.core.async :refer [<!! timeout]]
[cognitect.aws.client.api :as aws]
[bastion.clients :as clients]))
(defn- describe-network-interfaces
[attachment-description]
(println "Describing network interfaces for" attachment-description)
(aws/invoke @clients/ec2
{:op :DescribeNetworkInterfaces
:request {:Filters
[{:Name "description"
:Values [attachment-description]}]}}))
(defn wait-for-deletion
[attachment-description]
(println "Waiting for ENI deletion")
(loop [description (describe-network-interfaces attachment-description)]
(let [network-interfaces (:NetworkInterfaces description)]
(if (> (count network-interfaces) 0)
(do
(<!! (timeout 2000)) ; ENI destruction may take some time
(recur (describe-network-interfaces attachment-description)))))))
(defn get-public-ip
[attachment-description]
(println "Getting public IP for bastion")
(loop [description (describe-network-interfaces attachment-description)]
(let [network-interfaces (:NetworkInterfaces description)]
(if-let [public-ip (get-in (first network-interfaces) [:Association :PublicIp])]
public-ip
(do
(<!! (timeout 2000)) ; ENI attachment & IP assignment may take some time
(recur (describe-network-interfaces attachment-description)))))))