Skip to content

Commit

Permalink
Merge pull request #30 from revel/develop
Browse files Browse the repository at this point in the history
v0.14.0
  • Loading branch information
brendensoares authored Mar 24, 2017
2 parents 7c4f443 + 628a759 commit 209cc8b
Show file tree
Hide file tree
Showing 12 changed files with 84 additions and 42 deletions.
7 changes: 4 additions & 3 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
## INTELII = IDEA = mad brainx = polish = editor
.idea/
*.iml


# inetelli G idea.jet.brainz
*.iml
.idea/

28 changes: 25 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,29 @@
modules
=======
---
title: Modules Overview
section: modules
---

Set of officially supported modules for Revel applications
Revel Modules
==================================

## Core Modules

These modules are part of the core revel and a dependancy

- [Static](static/) = Serves static files
- [Jobs](jobs/) = The Cron Jobs runner
- [TestRunner](testrunner/) = Test sweet

## Upcoming

- [csrf](csrf/)
- [pprof](/pprof/)


## Xperimental

- [Auth](/auth/)
- [Db](/testrunner/)

### Caution
this is a work in progress
2 changes: 1 addition & 1 deletion auth/driver/secret/bcrypt.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ package secret
import (
"errors"

"golang.org/x/crypto/bcrypt"
"github.com/revel/modules/auth"
"golang.org/x/crypto/bcrypt"
)

