blob: d16b57ad7261f42902542fd8db42c6ce8e06367e [file] [log] [blame]
// Copyright 2018 The Goma Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
package acl
import (
"context"
"fmt"
"io/ioutil"
"google.golang.org/protobuf/encoding/prototext"
pb "go.chromium.org/goma/server/proto/auth"
)
// Loader loads acl data.
type Loader interface {
Load(ctx context.Context) (*pb.ACL, error)
}
// StaticLoader loads static acl data.
type StaticLoader struct {
*pb.ACL
}
func (l StaticLoader) Load(ctx context.Context) (*pb.ACL, error) {
return l.ACL, nil
}
// FileLoader loads acl data from Filename.
type FileLoader struct {
Filename string
}
// Loads loads acl stored as text proto in file.
func (l FileLoader) Load(ctx context.Context) (*pb.ACL, error) {
b, err := ioutil.ReadFile(l.Filename)
if err != nil {
return nil, err
}
a := &pb.ACL{}
err = prototext.Unmarshal(b, a)
if err != nil {
return nil, fmt.Errorf("load error %s: %v", l.Filename, err)
}
return a, nil
}