Class: CfnVpn::ClientVpn
- Inherits:
-
Object
- Object
- CfnVpn::ClientVpn
- Defined in:
- lib/cfnvpn/clientvpn.rb
Instance Attribute Summary collapse
-
#endpoint_id ⇒ Object
readonly
Returns the value of attribute endpoint_id.
Instance Method Summary collapse
- #delete_route(cidr, subnet) ⇒ Object
- #get_associations ⇒ Object
- #get_auth_rules(dns_route = nil) ⇒ Object
- #get_config ⇒ Object
- #get_dns_servers ⇒ Object
- #get_endpoint ⇒ Object
- #get_endpoint_id ⇒ Object
- #get_groups_for_route(cidr) ⇒ Object
- #get_rekove_list ⇒ Object
- #get_routes(dns_route = nil) ⇒ Object
- #get_sessions ⇒ Object
-
#initialize(name, region) ⇒ ClientVpn
constructor
A new instance of ClientVpn.
- #kill_session(connection_id) ⇒ Object
- #put_revoke_list(revoke_list) ⇒ Object
- #revoke_auth(cidr) ⇒ Object
Constructor Details
#initialize(name, region) ⇒ ClientVpn
Returns a new instance of ClientVpn.
10 11 12 13 14 |
# File 'lib/cfnvpn/clientvpn.rb', line 10 def initialize(name,region) @client = Aws::EC2::Client.new(region: region) @name = name @endpoint_id = self.get_endpoint_id() end |
Instance Attribute Details
#endpoint_id ⇒ Object (readonly)
Returns the value of attribute endpoint_id.
8 9 10 |
# File 'lib/cfnvpn/clientvpn.rb', line 8 def endpoint_id @endpoint_id end |
Instance Method Details
#delete_route(cidr, subnet) ⇒ Object
136 137 138 139 140 141 142 |
# File 'lib/cfnvpn/clientvpn.rb', line 136 def delete_route(cidr, subnet) @client.delete_client_vpn_route({ client_vpn_endpoint_id: @endpoint_id, target_vpc_subnet_id: subnet, destination_cidr_block: cidr }) end |
#get_associations ⇒ Object
110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 |
# File 'lib/cfnvpn/clientvpn.rb', line 110 def get_associations() associations = [] resp = @client.describe_client_vpn_target_networks({ client_vpn_endpoint_id: @endpoint_id }) resp.client_vpn_target_networks.each do |net| subnet_resp = @client.describe_subnets({ subnet_ids: [net.target_network_id] }) subnet = subnet_resp.subnets.first groups = get_groups_for_route(subnet.cidr_block) associations.push({ association_id: net.association_id, target_network_id: net.target_network_id, status: net.status.code, cidr: subnet.cidr_block, az: subnet.availability_zone, groups: groups.join(' ') }) end return associations end |
#get_auth_rules(dns_route = nil) ⇒ Object
85 86 87 88 89 90 91 92 93 94 95 |
# File 'lib/cfnvpn/clientvpn.rb', line 85 def get_auth_rules(dns_route=nil) rules = [] @client.({client_vpn_endpoint_id: @endpoint_id}) do |resp| if dns_route rules.concat resp..select {|rule| rule.description.include?(dns_route) } else rules.concat resp.routes end end return rules end |
#get_config ⇒ Object
35 36 37 38 39 40 |
# File 'lib/cfnvpn/clientvpn.rb', line 35 def get_config() resp = @client.export_client_vpn_client_configuration({ client_vpn_endpoint_id: @endpoint_id }) return resp.client_configuration end |
#get_dns_servers ⇒ Object
31 32 33 |
# File 'lib/cfnvpn/clientvpn.rb', line 31 def get_dns_servers() return get_endpoint().dns_servers end |
#get_endpoint ⇒ Object
16 17 18 19 20 21 22 23 24 25 |
# File 'lib/cfnvpn/clientvpn.rb', line 16 def get_endpoint() resp = @client.describe_client_vpn_endpoints({ filters: [{ name: "tag:cfnvpn:name", values: [@name] }] }) if resp.client_vpn_endpoints.empty? CfnVpn::Log.logger.error "unable to find endpoint with tag Key: cfnvpn:name with Value: #{@name}" raise "Unable to find client vpn" end return resp.client_vpn_endpoints.first end |
#get_endpoint_id ⇒ Object
27 28 29 |
# File 'lib/cfnvpn/clientvpn.rb', line 27 def get_endpoint_id() return get_endpoint().client_vpn_endpoint_id end |
#get_groups_for_route(cidr) ⇒ Object
97 98 99 100 101 102 103 104 105 106 107 108 |
# File 'lib/cfnvpn/clientvpn.rb', line 97 def get_groups_for_route(cidr) auth_resp = @client.({ client_vpn_endpoint_id: @endpoint_id, filters: [ { name: 'destination-cidr', values: [cidr] } ] }) return auth_resp..map {|rule| rule.group_id } end |
#get_rekove_list ⇒ Object
42 43 44 45 46 47 |
# File 'lib/cfnvpn/clientvpn.rb', line 42 def get_rekove_list() resp = @client.export_client_vpn_client_certificate_revocation_list({ client_vpn_endpoint_id: @endpoint_id }) return resp.certificate_revocation_list end |
#get_routes(dns_route = nil) ⇒ Object
73 74 75 76 77 78 79 80 81 82 83 |
# File 'lib/cfnvpn/clientvpn.rb', line 73 def get_routes(dns_route=nil) routes = [] @client.describe_client_vpn_routes({client_vpn_endpoint_id: @endpoint_id}).each do |resp| if dns_route routes.concat resp.routes.select {|route| route.description.include?(dns_route) } else routes.concat resp.routes end end return routes end |
#get_sessions ⇒ Object
57 58 59 60 61 62 63 64 |
# File 'lib/cfnvpn/clientvpn.rb', line 57 def get_sessions() params = { client_vpn_endpoint_id: @endpoint_id, max_results: 20 } resp = @client.describe_client_vpn_connections(params) return resp.connections end |
#kill_session(connection_id) ⇒ Object
66 67 68 69 70 71 |
# File 'lib/cfnvpn/clientvpn.rb', line 66 def kill_session(connection_id) @client.terminate_client_vpn_connections({ client_vpn_endpoint_id: @endpoint_id, connection_id: connection_id }) end |
#put_revoke_list(revoke_list) ⇒ Object
49 50 51 52 53 54 55 |
# File 'lib/cfnvpn/clientvpn.rb', line 49 def put_revoke_list(revoke_list) list = File.read(revoke_list) @client.import_client_vpn_client_certificate_revocation_list({ client_vpn_endpoint_id: @endpoint_id, certificate_revocation_list: list }) end |
#revoke_auth(cidr) ⇒ Object
144 145 146 147 148 149 150 151 |
# File 'lib/cfnvpn/clientvpn.rb', line 144 def revoke_auth(cidr) endpoint_id = get_endpoint_id() @client.revoke_client_vpn_ingress({ client_vpn_endpoint_id: @endpoint_id, target_network_cidr: cidr, revoke_all_groups: true }) end |