Skip to content

Commit 43aba60

Browse files
committed
lint: add docs, lint
1 parent f4e547d commit 43aba60

File tree

6 files changed

+94
-35
lines changed

6 files changed

+94
-35
lines changed

README.md

Lines changed: 21 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
# sysdig-go #
22

33
[![sysdig-go release](https://img.shields.io/github/v/release/trinchan/sysdig-go?sort=semver)](https://github.com/trinchan/sysdig-go/releases)
4-
[![GoDoc](https://img.shields.io/static/v1?label=godoc&message=reference&color=blue)](https://pkg.go.dev/github.com/trinchan/sysdig-go/github)
4+
[![GoDoc](https://img.shields.io/static/v1?label=godoc&message=reference&color=blue)](https://pkg.go.dev/github.com/trinchan/sysdig-go/sysdig)
55
[![Test Status](https://github.com/trinchan/sysdig-go/workflows/tests/badge.svg)](https://github.com/trinchan/sysdig-go/actions?query=workflow%3Atests)
66
[![Test Coverage](https://codecov.io/gh/trinchan/sysdig-go/branch/main/graph/badge.svg)](https://codecov.io/gh/trinchan/sysdig-go)
77

@@ -20,19 +20,19 @@ will resolve and add the package to the current development module, along with i
2020
Alternatively the same can be achieved if you use import in a package:
2121

2222
```go
23-
import "github.com/trinchan/sysdig-go/github"
23+
import "github.com/trinchan/sysdig-go/sysdig"
2424
```
2525

2626
and run `go get` without parameters.
2727

2828
## Implemented APIs ##
2929
| Base | Get | List | Create | Delete | Update | Other | Service | Description |
3030
|:-----------------------:|:---:|:----:|:------:|:------:|:------:|:-----------------------:|:-----------------------------:|-------------|
31-
| `/team` |||x ||x |ListUsers, Infrastructure| `client.Teams` |Information about teams, users, and usage |
32-
| `/user/me` ||x |x |x |x |x | `client.Users` |Information about the current user |
33-
| `/token` ||x |x |x |x |x | `client.Users` |Retrieves the current user's access token |
34-
| `/agents/connected` |✓ |x |x |x |x |x | `client.Users` |Rerieves the connected Agents for a user
35-
| `/alerts` ||||x |x |x | `client.Alerts` |Manage alert configurations |
31+
| `/team` |||x ||x |ListUsers, Infrastructure| `client.Teams` |[Information about teams, users, and usage](https://docs.sysdig.com/en/docs/administration/administration-settings/user-and-team-administration/manage-teams-and-roles/) |
32+
| `/user/me` ||x |x |x |x |x | `client.Users` |[Information about the current user](https://docs.sysdig.com/en/docs/administration/administration-settings/find-your-customer-id-and-name/) |
33+
| `/token` ||x |x |x |x |x | `client.Users` |[Retrieves the current user's access token](https://docs.sysdig.com/en/docs/administration/administration-settings/find-your-customer-id-and-name/) |
34+
| `/agents/connected` |✓ |x |x |x |x |x | `client.Users` |[Rerieves the connected Agents](https://docs.sysdig.com/en/docs/sysdig-monitor/)
35+
| `/alerts` ||||x |x |x | `client.Alerts` |[Manage alert configurations](https://docs.sysdig.com/en/docs/sysdig-monitor/alerts/manage-alerts/) |
3636
| `/v3/dashboards` ||||||Favorite, Transfer | `client.Dashboards` |Manage dashboard configurations |
3737
| `/v2/events` |||||x |x | `client.Events` |Manage event notifications |
3838
| `/notificationChannels` |||||x |x | `client.NotificationChannels` |Manage notification channels |
@@ -214,13 +214,7 @@ The Sysdig API (and this client) supports [gzip](https://docs.sysdig.com/en/docs
214214
sysdig.NewClient(sysdig.WithResponseCompression(true))
215215
```
216216

217-
For other options, check the [documentation](https://pkg.go.dev/github.com/trinchan/sysdig-go/github).
218-
219-
## Versioning ##
220-
221-
`sysdig-go` is currently undergoing its initial development and is still incomplete. As new APIs are documented by Sysdig and IBM Cloud, new
222-
APIs will be added or changed. Since `sysdig-go` is a client library, breaking changes in the upstream API may require updates to the client.
223-
`sysdig-go` will follow semver as closely as possible to minimize breaking changes.
217+
For other options, check the [documentation](https://pkg.go.dev/github.com/trinchan/sysdig-go/sysdig).
224218

225219
## FAQ ##
226220

@@ -233,10 +227,20 @@ you can also use the `client.Do()` method to send a custom request.
233227

234228
That's not a question! The client is incomplete as documentation for most of the Sysdig API has not been published. I have had to leave some types as `interface{}` until documentation is released or I receive a sample response. Submit an issue and include the (redacted) client logs with `Debug` mode enabled.
235229

230+
### "The documentation is wrong!" ###
231+
232+
Since there is no official documentation for most of the API, some documentation is bound to be incorrect. Corrections and improvements
233+
are very welcome -- please file an issue or submit a patch if you find something is inaccurate.
234+
236235
### "Is this an official client?" ###
237236

238237
Nope. The only official client I know is the [Python SDK](https://github.com/sysdiglabs/sysdig-sdk-python).
239238

239+
## Versioning ##
240+
241+
`sysdig-go` is currently undergoing its initial development and is still incomplete. As new APIs are documented by Sysdig and IBM Cloud, new
242+
APIs will be added or changed. Since `sysdig-go` is a client library, breaking changes in the upstream API may require updates to the client.
243+
`sysdig-go` will follow semver as closely as possible to minimize breaking changes.
240244

241245
## Credits ##
242246
- Sysdig's [Python SDK](https://github.com/sysdiglabs/sysdig-sdk-python) for API reference.
@@ -246,3 +250,6 @@ Nope. The only official client I know is the [Python SDK](https://github.com/sys
246250

247251
This library is distributed under the MIT license found in the [LICENSE](./LICENSE)
248252
file.
253+
254+
---
255+
_"Sysdig" and "IBM Cloud" are registered trademarks of their respective holders. Use of the name does not imply any affiliation with or endorsement by them._

sysdig/alerts.go

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,13 +9,17 @@ import (
99
// AlertService is the Service for communicating with the Sysdig Monitor Alert related API.
1010
type AlertService service
1111

12+
// AlertType defines the types of Alerts.
1213
type AlertType string
1314

1415
const (
1516
// AlertTypeEvent means the Alert is from an Event.
1617
AlertTypeEvent AlertType = "EVENT"
18+
// TODO: There must be others.
1719
)
1820

21+
// Alert defines a Sysdig Alert.
22+
// See: https://docs.sysdig.com/en/docs/sysdig-monitor/alerts/manage-alerts/
1923
type Alert struct {
2024
ID int `json:"id,omitempty"`
2125
Version int `json:"version,omitempty"`
@@ -44,20 +48,23 @@ type Alert struct {
4448
CustomerID int `json:"customerId"`
4549
}
4650

51+
// AlertCustomNotification is the structure for a Custom Notification on an Alert.
4752
type AlertCustomNotification struct {
4853
TitleTemplate string `json:"titleTemplate"`
4954
UseNewTemplate bool `json:"useNewTemplate"`
5055
}
5156

57+
// AlertCriteria defines the Criteria for an Alert.
58+
// TODO: What are the format of the unknown fields?
5259
type AlertCriteria struct {
53-
Text string `json:"text"`
54-
// TODO what are the format of these?
60+
Text string `json:"text"`
5561
Source interface{} `json:"source"`
5662
Severity interface{} `json:"severity"`
5763
Query interface{} `json:"query"`
5864
Scope interface{} `json:"scope"`
5965
}
6066

67+
// AlertResponse is a container for an Alert returned by the Sysdig API.
6168
type AlertResponse struct {
6269
Alert Alert `json:"alert"`
6370
}

sysdig/dashboards.go

Lines changed: 33 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@ import (
99
// DashboardService is the Service for communicating with the Sysdig Monitor Dashboard related API.
1010
type DashboardService service
1111

12+
// Dashboard is the structure for a Sysdig Dashboard.
13+
// See: https://docs.sysdig.com/en/docs/sysdig-monitor/dashboards/
1214
type Dashboard struct {
1315
ID int `json:"id,omitempty"`
1416
TeamID int `json:"teamId"`
@@ -33,17 +35,19 @@ type Dashboard struct {
3335
ScopeExpressionList []ScopeExpression `json:"scopeExpressionList,omitempty"`
3436
}
3537

36-
type DashboardResponse struct {
37-
Dashboard Dashboard `json:"dashboard"`
38-
}
39-
38+
// NewDashboard constructs an empty Dashboard with the given name.
4039
func NewDashboard(name string) *Dashboard {
4140
return &Dashboard{
4241
Name: name,
4342
Schema: 3,
4443
}
4544
}
4645

46+
// DashboardResponse is a container for a Dashboard returned by the DashboardService API.
47+
type DashboardResponse struct {
48+
Dashboard Dashboard `json:"dashboard"`
49+
}
50+
4751
// Get retrieves a Dashboard.
4852
func (s *DashboardService) Get(ctx context.Context, dashboardID int) (*DashboardResponse, *http.Response, error) {
4953
u := fmt.Sprintf("api/v3/dashboards/%d", dashboardID)
@@ -56,6 +60,7 @@ func (s *DashboardService) Get(ctx context.Context, dashboardID int) (*Dashboard
5660
return c, resp, err
5761
}
5862

63+
// ListDashboardsResponse is a container for Dashboards returned by the DashboardService.List API.
5964
type ListDashboardsResponse struct {
6065
Dashboards []Dashboard `json:"dashboards"`
6166
}
@@ -72,6 +77,7 @@ func (s *DashboardService) List(ctx context.Context) (*ListDashboardsResponse, *
7277
return c, resp, err
7378
}
7479

80+
// Create creates a new Dashboard.
7581
func (s *DashboardService) Create(ctx context.Context, dashboard Dashboard) (*DashboardResponse, *http.Response, error) {
7682
type dashboardRequest struct {
7783
Dashboard Dashboard `json:"dashboard"`
@@ -135,10 +141,12 @@ func (s *DashboardService) Favorite(ctx context.Context, id int, favorite bool)
135141
return c, resp, err
136142
}
137143

144+
// DashboardTransferResponse is a container for a DashboardTransferResults for the DashboardService.Transfer API.
138145
type DashboardTransferResponse struct {
139146
Results DashboardTransferResults `json:"results"`
140147
}
141148

149+
// DashboardTransferResults is the response structure for the DashboardService.Transfer API.
142150
type DashboardTransferResults struct {
143151
ID int `json:"id"`
144152
Name string `json:"name"`
@@ -182,18 +190,21 @@ func (s *DashboardService) Transfer(
182190
return c, resp, err
183191
}
184192

193+
// SharingSetting defines a sharing setting for a Dashboard.
185194
type SharingSetting struct {
186195
Role string `json:"role"`
187196
Member SharingMember `json:"member"`
188197
}
189198

199+
// SharingMember defines a sharing member for a Dashboard.
190200
type SharingMember struct {
191201
Type string `json:"type"`
192202
ID int `json:"id"`
193203
Name string `json:"name"`
194204
TeamTheme string `json:"teamTheme"`
195205
}
196206

207+
// ScopeExpression is a scope expression used in a Dashboard.
197208
type ScopeExpression struct {
198209
Operand string `json:"operand"`
199210
Operator string `json:"operator"`
@@ -204,6 +215,7 @@ type ScopeExpression struct {
204215
IsVariable bool `json:"isVariable"`
205216
}
206217

218+
// Layout defines the Layout of Panels a Dashboard.
207219
type Layout struct {
208220
PanelID int `json:"panelId"`
209221
X int `json:"x"`
@@ -212,6 +224,7 @@ type Layout struct {
212224
H int `json:"h"`
213225
}
214226

227+
// Panel is the structure of a Panel in a Dashboard.
215228
type Panel struct {
216229
ID int `json:"id"`
217230
Type string `json:"type"`
@@ -230,6 +243,7 @@ type Panel struct {
230243
TextAutosized bool `json:"textAutosized,omitempty"`
231244
}
232245

246+
// BasicQuery is a basic query type used in a Dashboard.
233247
type BasicQuery struct {
234248
Enabled bool `json:"enabled"`
235249
DisplayInfo BasicQueryDisplayInfo `json:"displayInfo"`
@@ -240,17 +254,20 @@ type BasicQuery struct {
240254
Segmentation BasicQuerySegmentation `json:"segmentation,omitempty"`
241255
}
242256

257+
// BasicQueryCompareTo is used in a BasicQuery on a Dashboard.
243258
type BasicQueryCompareTo struct {
244259
Enabled bool `json:"enabled"`
245260
Delta int `json:"delta"`
246261
TimeFormat string `json:"timeFormat"`
247262
}
248263

264+
// BasicQueryScope is a scope used in a BasicQuery on a Dashboard.
249265
type BasicQueryScope struct {
250266
Expressions []string `json:"expressions"`
251267
ExtendsDashboardScope bool `json:"extendsDashboardScope"`
252268
}
253269

270+
// BasicQueryMetric is a metric used in a BasicQuery on a Dashboard.
254271
type BasicQueryMetric struct {
255272
ID string `json:"id"`
256273
TimeAggregation string `json:"timeAggregation"`
@@ -259,12 +276,14 @@ type BasicQueryMetric struct {
259276
Sorting interface{} `json:"sorting"`
260277
}
261278

279+
// BasicQueryDisplayInfo is the display info used in a BasicQuery on a Dashboard.
262280
type BasicQueryDisplayInfo struct {
263281
DisplayName string `json:"displayName"`
264282
TimeSeriesDisplayNameTemplate string `json:"timeSeriesDisplayNameTemplate"`
265283
Type string `json:"type"`
266284
}
267285

286+
// BasicQueryFormat is the metric format used in a BasicQuery on a Dashboard.
268287
type BasicQueryFormat struct {
269288
Unit string `json:"unit"`
270289
InputFormat string `json:"inputFormat"`
@@ -274,37 +293,43 @@ type BasicQueryFormat struct {
274293
NullValueDisplayMode string `json:"nullValueDisplayMode"`
275294
}
276295

296+
// BasicQuerySegmentation is the segmentation used in a BasicQuery on a Dashboard.
277297
type BasicQuerySegmentation struct {
278298
Labels []BasicQuerySegmentationLabel `json:"labels"`
279299
Limit int `json:"limit"`
280300
Direction string `json:"direction"`
281301
}
282302

303+
// BasicQuerySegmentationLabel is a segmentation label used in a BasicQuerySegmentation of a BasicQuery on a Dashboard.
283304
type BasicQuerySegmentationLabel struct {
284305
ID string `json:"id"`
285306
Descriptor *string `json:"descriptor,omitempty"`
286307
DisplayName *string `json:"displayName,omitempty"`
287308
Sorting *string `json:"sorting,omitempty"`
288309
}
289310

311+
// Thresholds are the threshold for a Panel on a Dashboard.
290312
type Thresholds struct {
291313
Values []ThresholdValue `json:"values"`
292314
Base ThresholdBase `json:"base"`
293315
UseDefaults *bool `json:"useDefaults"`
294316
}
295317

318+
// ThresholdValue is a threshold value for a Thresholds on a Panel in a Dashboard.
296319
type ThresholdValue struct {
297320
Severity string `json:"severity"`
298321
Value float64 `json:"value"`
299322
InputFormat string `json:"inputFormat"`
300323
DisplayText string `json:"displayText"`
301324
}
302325

326+
// ThresholdBase is a threshold base for a Thresholds on a Panel in a Dashboard.
303327
type ThresholdBase struct {
304328
Severity string `json:"severity"`
305329
DisplayText string `json:"displayText"`
306330
}
307331

332+
// LegendConfiguration is the configuration for a legend on a Panel in a Dashboard.
308333
type LegendConfiguration struct {
309334
Enabled bool `json:"enabled"`
310335
Position string `json:"position"`
@@ -314,6 +339,7 @@ type LegendConfiguration struct {
314339
Height *float64 `json:"height"`
315340
}
316341

342+
// AxesConfiguration is the configuration for the axes of a Panel in a Dashboard.
317343
type AxesConfiguration struct {
318344
Bottom struct {
319345
Enabled bool `json:"enabled"`
@@ -322,6 +348,7 @@ type AxesConfiguration struct {
322348
Right Axis `json:"right"`
323349
}
324350

351+
// Axis is an axis configuration used in an AxesConfiguration for the axes of a Panel in a Dashboard.
325352
type Axis struct {
326353
Enabled bool `json:"enabled"`
327354
DisplayName *string `json:"displayName"`
@@ -335,11 +362,13 @@ type Axis struct {
335362
Scale string `json:"scale"`
336363
}
337364

365+
// EventDisplaySettings are the event display settings for a Dashboard.
338366
type EventDisplaySettings struct {
339367
Enabled bool `json:"enabled"`
340368
QueryParams EventDisplaySettingsQueryParams `json:"queryParams"`
341369
}
342370

371+
// EventDisplaySettingsQueryParams are the query parameters used in an EventDisplaySettings for a Dashboard.
343372
type EventDisplaySettingsQueryParams struct {
344373
Severities []Severity `json:"severities"`
345374
AlertStatuses []Status `json:"alertStatuses"`

sysdig/sysdig_test.go

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,8 @@ const (
2525
// setup sets up a test HTTP server along with a sysdig.Client that is
2626
// configured to talk to that test server. Tests should register handlers on
2727
// mux which provide mock responses for the API method being tested.
28-
func setup(authenticator authentication.Authenticator, options ...ClientOption) (client *Client, mux *http.ServeMux, serverURL string, teardown func()) {
28+
func setup(authenticator authentication.Authenticator) (
29+
client *Client, mux *http.ServeMux, serverURL string, teardown func()) {
2930
// mux is the HTTP request multiplexer used with the test server.
3031
mux = http.NewServeMux()
3132

@@ -48,9 +49,6 @@ func setup(authenticator authentication.Authenticator, options ...ClientOption)
4849
// client is the Sysdig client being tested and is
4950
// configured to use test server.
5051
client, _ = NewClient(authenticator, WithDebug(true))
51-
for _, o := range options {
52-
_ = o(client)
53-
}
5452
url, _ := url.Parse(server.URL + baseURLPath + "/")
5553
client.BaseURL = url
5654

0 commit comments

Comments
 (0)