// example implementation of a Revel auth security driver
Expand Down
12 changes: 6 additions & 6 deletions csrf/app/csrf.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ func RefreshToken(c *revel.Controller) {
//
// Usage:
// 1) Add `csrf.CsrfFilter` to the app's filters (it must come after the revel.SessionFilter).
// 2) Add CSRF fields to a form with the template tag `{{ csrftoken . }}`. The filter adds a function closure to the `RenderArgs` that can pull out the secret and make the token as-needed, caching the value in the request. Ajax support provided through the `X-CSRFToken` header.
// 2) Add CSRF fields to a form with the template tag `{{ csrftoken . }}`. The filter adds a function closure to the `ViewArgs` that can pull out the secret and make the token as-needed, caching the value in the request. Ajax support provided through the `X-CSRFToken` header.
func CsrfFilter(c *revel.Controller, fc []revel.Filter) {
token, foundToken := c.Session["csrf_token"]

Expand Down Expand Up @@ -91,9 +91,9 @@ func CsrfFilter(c *revel.Controller, fc []revel.Filter) {

fc[0](c, fc[1:])

// Only add token to RenderArgs if the request is: not AJAX, not missing referer header, and is same origin.
// Only add token to ViewArgs if the request is: not AJAX, not missing referer header, and is same origin.
if c.Request.Header.Get("X-CSRFToken") == "" && isSameOrigin {
c.RenderArgs["_csrftoken"] = token
c.ViewArgs["_csrftoken"] = token
}
}

Expand All @@ -111,9 +111,9 @@ func sameOrigin(u1, u2 *url.URL) bool {
}

func init() {
revel.TemplateFuncs["csrftoken"] = func(renderArgs map[string]interface{}) template.HTML {
if tokenFunc, ok := renderArgs["_csrftoken"]; !ok {
panic("REVEL CSRF: _csrftoken missing from RenderArgs.")
revel.TemplateFuncs["csrftoken"] = func(viewArgs map[string]interface{}) template.HTML {
if tokenFunc, ok := viewArgs["_csrftoken"]; !ok {
panic("REVEL CSRF: _csrftoken missing from ViewArgs.")
} else {
return template.HTML(tokenFunc.(func() string)())
}
Expand Down
4 changes: 2 additions & 2 deletions csrf/app/csrf_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,7 @@ func TestNoTokenInArgsWhenCORs(t *testing.T) {

testFilters[0](c, testFilters)

if _, ok := c.RenderArgs["_csrftoken"]; ok {
t.Fatal("RenderArgs should not contain token when not same origin")
if _, ok := c.ViewArgs["_csrftoken"]; ok {
t.Fatal("ViewArgs should not contain token when not same origin")
}
}
14 changes: 11 additions & 3 deletions db/app/db.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
// This module configures a database connection for the application.
// Copyright (c) 2012-2016 The Revel Framework Authors, All rights reserved.
// Revel Framework source code and usage is governed by a MIT style
// license that can be found in the LICENSE file.

// Package db module configures a database connection for the application.
//
// Developers use this module by importing and calling db.Init().
// A "Transactional" controller type is provided as a way to import interceptors
Expand All @@ -11,23 +15,26 @@ package db

import (
"database/sql"

"github.com/revel/revel"
)

// Database connection variables
var (
Db *sql.DB
Driver string
Spec string
)

// Init method used to initialize DB module on `OnAppStart`
func Init() {
// Read configuration.
var found bool
if Driver, found = revel.Config.String("db.driver"); !found {
revel.ERROR.Fatal("No db.driver found.")
revel.ERROR.Fatal("db.driver not configured")
}
if Spec, found = revel.Config.String("db.spec"); !found {
revel.ERROR.Fatal("No db.spec found.")
revel.ERROR.Fatal("db.spec not configured")
}

// Open a connection.
Expand All @@ -38,6 +45,7 @@ func Init() {
}
}

// Transactional definition for database transaction
type Transactional struct {
*revel.Controller
Txn *sql.Tx
Expand Down
4 changes: 3 additions & 1 deletion jobs/app/controllers/status.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,9 @@ func (c Jobs) Status() revel.Result {
remoteAddress = proxiedAddress[0]
}
}
if !strings.HasPrefix(remoteAddress, "127.0.0.1") && !strings.HasPrefix(remoteAddress, "::1") {
if !strings.HasPrefix(remoteAddress, "127.0.0.1") &&
!strings.HasPrefix(remoteAddress, "::1") &&
!strings.HasPrefix(remoteAddress, "[::1]") {
return c.Forbidden("%s is not local", remoteAddress)
}
entries := jobs.MainCron.Entries()
Expand Down
4 changes: 2 additions & 2 deletions jobs/app/jobs/job.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,12 @@ type Job struct {
running sync.Mutex
}

const UNNAMED = "(unnamed)"
const UnNamed = "(unnamed)"

func New(job cron.Job) *Job {
name := reflect.TypeOf(job).Name()
if name == "Func" {
name = UNNAMED
name = UnNamed
}
return &Job{
Name: name,
Expand Down
4 changes: 2 additions & 2 deletions jobs/app/jobs/plugin.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import (
"github.com/revel/revel"
)

const DEFAULT_JOB_POOL_SIZE = 10
const DefaultJobPoolSize = 10

var (
// Singleton instance of the underlying job scheduler.
Expand All @@ -23,7 +23,7 @@ var (
func init() {
MainCron = cron.New()
revel.OnAppStart(func() {
if size := revel.Config.IntDefault("jobs.pool", DEFAULT_JOB_POOL_SIZE); size > 0 {
if size := revel.Config.IntDefault("jobs.pool", DefaultJobPoolSize); size > 0 {
workPermits = make(chan struct{}, size)
}
selfConcurrent = revel.Config.BoolDefault("jobs.selfconcurrent", false)
Expand Down
13 changes: 9 additions & 4 deletions static/app/controllers/static.go
Original file line number Diff line number Diff line change
@@ -1,18 +1,24 @@
// Copyright (c) 2012-2016 The Revel Framework Authors, All rights reserved.
// Revel Framework source code and usage is governed by a MIT style
// license that can be found in the LICENSE file.

package controllers

import (
"github.com/revel/revel"
"os"
fpath "path/filepath"
"strings"
"syscall"

"github.com/revel/revel"
)

// Static file serving controller
type Static struct {
*revel.Controller
}

// This method handles requests for files. The supplied prefix may be absolute
// Serve method handles requests for files. The supplied prefix may be absolute
// or relative. If the prefix is relative it is assumed to be relative to the
// application directory. The filepath may either be just a file or an
// additional filepath to search for the given file. This response may return
Expand Down Expand Up @@ -52,7 +58,7 @@ func (c Static) Serve(prefix, filepath string) revel.Result {
return serve(c, prefix, filepath)
}

// This method allows modules to serve binary files. The parameters are the same
// ServeModule method allows modules to serve binary files. The parameters are the same
// as Static.Serve with the additional module name pre-pended to the list of
// arguments.
func (c Static) ServeModule(moduleName, prefix, filepath string) revel.Result {
Expand All @@ -74,7 +80,6 @@ func (c Static) ServeModule(moduleName, prefix, filepath string) revel.Result {
return serve(c, absPath, filepath)
}


// This method allows static serving of application files in a verified manner.
func serve(c Static, prefix, filepath string) revel.Result {
var basePath string
Expand Down
32 changes: 18 additions & 14 deletions testrunner/app/controllers/testrunner.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
// Copyright (c) 2012-2016 The Revel Framework Authors, All rights reserved.
// Revel Framework source code and usage is governed by a MIT style
// license that can be found in the LICENSE file.

package controllers

import (
Expand Down Expand Up @@ -68,7 +72,7 @@ var (

// Index is an action which renders the full list of available test suites and their tests.
func (c TestRunner) Index() revel.Result {
c.RenderArgs["suiteFound"] = len(testSuites) > 0
c.ViewArgs["suiteFound"] = len(testSuites) > 0
return c.Render(testSuites)
}

Expand All @@ -81,9 +85,9 @@ func (c TestRunner) Suite(suite string) revel.Result {
}
}

c.RenderArgs["testSuites"] = foundTestSuites
c.RenderArgs["suiteFound"] = len(foundTestSuites) > 0
c.RenderArgs["suiteName"] = suite
c.ViewArgs["testSuites"] = foundTestSuites
c.ViewArgs["suiteFound"] = len(foundTestSuites) > 0
c.ViewArgs["suiteName"] = suite

return c.RenderTemplate("TestRunner/Index.html")
}
Expand Down Expand Up @@ -118,7 +122,7 @@ func (c TestRunner) Run(suite, test string) revel.Result {
// Render the error and save to the result structure.
var buffer bytes.Buffer
tmpl, _ := revel.MainTemplateLoader.Template("TestRunner/FailureDetail.html")
tmpl.Render(&buffer, map[string]interface{}{
_ = tmpl.Render(&buffer, map[string]interface{}{
"error": panicErr,
"response": res,
"postfix": suite + "_" + test,
Expand Down Expand Up @@ -149,13 +153,13 @@ func (c TestRunner) Run(suite, test string) revel.Result {
result.Passed = true
}()

return c.RenderJson(result)
return c.RenderJSON(result)
}

// List returns a JSON list of test suites and tests.
// It is used by revel test command line tool.
func (c TestRunner) List() revel.Result {
return c.RenderJson(testSuites)
return c.RenderJSON(testSuites)
}

/*
Expand Down Expand Up @@ -209,21 +213,21 @@ func describeSuite(testSuite interface{}) TestSuiteDesc {

// errorSummary gets an error and returns its summary in human readable format.
func errorSummary(err *revel.Error) (message string) {
expected_prefix := "(expected)"
actual_prefix := "(actual)"
expectedPrefix := "(expected)"
actualPrefix := "(actual)"
errDesc := err.Description
//strip the actual/expected stuff to provide more condensed display.
if strings.Index(errDesc, expected_prefix) == 0 {
errDesc = errDesc[len(expected_prefix):len(errDesc)]
if strings.Index(errDesc, expectedPrefix) == 0 {
errDesc = errDesc[len(expectedPrefix):]
}
if strings.LastIndex(errDesc, actual_prefix) > 0 {
errDesc = errDesc[0 : len(errDesc)-len(actual_prefix)]
if strings.LastIndex(errDesc, actualPrefix) > 0 {
errDesc = errDesc[0 : len(errDesc)-len(actualPrefix)]
}

errFile := err.Path
slashIdx := strings.LastIndex(errFile, "/")
if slashIdx > 0 {
errFile = errFile[slashIdx+1 : len(errFile)]
errFile = errFile[slashIdx+1:]
}

message = fmt.Sprintf("%s %s#%d", errDesc, errFile, err.Line)
Expand Down
2 changes: 1 addition & 1 deletion testrunner/app/views/TestRunner/Index.html
Original file line number Diff line number Diff line change
Expand Up @@ -200,7 +200,7 @@ <h1 class="pull-left">
if (result.Passed) {
passCount++;
} else {
console.log("fail: result.Name");
console.log("fail:", result.Name);
failCount++;
var resultLnk = $("a", resultCell);
$(resultLnk).text(result.ErrorSummary);
Expand Down

0 comments on commit 209cc8b

Please sign in to comment.