Skip to content

Commit b3b79de

Browse files
authored
Merge pull request #10 from techlover10/master
Implement repo sync command + fix cookie redaction
2 parents d8ce4dd + 3ab65b8 commit b3b79de

3 files changed

Lines changed: 33 additions & 2 deletions

File tree

src/github.com/verizon/nelson/log_filter.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ import (
2222
"regexp"
2323
)
2424

25-
var sanitizer = regexp.MustCompile("nelson.session=(.*)")
25+
var sanitizer = regexp.MustCompile("\"Cookie: nelson.session=(.*)\"")
2626

2727
type FilteredLog struct {
2828
logger gorequest.Logger
@@ -38,7 +38,7 @@ func (f FilteredLog) SetPrefix(s string) {
3838

3939
func (f FilteredLog) Printf(format string, v ...interface{}) {
4040
s := fmt.Sprintf(format, v)
41-
f.logger.Println(sanitizer.ReplaceAllString(s, "nelson.session=<redacted>"))
41+
f.logger.Println(sanitizer.ReplaceAllString(s, "\"Cookie: nelson.session=<redacted>\""))
4242
}
4343

4444
func (f FilteredLog) Println(v ...interface{}) {

src/github.com/verizon/nelson/main.go

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -155,6 +155,22 @@ func main() {
155155
Aliases: []string{"repo"},
156156
Usage: "Commands for enabling and disabling project repositories",
157157
Subcommands: []cli.Command{
158+
{
159+
Name: "sync",
160+
Usage: "Synchronize the available repositories with GitHub",
161+
Action: func(c *cli.Context) error {
162+
pi.Start()
163+
cfg := LoadDefaultConfigOrExit(http)
164+
e := SyncRepos(http, cfg)
165+
pi.Stop()
166+
if e != nil {
167+
fmt.Println(e)
168+
return cli.NewExitError("Unable to synchronize repositories.", 1)
169+
}
170+
fmt.Println("Successfully synchronized repositories.")
171+
return nil
172+
},
173+
},
158174
{
159175
Name: "list",
160176
Usage: "List enabled/disabled statuses for project repositories",

src/github.com/verizon/nelson/repo.go

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,21 @@ type RepoSummary struct {
5050
Access string `json:"access"`
5151
}
5252

53+
func SyncRepos(http *gorequest.SuperAgent, cfg *Config) []error {
54+
uri := cfg.Endpoint + "/v1/profile/sync"
55+
r, _, errs := AugmentRequest(http.Post(uri), cfg).EndBytes()
56+
57+
if errs != nil {
58+
return errs
59+
}
60+
61+
if r.StatusCode/100 != 2 {
62+
errs = append(errs, errors.New("Unexpected response from Nelson server"))
63+
return errs
64+
}
65+
return nil
66+
}
67+
5368
func ListRepos(owner string, http *gorequest.SuperAgent, cfg *Config) (list []RepoSummary, err []error) {
5469
uri := cfg.Endpoint + "/v1/repos?owner=" + owner
5570
r, body, errs := AugmentRequest(http.Get(uri), cfg).EndBytes()

0 commit comments

Comments
 (0)