Skip to content

Commit b147ea8

Browse files
authored
feat(audit_trail): add exports listing (#2755)
1 parent f2d2e7d commit b147ea8

File tree

1 file changed

+169
-32
lines changed

1 file changed

+169
-32
lines changed

api/audit_trail/v1alpha1/audit_trail_sdk.go

Lines changed: 169 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -348,6 +348,47 @@ func (enum *ListEventsRequestOrderBy) UnmarshalJSON(data []byte) error {
348348
return nil
349349
}
350350

351+
type ListExportJobsRequestOrderBy string
352+
353+
const (
354+
ListExportJobsRequestOrderByNameAsc = ListExportJobsRequestOrderBy("name_asc")
355+
ListExportJobsRequestOrderByNameDesc = ListExportJobsRequestOrderBy("name_desc")
356+
ListExportJobsRequestOrderByCreatedAtAsc = ListExportJobsRequestOrderBy("created_at_asc")
357+
ListExportJobsRequestOrderByCreatedAtDesc = ListExportJobsRequestOrderBy("created_at_desc")
358+
)
359+
360+
func (enum ListExportJobsRequestOrderBy) String() string {
361+
if enum == "" {
362+
// return default value if empty
363+
return string(ListExportJobsRequestOrderByNameAsc)
364+
}
365+
return string(enum)
366+
}
367+
368+
func (enum ListExportJobsRequestOrderBy) Values() []ListExportJobsRequestOrderBy {
369+
return []ListExportJobsRequestOrderBy{
370+
"name_asc",
371+
"name_desc",
372+
"created_at_asc",
373+
"created_at_desc",
374+
}
375+
}
376+
377+
func (enum ListExportJobsRequestOrderBy) MarshalJSON() ([]byte, error) {
378+
return []byte(fmt.Sprintf(`"%s"`, enum)), nil
379+
}
380+
381+
func (enum *ListExportJobsRequestOrderBy) UnmarshalJSON(data []byte) error {
382+
tmp := ""
383+
384+
if err := json.Unmarshal(data, &tmp); err != nil {
385+
return err
386+
}
387+
388+
*enum = ListExportJobsRequestOrderBy(ListExportJobsRequestOrderBy(tmp).String())
389+
return nil
390+
}
391+
351392
type ResourceType string
352393

353394
const (
@@ -850,13 +891,6 @@ type SystemEvent struct {
850891
ProductName string `json:"product_name"`
851892
}
852893

853-
// ProductService: product service.
854-
type ProductService struct {
855-
Name string `json:"name"`
856-
857-
Methods []string `json:"methods"`
858-
}
859-
860894
// ExportJobS3: export job s3.
861895
type ExportJobS3 struct {
862896
Bucket string `json:"bucket"`
@@ -869,6 +903,13 @@ type ExportJobS3 struct {
869903
ProjectID *string `json:"project_id"`
870904
}
871905

906+
// ProductService: product service.
907+
type ProductService struct {
908+
Name string `json:"name"`
909+
910+
Methods []string `json:"methods"`
911+
}
912+
872913
// ListCombinedEventsResponseCombinedEvent: list combined events response combined event.
873914
type ListCombinedEventsResponseCombinedEvent struct {
874915
// Precisely one of API, Auth, System must be set.
@@ -881,6 +922,31 @@ type ListCombinedEventsResponseCombinedEvent struct {
881922
System *SystemEvent `json:"system,omitempty"`
882923
}
883924

925+
// ExportJob: export job.
926+
type ExportJob struct {
927+
// ID: ID of the export job.
928+
ID string `json:"id"`
929+
930+
// OrganizationID: ID of the targeted Organization.
931+
OrganizationID string `json:"organization_id"`
932+
933+
// Name: name of the export.
934+
Name string `json:"name"`
935+
936+
// S3: destination in an S3 storage.
937+
// Precisely one of S3 must be set.
938+
S3 *ExportJobS3 `json:"s3,omitempty"`
939+
940+
// CreatedAt: export job creation date.
941+
CreatedAt *time.Time `json:"created_at"`
942+
943+
// LastRunAt: last export date.
944+
LastRunAt *time.Time `json:"last_run_at"`
945+
946+
// Tags: tags of the export.
947+
Tags map[string]string `json:"tags"`
948+
}
949+
884950
// Product: product.
885951
type Product struct {
886952
// Title: product title.
@@ -921,31 +987,6 @@ type DeleteExportJobRequest struct {
921987
ExportJobID string `json:"-"`
922988
}
923989

924-
// ExportJob: export job.
925-
type ExportJob struct {
926-
// ID: ID of the export job.
927-
ID string `json:"id"`
928-
929-
// OrganizationID: ID of the targeted Organization.
930-
OrganizationID string `json:"organization_id"`
931-
932-
// Name: name of the export.
933-
Name string `json:"name"`
934-
935-
// S3: destination in an S3 storage.
936-
// Precisely one of S3 must be set.
937-
S3 *ExportJobS3 `json:"s3,omitempty"`
938-
939-
// CreatedAt: export job creation date.
940-
CreatedAt *time.Time `json:"created_at"`
941-
942-
// LastRunAt: last export date.
943-
LastRunAt *time.Time `json:"last_run_at"`
944-
945-
// Tags: tags of the export.
946-
Tags map[string]string `json:"tags"`
947-
}
948-
949990
// ListAuthenticationEventsRequest: list authentication events request.
950991
type ListAuthenticationEventsRequest struct {
951992
// Region: region to target. If none is passed will use default region from the config.
@@ -1062,6 +1103,56 @@ type ListEventsResponse struct {
10621103
NextPageToken *string `json:"next_page_token"`
10631104
}
10641105

1106+
// ListExportJobsRequest: list export jobs request.
1107+
type ListExportJobsRequest struct {
1108+
// Region: region to target. If none is passed will use default region from the config.
1109+
Region scw.Region `json:"-"`
1110+
1111+
// OrganizationID: filter by Organization ID.
1112+
OrganizationID string `json:"-"`
1113+
1114+
// Name: (Optional) Filter by export name.
1115+
Name *string `json:"-"`
1116+
1117+
// Tags: (Optional) List of tags to filter on.
1118+
Tags map[string]string `json:"-"`
1119+
1120+
Page *int32 `json:"-"`
1121+
1122+
PageSize *uint32 `json:"-"`
1123+
1124+
// OrderBy: default value: name_asc
1125+
OrderBy ListExportJobsRequestOrderBy `json:"-"`
1126+
}
1127+
1128+
// ListExportJobsResponse: list export jobs response.
1129+
type ListExportJobsResponse struct {
1130+
// ExportJobs: single page of export jobs matching the requested criteria.
1131+
ExportJobs []*ExportJob `json:"export_jobs"`
1132+
1133+
// TotalCount: total count of export jobs matching the requested criteria.
1134+
TotalCount uint64 `json:"total_count"`
1135+
}
1136+
1137+
// UnsafeGetTotalCount should not be used
1138+
// Internal usage only
1139+
func (r *ListExportJobsResponse) UnsafeGetTotalCount() uint64 {
1140+
return r.TotalCount
1141+
}
1142+
1143+
// UnsafeAppend should not be used
1144+
// Internal usage only
1145+
func (r *ListExportJobsResponse) UnsafeAppend(res any) (uint64, error) {
1146+
results, ok := res.(*ListExportJobsResponse)
1147+
if !ok {
1148+
return 0, errors.New("%T type cannot be appended to type %T", res, r)
1149+
}
1150+
1151+
r.ExportJobs = append(r.ExportJobs, results.ExportJobs...)
1152+
r.TotalCount += uint64(len(results.ExportJobs))
1153+
return uint64(len(results.ExportJobs)), nil
1154+
}
1155+
10651156
// ListProductsRequest: list products request.
10661157
type ListProductsRequest struct {
10671158
// Region: region to target. If none is passed will use default region from the config.
@@ -1365,3 +1456,49 @@ func (s *API) DeleteExportJob(req *DeleteExportJobRequest, opts ...scw.RequestOp
13651456
}
13661457
return nil
13671458
}
1459+
1460+
// ListExportJobs:
1461+
func (s *API) ListExportJobs(req *ListExportJobsRequest, opts ...scw.RequestOption) (*ListExportJobsResponse, error) {
1462+
var err error
1463+
1464+
if req.Region == "" {
1465+
defaultRegion, _ := s.client.GetDefaultRegion()
1466+
req.Region = defaultRegion
1467+
}
1468+
1469+
if req.OrganizationID == "" {
1470+
defaultOrganizationID, _ := s.client.GetDefaultOrganizationID()
1471+
req.OrganizationID = defaultOrganizationID
1472+
}
1473+
1474+
defaultPageSize, exist := s.client.GetDefaultPageSize()
1475+
if (req.PageSize == nil || *req.PageSize == 0) && exist {
1476+
req.PageSize = &defaultPageSize
1477+
}
1478+
1479+
query := url.Values{}
1480+
parameter.AddToQuery(query, "organization_id", req.OrganizationID)
1481+
parameter.AddToQuery(query, "name", req.Name)
1482+
parameter.AddToQuery(query, "tags", req.Tags)
1483+
parameter.AddToQuery(query, "page", req.Page)
1484+
parameter.AddToQuery(query, "page_size", req.PageSize)
1485+
parameter.AddToQuery(query, "order_by", req.OrderBy)
1486+
1487+
if fmt.Sprint(req.Region) == "" {
1488+
return nil, errors.New("field Region cannot be empty in request")
1489+
}
1490+
1491+
scwReq := &scw.ScalewayRequest{
1492+
Method: "GET",
1493+
Path: "/audit-trail/v1alpha1/regions/" + fmt.Sprint(req.Region) + "/export-jobs",
1494+
Query: query,
1495+
}
1496+
1497+
var resp ListExportJobsResponse
1498+
1499+
err = s.client.Do(scwReq, &resp, opts...)
1500+
if err != nil {
1501+
return nil, err
1502+
}
1503+
return &resp, nil
1504+
}

0 commit comments

Comments
 (0)