grim/hgkeeper

f70ee21d6c1c
Parents 84baf61558d2
Children bc46a398eba6
Rename the --disable-http serve flag to --disable-hgweb.

The HTTP interface will be required going forward.
  • +4 -4
    README.md
  • +22 -10
    http/server.go
  • +12 -20
    serve/command.go
  • --- a/README.md Mon Mar 07 02:08:55 2022 -0600
    +++ b/README.md Mon Mar 07 02:11:52 2022 -0600
    @@ -84,18 +84,18 @@
    The `serve` command is the main mode of operation which is to provide access to
    the repositories.
    -You can optionally disable either one of the HTTP or SSH servers to limit
    +You can optionally disable either one of the HGWeb or SSH servers to limit
    resources or just disable the portions you don't need.
    For example, say you don't need public access or the web interface at all, you
    -can disable it by passing `--disable-http` to the `serve` command or by setting
    -the `HGK_DISABLE_HTTP` environment variable to `true`.
    +can disable it by passing `--disable-hgweb` to the `serve` command or by setting
    +the `HGK_DISABLE_HGWEB` environment variable to `true`.
    Likewise, if you just want to serve up read only repositories over http you can
    disable the SSH server by passing `--disable-ssh` to the `serve` command or by
    setting the `HGK_DISABLE_SSH` environment variable to `true`.
    -The `--disable-http` and `--disable-ssh` options are mutually exclusive and
    +The `--disable-hgweb` and `--disable-ssh` options are mutually exclusive and
    passing both will stop HGKeeper from starting.
    The `serve` command also has options to tell HGKeeper how it can be accessed
    --- a/http/server.go Mon Mar 07 02:08:55 2022 -0600
    +++ b/http/server.go Mon Mar 07 02:11:52 2022 -0600
    @@ -19,16 +19,21 @@
    externalPort string
    }
    -func NewServer(listenAddr string, externalHostname, externalPort string) (*Server, error) {
    - return &Server{
    +func NewServer(listenAddr string, disableHGWeb bool, externalHostname, externalPort string) (*Server, error) {
    + s := &Server{
    listenAddr: listenAddr,
    server: &http.Server{
    Addr: listenAddr,
    },
    - hgw: hgweb.New(),
    externalHostname: externalHostname,
    externalPort: externalPort,
    - }, nil
    + }
    +
    + if !disableHGWeb {
    + s.hgw = hgweb.New()
    + }
    +
    + return s, nil
    }
    func (s *Server) Listen() error {
    @@ -51,11 +56,16 @@
    mux.Handle("/static/", http.StripPrefix("/static", fileServer))
    - hgwHandler, err := s.hgw.Handler()
    - if err != nil {
    - return err
    + if s.hgw != nil {
    + log.Infof("enabling HGWeb CGI server")
    + hgwHandler, err := s.hgw.Handler()
    + if err != nil {
    + return err
    + }
    + mux.Handle("/", hgwHandler)
    + } else {
    + log.Infof("not enabling HGWeb CGI server as requested")
    }
    - mux.Handle("/", hgwHandler)
    s.server.Handler = Logger(mux)
    @@ -65,8 +75,10 @@
    }
    func (s *Server) Close() {
    - if err := s.hgw.Close(); err != nil {
    - log.Warnf("failed to close hgweb: %v", err)
    + if s.hgw != nil {
    + if err := s.hgw.Close(); err != nil {
    + log.Warnf("failed to close hgweb: %v", err)
    + }
    }
    if err := s.server.Close(); err != nil {
    --- a/serve/command.go Mon Mar 07 02:08:55 2022 -0600
    +++ b/serve/command.go Mon Mar 07 02:11:52 2022 -0600
    @@ -19,14 +19,14 @@
    SSHHostKeysPath string `kong:"flag,name='ssh-host-keys-path',env='HGK_SSH_HOST_KEYS_PATH',short='H',help='the path where host keys are kept',default='host-keys'"`
    HTTPAddr string `kong:"flag,name='http-listen-addr',env='HGK_HTTP_LISTEN_ADDR',help='what address the http server listens on',default=':8080'"`
    DisableSSH bool `kong:"flag,name='disable-ssh',env='HGK_DISABLE_SSH',help='disable the SSH server',default='false'"`
    - DisableHTTP bool `kong:"flag,name='disable-http',env='HGK_DISABLE_HTTP',help='disable the HTTP server',default='false'"`
    + DisableHGWeb bool `kong:"flag,name='disable-hgweb',env='HGK_DISABLE_HGWEB',help='disable the HGWEB cgi server',default='false'"`
    ExternalHostname string `kong:"flag,name='external-hostname',env='HGK_EXTERNAL_HOSTNAME',help='The external hostname of the hgkeeper instance. This is used to integrate with other ssh servers.'"`
    ExternalPort string `kong:"flag,name='external-port',env='HGK_EXTERNAL_PORT',help='The external port of the hgkeeper instance. This is used to itegrate with other ssh servers.',default='22222'"`
    }
    func (c *Command) Run(g *globals.Globals) error {
    - if c.DisableHTTP && c.DisableSSH {
    - return fmt.Errorf("both HTTP and SSH servers have been disabled")
    + if c.DisableHGWeb && c.DisableSSH {
    + return fmt.Errorf("both HGWeb and SSH servers have been disabled")
    }
    if err := access.Setup(g.ReposPath, g.AdminRepo); err != nil {
    @@ -40,7 +40,6 @@
    errChan := make(chan error, 10)
    var sshServer *ssh.Server
    - var httpServer *http.Server
    if c.DisableSSH {
    log.Info("SSH server has been disabled")
    @@ -53,16 +52,11 @@
    defer sshServer.Close()
    }
    - if c.DisableHTTP {
    - log.Info("HTTP server has been disabled")
    - } else {
    - var err error
    - httpServer, err = http.NewServer(c.HTTPAddr, c.ExternalHostname, c.ExternalPort)
    - if err != nil {
    - return err
    - }
    - defer httpServer.Close()
    + httpServer, err := http.NewServer(c.HTTPAddr, c.DisableHGWeb, c.ExternalHostname, c.ExternalPort)
    + if err != nil {
    + return err
    }
    + defer httpServer.Close()
    if !c.DisableSSH {
    go func() {
    @@ -72,13 +66,11 @@
    }()
    }
    - if !c.DisableHTTP {
    - go func() {
    - if err := httpServer.Listen(); err != nil {
    - errChan <- err
    - }
    - }()
    - }
    + go func() {
    + if err := httpServer.Listen(); err != nil {
    + errChan <- err
    + }
    + }()
    for {
    select {