2019-05-11 14:03:26 -05:00
|
|
|
package witProtobuf
|
|
|
|
|
|
|
|
import "log"
|
2019-05-11 14:21:27 -05:00
|
|
|
|
|
|
|
//
|
|
|
|
// This generates some sample data. It *should* match the .proto file
|
|
|
|
//
|
2019-05-11 14:03:26 -05:00
|
|
|
|
|
|
|
func CreateSampleEvent() *Event {
|
|
|
|
// TODO: flush this out to do all the fields
|
|
|
|
log.Println("CreateSampleEvent() is generating a example protobuf Event")
|
|
|
|
|
|
|
|
e := &Event{
|
2019-05-11 14:21:27 -05:00
|
|
|
Id: 1234,
|
|
|
|
Email: "test+protobuf@wit.com",
|
|
|
|
Comment: "this is a sample event",
|
2019-05-12 01:02:53 -05:00
|
|
|
Type: Event_MIGRATE,
|
2019-05-11 14:21:27 -05:00
|
|
|
Results: []*Event_Response{
|
|
|
|
{Name: "fooadd", Type: Event_ADD},
|
|
|
|
{Name: "foodelete", Type: Event_DELETE},
|
2019-05-11 14:25:19 -05:00
|
|
|
{
|
|
|
|
Name: "foopoweron",
|
|
|
|
Type: Event_POWERON,
|
|
|
|
Error: "No error happened",
|
|
|
|
Id: 54321,
|
|
|
|
},
|
2019-05-11 14:03:26 -05:00
|
|
|
},
|
|
|
|
}
|
|
|
|
return e
|
|
|
|
}
|
2019-05-11 14:13:34 -05:00
|
|
|
|
|
|
|
func CreateSampleEvents(total int) []Event {
|
|
|
|
// TODO: flush this out to do all the fields
|
|
|
|
log.Println("CreateSampleEvent() is generating %d protobuf Events", total)
|
|
|
|
|
|
|
|
var all []Event
|
|
|
|
|
|
|
|
for i := 0; i < total; i++ {
|
|
|
|
e := CreateSampleEvent()
|
|
|
|
|
|
|
|
e.Id += 1000 + int32(i)
|
2019-05-23 22:12:36 -05:00
|
|
|
e.Comment = "Sample Event " + string(i)
|
2019-05-11 14:13:34 -05:00
|
|
|
|
|
|
|
all = append(all, *e)
|
|
|
|
}
|
|
|
|
|
|
|
|
return all
|
|
|
|
}
|
2019-05-12 01:02:53 -05:00
|
|
|
|
|
|
|
func DumpEventData(myevent *Event) {
|
|
|
|
log.Println("Received Event name=", myevent)
|
|
|
|
log.Println("Displaying the Event_Results:")
|
|
|
|
msgItems := myevent.GetResults()
|
|
|
|
for _, item := range msgItems {
|
|
|
|
log.Println("\t", item)
|
|
|
|
}
|
|
|
|
}
|
2019-05-23 20:33:42 -05:00
|
|
|
|
|
|
|
func MakeGetEvent() *Event {
|
|
|
|
e := &Event{
|
|
|
|
Id: 1234,
|
2019-05-23 22:12:36 -05:00
|
|
|
Comment: "List all user VMs",
|
2019-05-23 20:33:42 -05:00
|
|
|
Email: "test+protobuf@wit.com",
|
|
|
|
Type: Event_GET,
|
|
|
|
}
|
|
|
|
e.Comment ="this should return a protobuf with all the VM's"
|
|
|
|
return e
|
|
|
|
}
|
2019-05-23 22:01:24 -05:00
|
|
|
|
|
|
|
func MakeLoginEvent() *Event {
|
|
|
|
e := &Event{
|
|
|
|
Id: 1234,
|
2019-05-23 22:12:36 -05:00
|
|
|
Comment: "Login to get a Token",
|
2019-05-23 22:01:24 -05:00
|
|
|
Type: Event_LOGIN,
|
|
|
|
}
|
|
|
|
e.Comment ="this should return a protobuf with the token"
|
|
|
|
return e
|
|
|
|
}
|
2019-05-24 01:35:40 -05:00
|
|
|
|
|
|
|
func MakeOkResponse() *Event {
|
|
|
|
log.Println("CreateSampleEvent() is generating a example protobuf Event")
|
|
|
|
|
|
|
|
e := &Event{
|
|
|
|
Id: 1234,
|
|
|
|
Email: "test+protobuf@wit.com",
|
2019-05-24 01:43:58 -05:00
|
|
|
Comment: "everything is OK",
|
2019-05-24 01:35:40 -05:00
|
|
|
Type: Event_OK,
|
|
|
|
Results: []*Event_Response{
|
|
|
|
{Name: "fooadd", Type: Event_OK},
|
|
|
|
{Name: "foodelete", Type: Event_DELETE},
|
|
|
|
{
|
|
|
|
Name: "foopoweron",
|
|
|
|
Type: Event_POWERON,
|
|
|
|
Error: "No error happened",
|
|
|
|
Id: 54321,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
}
|
|
|
|
return e
|
|
|
|
}
|
2019-05-24 01:43:58 -05:00
|
|
|
|
|
|
|
func MakeFailResponse() *Event {
|
|
|
|
log.Println("CreateSampleEvent() is generating a example protobuf Event")
|
|
|
|
|
|
|
|
e := &Event{
|
|
|
|
Id: 1234,
|
|
|
|
Email: "test+protobuf@wit.com",
|
|
|
|
Comment: "something failed",
|
|
|
|
Type: Event_FAIL,
|
|
|
|
Results: []*Event_Response{
|
|
|
|
{Name: "fooadd", Type: Event_FAIL},
|
|
|
|
{Name: "foodelete", Type: Event_DELETE},
|
|
|
|
{
|
|
|
|
Name: "foopoweron",
|
|
|
|
Type: Event_POWERON,
|
|
|
|
Error: "No error happened",
|
|
|
|
Id: 54321,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
}
|
|
|
|
return e
|
|
|
|
}
|