Skip to content

Commit 7e7d78b

Browse files
authored
feat(audit_trail): add event export (scaleway#2745)
1 parent cecef1c commit 7e7d78b

File tree

1 file changed

+93
-0
lines changed

1 file changed

+93
-0
lines changed

api/audit_trail/v1alpha1/audit_trail_sdk.go

Lines changed: 93 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -857,6 +857,18 @@ type ProductService struct {
857857
Methods []string `json:"methods"`
858858
}
859859

860+
// ExportJobS3: export job s3.
861+
type ExportJobS3 struct {
862+
Bucket string `json:"bucket"`
863+
864+
// Region: region to target. If none is passed will use default region from the config.
865+
Region scw.Region `json:"region"`
866+
867+
Prefix *string `json:"prefix"`
868+
869+
ProjectID *string `json:"project_id"`
870+
}
871+
860872
// ListCombinedEventsResponseCombinedEvent: list combined events response combined event.
861873
type ListCombinedEventsResponseCombinedEvent struct {
862874
// Precisely one of API, Auth, System must be set.
@@ -881,6 +893,50 @@ type Product struct {
881893
Services []*ProductService `json:"services"`
882894
}
883895

896+
// CreateExportJobRequest: create export job request.
897+
type CreateExportJobRequest struct {
898+
// Region: region to target. If none is passed will use default region from the config.
899+
Region scw.Region `json:"-"`
900+
901+
// OrganizationID: ID of the Organization to target.
902+
OrganizationID string `json:"organization_id"`
903+
904+
// Name: name of the export.
905+
Name string `json:"name"`
906+
907+
// S3: the configuration specifying the bucket where the audit trail events will be exported.
908+
// Precisely one of S3 must be set.
909+
S3 *ExportJobS3 `json:"s3,omitempty"`
910+
911+
// Tags: tags of the export.
912+
Tags map[string]string `json:"tags"`
913+
}
914+
915+
// ExportJob: export job.
916+
type ExportJob struct {
917+
// ID: ID of the export job.
918+
ID string `json:"id"`
919+
920+
// OrganizationID: ID of the targeted Organization.
921+
OrganizationID string `json:"organization_id"`
922+
923+
// Name: name of the export.
924+
Name string `json:"name"`
925+
926+
// S3: destination in an S3 storage.
927+
// Precisely one of S3 must be set.
928+
S3 *ExportJobS3 `json:"s3,omitempty"`
929+
930+
// CreatedAt: export job creation date.
931+
CreatedAt *time.Time `json:"created_at"`
932+
933+
// LastRunAt: last export date.
934+
LastRunAt *time.Time `json:"last_run_at"`
935+
936+
// Tags: tags of the export.
937+
Tags map[string]string `json:"tags"`
938+
}
939+
884940
// ListAuthenticationEventsRequest: list authentication events request.
885941
type ListAuthenticationEventsRequest struct {
886942
// Region: region to target. If none is passed will use default region from the config.
@@ -1234,3 +1290,40 @@ func (s *API) ListProducts(req *ListProductsRequest, opts ...scw.RequestOption)
12341290
}
12351291
return &resp, nil
12361292
}
1293+
1294+
// CreateExportJob: Create an export job for a specified organization. This allows you to export audit trail events to a destination, such as an S3 bucket. The request requires the organization ID, a name for the export, and a destination configuration.
1295+
func (s *API) CreateExportJob(req *CreateExportJobRequest, opts ...scw.RequestOption) (*ExportJob, error) {
1296+
var err error
1297+
1298+
if req.Region == "" {
1299+
defaultRegion, _ := s.client.GetDefaultRegion()
1300+
req.Region = defaultRegion
1301+
}
1302+
1303+
if req.OrganizationID == "" {
1304+
defaultOrganizationID, _ := s.client.GetDefaultOrganizationID()
1305+
req.OrganizationID = defaultOrganizationID
1306+
}
1307+
1308+
if fmt.Sprint(req.Region) == "" {
1309+
return nil, errors.New("field Region cannot be empty in request")
1310+
}
1311+
1312+
scwReq := &scw.ScalewayRequest{
1313+
Method: "POST",
1314+
Path: "/audit-trail/v1alpha1/regions/" + fmt.Sprint(req.Region) + "/export-jobs",
1315+
}
1316+
1317+
err = scwReq.SetBody(req)
1318+
if err != nil {
1319+
return nil, err
1320+
}
1321+
1322+
var resp ExportJob
1323+
1324+
err = s.client.Do(scwReq, &resp, opts...)
1325+
if err != nil {
1326+
return nil, err
1327+
}
1328+
return &resp, nil
1329+
}

0 commit comments

Comments
 (0)