Skip to content

fix: use typed wireguard public keys in database structs #2639

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Jun 24, 2022
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
fixup! Merge branch 'main' into colin/wg-db-typed
  • Loading branch information
coadler committed Jun 24, 2022
commit bcb95d46f47bd7b854d42472d0847c2c52f74d07
24 changes: 24 additions & 0 deletions coderd/database/dbtypes/wireguard.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,18 @@ import (

type NodePublic key.NodePublic

func (n NodePublic) String() string {
return key.NodePublic(n).String()
}

func (n NodePublic) MarshalJSON() ([]byte, error) {
j, err := key.NodePublic(n).MarshalText()
// surround in quotes to make it a JSON string
j = append([]byte{'"'}, j...)
j = append(j, '"')
return j, err
}

func (n NodePublic) Value() (driver.Value, error) {
return key.NodePublic(n).MarshalText()
}
Expand All @@ -26,6 +38,18 @@ func (n *NodePublic) Scan(value interface{}) error {

type DiscoPublic key.DiscoPublic

func (n DiscoPublic) String() string {
return key.DiscoPublic(n).String()
}

func (n DiscoPublic) MarshalJSON() ([]byte, error) {
j, err := key.DiscoPublic(n).MarshalText()
// surround in quotes to make it a JSON string
j = append([]byte{'"'}, j...)
j = append(j, '"')
return j, err
}

func (n DiscoPublic) Value() (driver.Value, error) {
return key.DiscoPublic(n).MarshalText()
}
Expand Down