1// Copyright (c) 2016, 2018, 2019, Oracle and/or its affiliates. All rights reserved. 2// Code generated. DO NOT EDIT. 3 4// Audit API 5// 6// API for the Audit Service. Use this API for compliance monitoring in your tenancy. 7// For more information, see Overview of Audit (https://docs.cloud.oracle.com/iaas/Content/Audit/Concepts/auditoverview.htm). 8// **Tip**: This API is good for queries, but not bulk-export operations. 9// 10 11package audit 12 13import ( 14 "context" 15 "fmt" 16 "github.com/oracle/oci-go-sdk/common" 17 "net/http" 18) 19 20//AuditClient a client for Audit 21type AuditClient struct { 22 common.BaseClient 23 config *common.ConfigurationProvider 24} 25 26// NewAuditClientWithConfigurationProvider Creates a new default Audit client with the given configuration provider. 27// the configuration provider will be used for the default signer as well as reading the region 28func NewAuditClientWithConfigurationProvider(configProvider common.ConfigurationProvider) (client AuditClient, err error) { 29 baseClient, err := common.NewClientWithConfig(configProvider) 30 if err != nil { 31 return 32 } 33 34 client = AuditClient{BaseClient: baseClient} 35 client.BasePath = "20190901" 36 err = client.setConfigurationProvider(configProvider) 37 return 38} 39 40// SetRegion overrides the region of this client. 41func (client *AuditClient) SetRegion(region string) { 42 client.Host = common.StringToRegion(region).EndpointForTemplate("audit", "https://audit.{region}.oraclecloud.com") 43} 44 45// SetConfigurationProvider sets the configuration provider including the region, returns an error if is not valid 46func (client *AuditClient) setConfigurationProvider(configProvider common.ConfigurationProvider) error { 47 if ok, err := common.IsConfigurationProviderValid(configProvider); !ok { 48 return err 49 } 50 51 // Error has been checked already 52 region, _ := configProvider.Region() 53 client.SetRegion(region) 54 client.config = &configProvider 55 return nil 56} 57 58// ConfigurationProvider the ConfigurationProvider used in this client, or null if none set 59func (client *AuditClient) ConfigurationProvider() *common.ConfigurationProvider { 60 return client.config 61} 62 63// GetConfiguration Get the configuration 64func (client AuditClient) GetConfiguration(ctx context.Context, request GetConfigurationRequest) (response GetConfigurationResponse, err error) { 65 var ociResponse common.OCIResponse 66 policy := common.NoRetryPolicy() 67 if request.RetryPolicy() != nil { 68 policy = *request.RetryPolicy() 69 } 70 ociResponse, err = common.Retry(ctx, request, client.getConfiguration, policy) 71 if err != nil { 72 if ociResponse != nil { 73 response = GetConfigurationResponse{RawResponse: ociResponse.HTTPResponse()} 74 } 75 return 76 } 77 if convertedResponse, ok := ociResponse.(GetConfigurationResponse); ok { 78 response = convertedResponse 79 } else { 80 err = fmt.Errorf("failed to convert OCIResponse into GetConfigurationResponse") 81 } 82 return 83} 84 85// getConfiguration implements the OCIOperation interface (enables retrying operations) 86func (client AuditClient) getConfiguration(ctx context.Context, request common.OCIRequest) (common.OCIResponse, error) { 87 httpRequest, err := request.HTTPRequest(http.MethodGet, "/configuration") 88 if err != nil { 89 return nil, err 90 } 91 92 var response GetConfigurationResponse 93 var httpResponse *http.Response 94 httpResponse, err = client.Call(ctx, &httpRequest) 95 defer common.CloseBodyIfValid(httpResponse) 96 response.RawResponse = httpResponse 97 if err != nil { 98 return response, err 99 } 100 101 err = common.UnmarshalResponse(httpResponse, &response) 102 return response, err 103} 104 105// ListEvents Returns all the audit events processed for the specified compartment within the specified 106// time range. 107func (client AuditClient) ListEvents(ctx context.Context, request ListEventsRequest) (response ListEventsResponse, err error) { 108 var ociResponse common.OCIResponse 109 policy := common.NoRetryPolicy() 110 if request.RetryPolicy() != nil { 111 policy = *request.RetryPolicy() 112 } 113 ociResponse, err = common.Retry(ctx, request, client.listEvents, policy) 114 if err != nil { 115 if ociResponse != nil { 116 response = ListEventsResponse{RawResponse: ociResponse.HTTPResponse()} 117 } 118 return 119 } 120 if convertedResponse, ok := ociResponse.(ListEventsResponse); ok { 121 response = convertedResponse 122 } else { 123 err = fmt.Errorf("failed to convert OCIResponse into ListEventsResponse") 124 } 125 return 126} 127 128// listEvents implements the OCIOperation interface (enables retrying operations) 129func (client AuditClient) listEvents(ctx context.Context, request common.OCIRequest) (common.OCIResponse, error) { 130 httpRequest, err := request.HTTPRequest(http.MethodGet, "/auditEvents") 131 if err != nil { 132 return nil, err 133 } 134 135 var response ListEventsResponse 136 var httpResponse *http.Response 137 httpResponse, err = client.Call(ctx, &httpRequest) 138 defer common.CloseBodyIfValid(httpResponse) 139 response.RawResponse = httpResponse 140 if err != nil { 141 return response, err 142 } 143 144 err = common.UnmarshalResponse(httpResponse, &response) 145 return response, err 146} 147 148// UpdateConfiguration Update the configuration 149func (client AuditClient) UpdateConfiguration(ctx context.Context, request UpdateConfigurationRequest) (response UpdateConfigurationResponse, err error) { 150 var ociResponse common.OCIResponse 151 policy := common.NoRetryPolicy() 152 if request.RetryPolicy() != nil { 153 policy = *request.RetryPolicy() 154 } 155 ociResponse, err = common.Retry(ctx, request, client.updateConfiguration, policy) 156 if err != nil { 157 if ociResponse != nil { 158 response = UpdateConfigurationResponse{RawResponse: ociResponse.HTTPResponse()} 159 } 160 return 161 } 162 if convertedResponse, ok := ociResponse.(UpdateConfigurationResponse); ok { 163 response = convertedResponse 164 } else { 165 err = fmt.Errorf("failed to convert OCIResponse into UpdateConfigurationResponse") 166 } 167 return 168} 169 170// updateConfiguration implements the OCIOperation interface (enables retrying operations) 171func (client AuditClient) updateConfiguration(ctx context.Context, request common.OCIRequest) (common.OCIResponse, error) { 172 httpRequest, err := request.HTTPRequest(http.MethodPut, "/configuration") 173 if err != nil { 174 return nil, err 175 } 176 177 var response UpdateConfigurationResponse 178 var httpResponse *http.Response 179 httpResponse, err = client.Call(ctx, &httpRequest) 180 defer common.CloseBodyIfValid(httpResponse) 181 response.RawResponse = httpResponse 182 if err != nil { 183 return response, err 184 } 185 186 err = common.UnmarshalResponse(httpResponse, &response) 187 return response, err 188} 189