Add config flag for read-only mode, see #56

This commit is contained in:
Michael Mayer 2019-05-04 09:11:33 +02:00
parent 7074faabe0
commit e565195f23
8 changed files with 21 additions and 2 deletions

3
go.sum
View file

@ -9,7 +9,9 @@ github.com/DATA-DOG/go-sqlmock v1.3.3 h1:CWUqKXe0s8A2z6qCgkP4Kru7wC11YoAnoupUKFD
github.com/DATA-DOG/go-sqlmock v1.3.3/go.mod h1:f/Ixk793poVmq4qj/V1dPUg2JEAKC73Q5eFN3EC/SaM=
github.com/Shopify/sarama v1.19.0/go.mod h1:FVkBWblsNy7DGZRfXLU0O9RCGt5g3g3yEuWXgklEdEo=
github.com/Shopify/toxiproxy v2.1.4+incompatible/go.mod h1:OXgGpZ6Cli1/URJOF1DMxUHB2q5Ap20/P/eIdh4G0pI=
github.com/alecthomas/template v0.0.0-20160405071501-a0175ee3bccc h1:cAKDfWh5VpdgMhJosfJnn5/FoN2SRZ4p7fJNX58YPaU=
github.com/alecthomas/template v0.0.0-20160405071501-a0175ee3bccc/go.mod h1:LOuyumcjzFXgccqObfd/Ljyb9UuFJ6TxHnclSeseNhc=
github.com/alecthomas/units v0.0.0-20151022065526-2efee857e7cf h1:qet1QNfXsQxTZqLG4oE62mJzwPIB8+Tee4RNCL9ulrY=
github.com/alecthomas/units v0.0.0-20151022065526-2efee857e7cf/go.mod h1:ybxpYRFXyAe+OPACYpWeL0wqObRcbAqCMya13uyzqw0=
github.com/apache/thrift v0.0.0-20161221203622-b2a4d4ae21c7 h1:Fv9bK1Q+ly/ROk4aJsVMeuIwPel4bEnD8EPiI91nZMg=
github.com/apache/thrift v0.0.0-20161221203622-b2a4d4ae21c7/go.mod h1:cp2SuWMxlEZw2r+iP2GNCdIi4C1qmUzdZFSVb+bacwQ=
@ -357,6 +359,7 @@ google.golang.org/grpc v1.17.0 h1:TRJYBgMclJvGYn2rIMjj+h9KtMt5r1Ij7ODVRIZkwhk=
google.golang.org/grpc v1.17.0/go.mod h1:6QZJwpn2B+Zp71q/5VxRsJ6NXXVCE5NRUHRo+f3cWCs=
google.golang.org/grpc v1.19.0 h1:cfg4PD8YEdSFnm7qLV4++93WcmhH2nIUhMjhdCvl3j8=
google.golang.org/grpc v1.19.0/go.mod h1:mqu4LbDTu4XGKhr4mRzUsmM4RtVoemTSY81AxZiDr8c=
gopkg.in/alecthomas/kingpin.v2 v2.2.6 h1:jMFz6MfLP0/4fUyZle81rXUoxOBFi19VUFKVDOQfozc=
gopkg.in/alecthomas/kingpin.v2 v2.2.6/go.mod h1:FMv+mEhP44yOT+4EoQTLFTRgOQ1FBLkstjWtayDeSgw=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127 h1:qIbj1fsPNlZgppZ+VLlY7N33q108Sa+fhmuc+sWQYwY=

View file

@ -22,6 +22,7 @@ func configAction(ctx *cli.Context) error {
fmt.Printf("version %s\n", app.Version())
fmt.Printf("copyright %s\n", app.Copyright())
fmt.Printf("debug %t\n", app.Debug())
fmt.Printf("read-only %t\n", app.ReadOnly())
fmt.Printf("log-level %s\n", app.LogLevel())
fmt.Printf("config-file %s\n", app.ConfigFile())

View file

@ -14,7 +14,7 @@ var MigrateCommand = cli.Command{
}
func migrateAction(ctx *cli.Context) error {
app := context.NewContext( ctx)
app := context.NewContext(ctx)
log.Infoln("migrating database")

View file

@ -32,6 +32,7 @@ type Config struct {
Version string
Copyright string
Debug bool `yaml:"debug" flag:"debug"`
ReadOnly bool `yaml:"read-only" flag:"read-only"`
LogLevel string `yaml:"log-level" flag:"log-level"`
ConfigFile string
AssetsPath string `yaml:"assets-path" flag:"assets-path"`

View file

@ -19,6 +19,7 @@ func TestNewConfig(t *testing.T) {
assert.Equal(t, fsutil.ExpandedFilename("../../assets"), c.AssetsPath)
assert.False(t, c.Debug)
assert.False(t, c.ReadOnly)
}
func TestConfig_SetValuesFromFile(t *testing.T) {
@ -29,6 +30,7 @@ func TestConfig_SetValuesFromFile(t *testing.T) {
assert.Nil(t, err)
assert.False(t, c.Debug)
assert.False(t, c.ReadOnly)
assert.Equal(t, "/srv/photoprism", c.AssetsPath)
assert.Equal(t, "/srv/photoprism/cache", c.CachePath)
assert.Equal(t, "/srv/photoprism/photos/originals", c.OriginalsPath)

View file

@ -20,7 +20,7 @@ type Context struct {
config *Config
}
func initLogger(debug bool) {
func initLogger(debug bool) {
log.SetFormatter(&log.TextFormatter{
DisableColors: false,
FullTimestamp: true,
@ -162,6 +162,11 @@ func (c *Context) Debug() bool {
return c.config.Debug
}
// ReadOnly returns true if photo directories are write protected.
func (c *Context) ReadOnly() bool {
return c.config.ReadOnly
}
// LogLevel returns the logrus log level.
func (c *Context) LogLevel() log.Level {
if c.Debug() {
@ -364,6 +369,7 @@ func (c *Context) ClientConfig() ClientConfig {
"version": c.Version(),
"copyright": c.Copyright(),
"debug": c.Debug(),
"readonly": c.ReadOnly(),
"cameras": cameras,
"countries": countries,
"jsHash": jsHash,

View file

@ -19,4 +19,5 @@ func TestNewContext(t *testing.T) {
assert.Equal(t, fsutil.ExpandedFilename("../../assets"), c.AssetsPath())
assert.False(t, c.Debug())
assert.False(t, c.ReadOnly())
}

View file

@ -9,6 +9,11 @@ var GlobalFlags = []cli.Flag{
Usage: "run in debug mode",
EnvVar: "PHOTOPRISM_DEBUG",
},
cli.BoolFlag{
Name: "read-only, r",
Usage: "run in read-only mode",
EnvVar: "PHOTOPRISM_READ_ONLY",
},
cli.StringFlag{
Name: "config-file, c",
Usage: "load configuration from `FILENAME`",