-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Adding a configuration file for gitserver
Now that gitserver is a bit more mature, let's stop passing in so many flags and instead use the same config format that the rest of the omegaUp services use.
- Loading branch information
Showing
6 changed files
with
154 additions
and
44 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,90 @@ | ||
package main | ||
|
||
import ( | ||
"encoding/json" | ||
"io" | ||
) | ||
|
||
// DbConfig represents the configuration for the database. | ||
type DbConfig struct { | ||
Driver string | ||
DataSourceName string | ||
} | ||
|
||
// LoggingConfig represents the configuration for logging. | ||
type LoggingConfig struct { | ||
File string | ||
Level string | ||
} | ||
|
||
// GitserverConfig represents the configuration for the Grader. | ||
type GitserverConfig struct { | ||
// RootPath is the root path of all repositories. | ||
RootPath string | ||
|
||
// PublicKeyBase64 is the base64-encoded public key of the omegaUp frontend. | ||
// Used for verifying Paseto tokens. | ||
PublicKeyBase64 string | ||
|
||
// SecretToken is a shared secret with the frontend that can be used to | ||
// authenticate instead of using PKI for speeding up tests. | ||
SecretToken string | ||
|
||
// Port is the TCP port in which the server will listen. | ||
Port uint16 | ||
|
||
// PprofPort is the TCP port in which the pprof server will listen. | ||
PprofPort uint16 | ||
|
||
// LibinteractivePath is the path of libinteractive.jar. | ||
LibinteractivePath string | ||
|
||
// AllowDirectPushToMaster determines whether gitserver allows pushing | ||
// directly to master. | ||
AllowDirectPushToMaster bool | ||
} | ||
|
||
// Config represents the configuration for the whole program. | ||
type Config struct { | ||
Db DbConfig | ||
Logging LoggingConfig | ||
Gitserver GitserverConfig | ||
} | ||
|
||
var defaultConfig = Config{ | ||
Db: DbConfig{ | ||
Driver: "sqlite3", | ||
DataSourceName: "./omegaup.db", | ||
}, | ||
Logging: LoggingConfig{ | ||
File: "/var/log/omegaup/gitserver.log", | ||
Level: "info", | ||
}, | ||
Gitserver: GitserverConfig{ | ||
RootPath: "/var/lib/omegaup/problems.git", | ||
PublicKeyBase64: "gKEg5JlIOA1BsIxETZYhjd+ZGchY/rZeQM0GheAWvXw=", | ||
SecretToken: "", | ||
Port: 33861, | ||
PprofPort: 33862, | ||
LibinteractivePath: "/usr/share/java/libinteractive.jar", | ||
AllowDirectPushToMaster: false, | ||
}, | ||
} | ||
|
||
// DefaultConfig returns a default Config. | ||
func DefaultConfig() Config { | ||
return defaultConfig | ||
} | ||
|
||
// NewConfig creates a new Config from the specified reader. | ||
func NewConfig(reader io.Reader) (*Config, error) { | ||
config := defaultConfig | ||
|
||
// Read basic config | ||
decoder := json.NewDecoder(reader) | ||
if err := decoder.Decode(&config); err != nil { | ||
return nil, err | ||
} | ||
|
||
return &config, nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,18 @@ | ||
module github.com/omegaup/gitserver | ||
|
||
go 1.12 | ||
|
||
require ( | ||
github.com/coreos/go-systemd v0.0.0-20190620071333-e64a0ec8b42a | ||
github.com/inconshreveable/log15 v0.0.0-20180818164646-67afb5ed74ec | ||
github.com/lhchavez/git2go v0.0.0-20190221190548-e9c961d8b627 | ||
github.com/o1egl/paseto v1.0.0 | ||
github.com/omegaup/githttp v0.0.0-20190424035114-ded1cff40e18 | ||
github.com/omegaup/go-base v0.0.0-20190624033755-26f895597739 | ||
github.com/omegaup/quark v1.1.19 | ||
github.com/pkg/errors v0.8.1 | ||
github.com/prometheus/client_golang v1.0.0 | ||
github.com/saintfish/chardet v0.0.0-20120816061221-3af4cd4741ca | ||
golang.org/x/crypto v0.0.0-20190103213133-ff983b9c42bc | ||
golang.org/x/text v0.3.2 | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters