Skip to content

Commit

Permalink
Generate WebHook secret by default
Browse files Browse the repository at this point in the history
Closes #179
  • Loading branch information
bobheadxi committed Apr 30, 2018
1 parent 3a63434 commit 74000d1
Show file tree
Hide file tree
Showing 5 changed files with 28 additions and 24 deletions.
12 changes: 12 additions & 0 deletions common/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ package common
import (
"archive/tar"
"compress/gzip"
"crypto/rand"
"encoding/base64"
"fmt"
"io"
"net/http"
Expand All @@ -11,6 +13,16 @@ import (
"strings"
)

// GenerateRandomString creates a rand.Reader-generated
// string for use with simple secrets and identifiers
func GenerateRandomString() (string, error) {
b := make([]byte, 32)
if _, err := io.ReadFull(rand.Reader, b); err != nil {
return "", err
}
return base64.URLEncoding.EncodeToString(b), nil
}

// CheckForDockerCompose returns error if current directory is a
// not a docker-compose project
func CheckForDockerCompose(cwd string) bool {
Expand Down
4 changes: 3 additions & 1 deletion daemon/inertia/auth/sessions.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ import (
"net/url"
"sync"
"time"

"github.com/ubclaunchpad/inertia/common"
)

// session are properties associated with session,
Expand Down Expand Up @@ -70,7 +72,7 @@ func (s *sessionManager) Close() {
// and adding session to memory
func (s *sessionManager) BeginSession(username string, w http.ResponseWriter, r *http.Request) error {
expiration := time.Now().Add(s.cookieTimeout)
id, err := generateSessionID()
id, err := common.GenerateRandomString()
if err != nil {
return errors.New("Failed to begin session for " + username + ": " + err.Error())
}
Expand Down
15 changes: 0 additions & 15 deletions daemon/inertia/auth/util.go

This file was deleted.

15 changes: 13 additions & 2 deletions input.go
Original file line number Diff line number Diff line change
@@ -1,14 +1,22 @@
package main

import (
"errors"
"fmt"
"io"
"os"
"path/filepath"

"github.com/ubclaunchpad/inertia/common"

"github.com/ubclaunchpad/inertia/client"
)

var (
errInvalidUser = errors.New("invalid user")
errInvalidAddress = errors.New("invalid IP address")
)

// addRemoteWalkthough is the command line walkthrough that asks
// users for RemoteVPS details
func addRemoteWalkthrough(in io.Reader, name, port, sshPort, currBranch string, config *client.Config) error {
Expand Down Expand Up @@ -38,10 +46,13 @@ func addRemoteWalkthrough(in io.Reader, name, port, sshPort, currBranch string,
}
address := response

fmt.Println("Enter webhook secret:")
fmt.Println("Enter webhook secret (leave blank to generate one):")
n, err = fmt.Fscanln(in, &response)
if err != nil || n == 0 {
return errInvalidSecret
response, err = common.GenerateRandomString()
if err != nil {
return err
}
}
secret := response

Expand Down
6 changes: 0 additions & 6 deletions remote.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,6 @@ import (
"github.com/ubclaunchpad/inertia/common"
)

var (
errInvalidUser = errors.New("invalid user")
errInvalidAddress = errors.New("invalid IP address")
errInvalidSecret = errors.New("invalid secret")
)

var remoteCmd = &cobra.Command{
Use: "remote",
Short: "Configure the local settings for a remote VPS instance",
Expand Down

0 comments on commit 74000d1

Please sign in to comment.