Skip to content

Commit

Permalink
Potentially fix deleting wireguard peer (#304)
Browse files Browse the repository at this point in the history
  • Loading branch information
michaeljguarino authored Feb 28, 2023
1 parent 3973d65 commit 83d939f
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 4 deletions.
3 changes: 3 additions & 0 deletions assets/src/components/account/vpn/VPN.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ import {
} from 'react'
import { useQuery } from '@apollo/client'

import { SHORT_POLL_INTERVAL } from 'components/cluster/constants'

import { ScrollablePage } from '../../utils/layout/ScrollablePage'
import VPNClientList from '../../vpn/VPNClientList'
import {
Expand All @@ -26,6 +28,7 @@ import { VPNHeaderActions } from './VPNHeaderActions'
function VPN() {
const { data: { wireguardPeers } = {}, loading, refetch } = useQuery<Pick<RootQueryType, 'wireguardPeers'>>(WireguardPeers, {
fetchPolicy: 'network-only',
pollInterval: SHORT_POLL_INTERVAL,
})
const [selectedUsers, setSelectedUsers] = useState<Set<Key>>(new Set<Key>())
const columns = useMemo(() => [ColumnName, ColumnUser, ColumnAddress, ColumnPublicKey, ColumnStatus, ColumnActions(refetch)], [refetch])
Expand Down
7 changes: 3 additions & 4 deletions lib/kube/client.ex
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ defmodule Kube.Client do
get_request :get_wireguard_peer, Kube.WireguardPeer, "vpn.plural.sh", "v1alpha1", "wireguardpeers"
get_request :get_wireguard_server, Kube.WireguardServer, "vpn.plural.sh", "v1alpha1", "wireguardservers"

delete_request :delete_wireguard_peer, "vpn.plural.sh", "v1alpha1", "wireguardpeers"

def get_application(name), do: get_application(name, name)

def list_slashcommands() do
Expand Down Expand Up @@ -50,10 +52,7 @@ defmodule Kube.Client do
defp has_email?(%Kube.WireguardPeer{metadata: %{annotations: %{"vpn.plural.sh/email" => e}}}, e), do: true
defp has_email?(_, _), do: false

def delete_wireguard_peer(name) do
path_builder("vpn.plural.sh", "v1alpha1", "wireguardpeers", Console.namespace("wireguard"), name)
|> make_request("delete", Kube.WireguardPeer)
end
def delete_wireguard_peer(name), do: delete_wireguard_peer(Console.namespace("wireguard"), name)

def create_wireguard_peer(email, name) do
namespace = Console.namespace("wireguard")
Expand Down
14 changes: 14 additions & 0 deletions lib/kube/client/base.ex
Original file line number Diff line number Diff line change
Expand Up @@ -47,4 +47,18 @@ defmodule Kube.Client.Base do
end
end
end

defmacro delete_request(name, g, v, k) do
quote do
def unquote(name)(namespace, name, params \\ %{}) do
%Kazan.Request{
method: "delete",
path: path_builder(unquote(g), unquote(v), unquote(k), namespace, name),
query_params: params,
response_model: Kazan.Models.Apimachinery.Meta.V1.Status
}
|> Kazan.run()
end
end
end
end

0 comments on commit 83d939f

Please sign in to comment.