fix(internal/peer): read admins file correctly

Previously, the 'keyRaw' slice was being allocated with a length of 0.
However, the 'Read()' function will only read up to the slice's length.
Together, this means that we always read 0 bytes from the admins file.
Now, we can use the 'io.ReadAll()' function to read all of the admins
file before parsing.
This commit is contained in:
Dustin Stiles 2025-03-24 12:41:56 -04:00
parent 433b4e03a4
commit d6cf91916f
Signed by: duwstiles
GPG Key ID: BCD9912EC231FC87

View File

@ -189,12 +189,12 @@ func (p *Peer) Run(ctx context.Context) error {
// loadAdmins ...
func (p *Peer) loadAdmins() ([]string, error) {
hasKeyFile, err := p.hasAdminsFile()
hasAdminsFile, err := p.hasAdminsFile()
if err != nil {
return nil, fmt.Errorf("failed to check for admins file: %w", err)
}
if !hasKeyFile {
if !hasAdminsFile {
if err := p.createAdminsFile(); err != nil {
return nil, fmt.Errorf("failed to create admins file: %w", err)
}
@ -236,8 +236,7 @@ func (p *Peer) readAdminsFile() ([]string, error) {
}
defer f.Close()
keyRaw := make([]byte, 0)
_, err = f.Read(keyRaw)
keyRaw, err := io.ReadAll(f)
if err != nil {
return nil, err
}