Skip to content

Commit

Permalink
fix: reads policy file in the get policy api when mode is file
Browse files Browse the repository at this point in the history
  • Loading branch information
pallabpain committed Jun 22, 2024
1 parent 17caa77 commit f4758c9
Showing 1 changed file with 11 additions and 7 deletions.
18 changes: 11 additions & 7 deletions hscontrol/grpcv1.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,9 @@ package hscontrol

import (
"context"
"encoding/json"
"errors"
"io"
"os"
"sort"
"strings"
"time"
Expand Down Expand Up @@ -685,17 +686,20 @@ func (api headscaleV1APIServer) GetPolicy(
return nil, err
}

// We retain the HuJSON format of the policy while storing
// it in the database. But should we return the same in the
// get policy response? Or should we consider returning the
// policy in JSON format?

return &v1.GetPolicyResponse{
Policy: p.Data,
UpdatedAt: timestamppb.New(p.UpdatedAt),
}, nil
case types.PolicyModeFile:
b, err := json.Marshal(api.h.ACLPolicy)
// Read the file and return the contents as-is.
f, err := os.Open(api.h.cfg.Policy.Path)
if err != nil {
return nil, err
}

defer f.Close()

b, err := io.ReadAll(f)
if err != nil {
return nil, err
}
Expand Down

0 comments on commit f4758c9

Please sign in to comment.