Skip to content

Commit

Permalink
Don't outptu Gorm's cols(ID, date) in JSON
Browse files Browse the repository at this point in the history
  • Loading branch information
kotakanbe committed May 29, 2016
1 parent ae39949 commit 0f0ef97
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 57 deletions.
72 changes: 17 additions & 55 deletions models/models.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import (
"time"

"github.com/jinzhu/gorm"
log "github.com/kotakanbe/go-cve-dictionary/log"
)

// CveDetails is for sorting
Expand All @@ -25,8 +24,8 @@ func (c CveDetails) Less(i, j int) bool {

// CveDetail is a parent of Jnv/Nvd model
type CveDetail struct {
gorm.Model
CveInfoID uint // Foreign key
gorm.Model `json:"-"`
CveInfoID uint `json:"-"`

CveID string
Nvd Nvd
Expand All @@ -37,55 +36,21 @@ type CveDetail struct {
func (c CveDetail) CvssScore(lang string) float64 {
switch lang {
case "en":
if c.Nvd.GetID() != 0 && c.Nvd.CvssScore() != 0 {
log.Debugf("%s, Score :%f, Nvd.ID: %d, Lang: %s",
c.CveID,
c.Nvd.CvssScore(),
c.Nvd.ID,
lang)
if 0 < c.Nvd.CvssScore() {
return c.Nvd.CvssScore()
} else if c.Jvn.GetID() != 0 && c.Jvn.CvssScore() != 0 {
log.Debugf("%s, Score :%f, Jvn.ID: %d, Lang: %s",
c.CveID,
c.Jvn.CvssScore(),
c.Jvn.ID,
lang)
} else if 0 < c.Jvn.CvssScore() {
return c.Jvn.CvssScore()
} else {
log.Debugf("Cvss Score is unknown. CveID: %v",
c.Jvn.JvnID,
c.Jvn.Link(),
c.CveID,
)
}
return -1
case "ja":
if c.Jvn.GetID() != 0 && c.Jvn.CvssScore() != 0 {
log.Debugf("%s, Score :%f, Jvn.ID: %d, Lang: %s",
c.CveID,
c.Jvn.CvssScore(),
c.Jvn.GetID(),
lang)
if 0 < c.Jvn.CvssScore() {
return c.Jvn.CvssScore()
} else if c.Nvd.GetID() != 0 && c.Nvd.CvssScore() != 0 {
log.Debugf("%s, Score :%f, Nvd.ID: %d, Lang: %s",
c.CveID,
c.Nvd.CvssScore(),
c.Nvd.ID,
lang)
} else if 0 < c.Nvd.CvssScore() {
return c.Nvd.CvssScore()
} else {
log.Debugf("Cvss Score is unknown. CveID: %v",
c.Jvn.JvnID,
c.Jvn.Link(),
c.CveID,
)
}
return -1
default:
log.Errorf("Not implement yet. lang: %s", lang)
return c.CvssScore("en")
// reutrn -1
}
}

Expand Down Expand Up @@ -125,8 +90,8 @@ type CveDictionary interface {

// Nvd is a model of NVD
type Nvd struct {
gorm.Model
CveDetailID uint
gorm.Model `json:"-"`
CveDetailID uint `json:"-"`

Summary string

Expand Down Expand Up @@ -212,15 +177,13 @@ func firstChar(str string) string {
return string(str[0])
}

// Link return summary
// Link return empty string
func (c Nvd) Link() string {
//TODO return NVD Link
return ""
}

// VulnSiteReferences return References
func (c Nvd) VulnSiteReferences() []Reference {
//TODO return NVD Link
return c.References
}

Expand All @@ -241,8 +204,8 @@ func (c Nvd) LastModified() time.Time {

// Jvn is a model of JVN
type Jvn struct {
gorm.Model
CveDetailID uint
gorm.Model `json:"-"`
CveDetailID uint `json:"-"`

Title string
Summary string
Expand Down Expand Up @@ -308,7 +271,6 @@ func (c Jvn) CvssSeverity() string {

// VulnSiteReferences return summary
func (c Jvn) VulnSiteReferences() []Reference {
//TODO return NVD Link
return c.References
}

Expand All @@ -330,9 +292,9 @@ func (c Jvn) LastModified() time.Time {
// Cpe is Child model of Jvn/Nvd.
// see https://www.ipa.go.jp/security/vuln/CPE.html
type Cpe struct {
gorm.Model
JvnID uint
NvdID uint
gorm.Model `json:"-"`
JvnID uint `json:"-"`
NvdID uint `json:"-"`

// CPE Name (URL sytle)
// JVN ... cpe:/a:oracle:mysql
Expand All @@ -352,9 +314,9 @@ type Cpe struct {
// Reference is Child model of Jvn/Nvd.
// It holds reference information about the CVE.
type Reference struct {
gorm.Model
JvnID uint
NvdID uint
gorm.Model `json:"-"`
JvnID uint `json:"-"`
NvdID uint `json:"-"`

Source string
Link string
Expand Down
2 changes: 1 addition & 1 deletion nvd/nvd.go
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,7 @@ func fetchFeedFile(url string, httpProxy string) (nvd Nvd, err error) {

resp, body, errs = gorequest.New().Proxy(httpProxy).Get(url).End()
// defer resp.Body.Close()
if len(errs) > 0 || resp.StatusCode != 200 {
if len(errs) > 0 || resp == nil || resp.StatusCode != 200 {
return nvd, fmt.Errorf(
"HTTP error. errs: %v, url: %s", errs, url)
}
Expand Down
2 changes: 1 addition & 1 deletion version/version.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,4 @@ package version
const Name string = "go-cve-dictionary"

// Version ... Version
const Version string = "0.1.0"
const Version string = "0.1.1"

0 comments on commit 0f0ef97

Please sign in to comment.