Skip to content

Commit 7c23937

Browse files
cristianciuteafryckbos
authored andcommitted
Add docker files and event data list comand (#13)
* added docker files * added list eventdata command
1 parent 0665732 commit 7c23937

File tree

5 files changed

+83
-10
lines changed

5 files changed

+83
-10
lines changed

docker/Dockerfile

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
FROM alpine:3.4
2+
3+
ARG VERSION
4+
ADD https://github.com/CoScale/coscale-cli/releases/download/${VERSION}/coscale-cli /tmp/coscale-cli
5+
6+
RUN apk add --no-cache ca-certificates && \
7+
apk update && \
8+
apk add --upgrade libssl1.0 && \
9+
mkdir -p /opt/coscale/cli/ && \
10+
mv /tmp/coscale-cli /opt/coscale/cli/ && \
11+
chmod +x /opt/coscale/cli/coscale-cli
12+
13+
ENTRYPOINT ["/opt/coscale/cli/coscale-cli"]

docker/build.sh

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
#!/bin/bash -e
2+
3+
source conf.sh
4+
docker build -t coscale/cli --build-arg VERSION=${VERSION} .

docker/conf.sh

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
#!/bin/bash
2+
3+
export VERSION=$(curl -s -X GET https://api.github.com/repos/CoScale/coscale-cli/releases/latest | grep -Po '(?<="tag_name": ")[^"]+(?=")')

src/coscale/api/event.go

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,15 @@ func (api *Api) DeleteEvent(event *Event) error {
8080
return nil
8181
}
8282

83+
// ListEventData will return a list of eventdata for the event Id
84+
func (api *Api) ListEventData(eventId, since, before int64) (string, error) {
85+
var result string
86+
if err := api.makeCall("GET", fmt.Sprintf("/api/v1/app/%s/events/%d/data/?start=%d&stop=%d", api.AppID, eventId, since, before), nil, true, &result); err != nil {
87+
return "", err
88+
}
89+
return result, nil
90+
}
91+
8392
// GetEventData will return the eventdata by the event Id and eventdata Id.
8493
func (api *Api) GetEventData(eventId, eventdataId int64, eventData *EventData) error {
8594
if err := api.makeCall("GET", fmt.Sprintf("/api/v1/app/%s/events/%d/data/get/%d/", api.AppID, eventId, eventdataId), nil, false, &eventData); err != nil {

src/coscale/command/event.go

Lines changed: 54 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ Create new event category.
2424
The flags for new event action are:
2525
2626
Mandatory:
27-
--name
27+
--name
2828
specify name of the event.
2929
Optional:
3030
--description
@@ -59,7 +59,7 @@ The flags for update event action are:
5959
The name or id should be specified
6060
--id
6161
Unique identifier, if we want to update the name of the event, this become mandatory
62-
--name
62+
--name
6363
specify the event name of the event.
6464
--description
6565
specify the description of the event.
@@ -109,6 +109,50 @@ The name or id should be specified
109109
cmd.PrintResult(cmd.Capi.UpdateEvent(eventObj))
110110
},
111111
},
112+
{
113+
Name: "listdata",
114+
UsageLine: "event listdata (--name | --id) [--since --before]",
115+
Long: `
116+
List the data objects for a CoScale event.
117+
118+
The flags for listdata event action are:
119+
The name or id should be specified
120+
--id
121+
unique identifier of the event
122+
--name
123+
the event name of the event.
124+
--since
125+
list event data newer then the since UNIX timestamp.
126+
--before
127+
list event data older then the before UNIX timestamp.
128+
`,
129+
Run: func(cmd *Command, args []string) {
130+
var name string
131+
var id, since, before int64
132+
cmd.Flag.Usage = func() { cmd.PrintUsage() }
133+
cmd.Flag.StringVar(&name, "name", DEFAULT_STRING_FLAG_VALUE, "The name of the event.")
134+
cmd.Flag.Int64Var(&id, "id", -1, "Unique identifier of the event")
135+
cmd.Flag.Int64Var(&since, "since", -1, "list event data newer then the since UNIX timestamp.")
136+
cmd.Flag.Int64Var(&before, "before", -1, "list event data older then the before UNIX timestamp.")
137+
cmd.ParseArgs(args)
138+
139+
var eventObj = &api.Event{}
140+
var err error
141+
if id != -1 {
142+
err = cmd.Capi.GetObjectRef("event", id, eventObj)
143+
} else if name != DEFAULT_STRING_FLAG_VALUE {
144+
err = cmd.Capi.GetObejctRefByName("event", name, eventObj)
145+
} else {
146+
cmd.PrintUsage()
147+
os.Exit(EXIT_FLAG_ERROR)
148+
}
149+
if err != nil {
150+
cmd.PrintResult("", err)
151+
}
152+
153+
cmd.PrintResult(cmd.Capi.ListEventData(eventObj.ID, since, before))
154+
},
155+
},
112156
{
113157
Name: "data",
114158
UsageLine: "event data (--name --id --message --subject) [--attribute --timestamp --stopTime]",
@@ -161,18 +205,18 @@ Insert event data.
161205
162206
The flags for newdata event action are:
163207
Mandatory:
164-
--name
208+
--name
165209
specify the event name.
166210
--id
167211
specify the event id.
168212
Only one from id/name is necessary.
169-
213+
170214
--message
171-
The message for the event data.
215+
The message for the event data.
172216
--subject
173217
The subject for the event data. The subject is structured as follows:
174218
s<serverId> for a server, g<servergroupId> for a server group, a for the application.
175-
Optional:
219+
Optional:
176220
--attribute
177221
JSON String detailing the progress of the event.
178222
--timestamp
@@ -224,17 +268,17 @@ Update event data.
224268
225269
The flags for updatedata event action are:
226270
Mandatory:
227-
--name
271+
--name
228272
specify the event name.
229273
--id
230274
specify the event id.
231275
Only one from id/name is necessary.
232-
276+
233277
--dataid
234278
specify the unique id of the event data.
235279
Optional:
236280
--message
237-
The message for the event data.
281+
The message for the event data.
238282
--subject
239283
The subject for the event data. The subject is structured as follows:
240284
s<serverId> for a server, g<servergroupId> for a server group, a for the application.
@@ -310,7 +354,7 @@ Delete a eventdata entry.
310354
311355
The flags for event deletedata action are:
312356
Mandatory:
313-
--id
357+
--id
314358
specify the event id.
315359
--dataid
316360
specify the unique id of the event data.

0 commit comments

Comments
 (0)