diff --git a/README.md b/README.md index 88d99be..1d4f1c8 100644 --- a/README.md +++ b/README.md @@ -247,6 +247,78 @@ Example input JSON format: -d '{"Name":"Alice","Password":"Lewis"}' {"Status":"ok"} + +### Order + +Order creates a new order and lets other users know delegations are needed. + +Example input JSON format: + $ curl --cacert server/server.crt https://localhost:8080/order \ + -d '{"Name":"Alice","Password":"Lewis","Labels": ["Blue","Red"],\ + "Duration":"1h","Uses":5,"EncryptedData":"ABCDE=="}' + { + "Admins": [ + "Bob", + "Eve" + ], + "AdminsDelegated": null, + "Delegated": 0, + "DurationRequested": 3.6e+12, + "Labels": [ + "blue", + "red" + ], + "Name": "Alice", + "Num": "77da1cfd8962fb9685c15c84", + "TimeRequested": "2016-01-25T15:58:41.961906679-08:00" + } + +### Orders Outstanding + +Orders Outstanding will return a list of current order numbers + + $ curl --cacert server/server.crt https://localhost:8080/orderout + -d '{"Name":"Alice","Password":"Lewis"}' + { + "77da1cfd8962fb9685c15c84":{ + "Name":"Alice", + "Num":"77da1cfd8962fb9685c15c84", + "TimeRequested":"2016-01-25T15:58:41.961906679-08:00", + "DurationRequested":3600000000000, + "Delegated":0," + AdminsDelegated":null, + "Admins":["Bob, Eve"], + "Labels":["Blue","Red"] + } + } + +### Order Information + $ curl --cacert server/server.crt https://localhost:8080/orderinfo + -d '{"Name":"Alice","Password":"Lewis", \ + "OrderNum":"77da1cfd8962fb9685c15c84"}' + { + "Admins": [ + "Bob", + "Eve" + ], + "AdminsDelegated": null, + "Delegated": 0, + "DurationRequested": 3.6e+12, + "Labels": [ + "blue", + "red" + ], + "Name": "Alice", + "Num": "77da1cfd8962fb9685c15c84", + "TimeRequested": "2016-01-25T15:58:41.961906679-08:00" + } + +### Order Cancel + $ curl --cacert server/server.crt https://localhost:8080/orderinfo + -d '{"Name":"Alice","Password":"Lewis", \ + "OrderNum":"77da1cfd8962fb9685c15c84"}' + {"Status":"ok"} + ### Web interface You can build a web interface to manage the Red October service using diff --git a/core/core.go b/core/core.go index 2c719a0..c37ef56 100644 --- a/core/core.go +++ b/core/core.go @@ -58,9 +58,10 @@ type DelegateRequest struct { } type CreateUserRequest struct { - Name string - Password string - UserType string + Name string + Password string + UserType string + HipchatName string } type PasswordRequest struct { @@ -113,12 +114,12 @@ type ExportRequest struct { } type OrderRequest struct { - Name string - Password string - Duration string - Uses int - Data []byte - Labels []string + Name string + Password string + Duration string + Uses int + EncryptedData []byte + Labels []string } type OrderInfoRequest struct { @@ -454,10 +455,13 @@ func CreateUser(jsonIn []byte) ([]byte, error) { return jsonStatusError(err) } - if _, err = records.AddNewRecord(s.Name, s.Password, false, s.UserType); err != nil { + if _, err := records.AddNewRecord(s.Name, s.Password, false, s.UserType); err != nil { return jsonStatusError(err) } + if err = records.ChangePassword(s.Name, s.Password, "", s.HipchatName); err != nil { + return jsonStatusError(err) + } return jsonStatusOk() } @@ -749,7 +753,7 @@ func Order(jsonIn []byte) (out []byte, err error) { } // Get the owners of the ciphertext. - owners, _, err := crypt.GetOwners(o.Data) + owners, _, err := crypt.GetOwners(o.EncryptedData) if err != nil { jsonStatusError(err) } diff --git a/index.html b/index.html index 9b8f189..8fb8483 100644 --- a/index.html +++ b/index.html @@ -71,6 +71,8 @@ + +
Order Number: '+d.Num+'
' }) ); } }); }); @@ -711,7 +739,6 @@ evt.preventDefault(); var $form = $(evt.currentTarget), data = serialize($form); - alert(1); submit( $form, { data : data, success : function(d){ @@ -753,7 +780,7 @@ if (!d.hasOwnProperty(jj)) continue; var o = d[jj]; - ordout += o.Name + " requesting " + o.Label + " has " + o.Delegated + "\n"; + ordout += o.Name + " requesting " + JSON.stringify(o.Labels) + " has " + o.Delegated + "\n"; } $form.find('.feedback').empty().append( diff --git a/order/order.go b/order/order.go index 4360419..d052d4d 100644 --- a/order/order.go +++ b/order/order.go @@ -1,3 +1,8 @@ +// Package order manages the bookkeeping and utilies required +// for users to create an 'order' meaning they have requested +// delegations for a certian resource. +// +// Copyright (c) 2016 CloudFlare, Inc. package order import ( diff --git a/passvault/passvault.go b/passvault/passvault.go index a20dfc0..912334b 100644 --- a/passvault/passvault.go +++ b/passvault/passvault.go @@ -374,18 +374,20 @@ func (records *Records) AddNewRecord(name, password string, admin bool, userType func (records *Records) ChangePassword(name, password, newPassword, hipchatName string) (err error) { pr, ok := records.GetRecord(name) - if len(newPassword) == 0 { - if len(hipchatName) != 0 { - pr.AltNames["HipchatName"] = hipchatName - } - records.SetRecord(pr, name) - return records.WriteRecordsToDisk() - } if !ok { err = errors.New("Record not present") return } + if len(hipchatName) != 0 { + pr.AltNames["HipchatName"] = hipchatName + } + + if len(newPassword) == 0 { + records.SetRecord(pr, name) + return records.WriteRecordsToDisk() + } + var keySalt []byte if keySalt, err = symcrypt.MakeRandom(16); err != nil { return diff --git a/redoctober.go b/redoctober.go index bb14b68..b8a7574 100644 --- a/redoctober.go +++ b/redoctober.go @@ -353,6 +353,8 @@ var indexHtml = []byte(`Order Num: '+d.Num+'
' }) ); + makeAlert({ type: 'success', message: 'Order Number: '+d.Num+'
' }) ); } }); }); @@ -993,7 +1021,6 @@ var indexHtml = []byte(` evt.preventDefault(); var $form = $(evt.currentTarget), data = serialize($form); - alert(1); submit( $form, { data : data, success : function(d){ @@ -1035,7 +1062,7 @@ var indexHtml = []byte(` if (!d.hasOwnProperty(jj)) continue; var o = d[jj]; - ordout += o.Name + " requesting " + o.Label + " has " + o.Delegated + "\n"; + ordout += o.Name + " requesting " + JSON.stringify(o.Labels) + " has " + o.Delegated + "\n"; } $form.find('.feedback').empty().append(