-
Notifications
You must be signed in to change notification settings - Fork 18
/
options.go
39 lines (34 loc) · 957 Bytes
/
options.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
package firebase
import (
"errors"
"fmt"
"os"
)
// Options is storage for configurable Firebase options.
type Options struct {
// ServiceAccountPath is the path to load the Service Account.
ServiceAccountPath string
// ServiceAccountCredential is the credential for the Service Account.
ServiceAccountCredential *GoogleServiceAccountCredential
}
// ensureServiceAccount sets the Service Account associated with the Firebase Options.
func (o *Options) ensureServiceAccount() error {
if o.ServiceAccountCredential != nil {
// credential already loaded
return nil
}
if o.ServiceAccountPath == "" {
return errors.New("ServiceAccountPath cannot be empty.")
}
f, err := os.Open(o.ServiceAccountPath)
if err != nil {
return fmt.Errorf("Service Account file cannot be opened: %s %v", o.ServiceAccountPath, err)
}
defer f.Close()
c, err := loadCredential(f)
if err != nil {
return err
}
o.ServiceAccountCredential = c
return nil
}