1package attestation 2 3// Copyright (c) Microsoft Corporation. All rights reserved. 4// Licensed under the MIT License. See License.txt in the project root for license information. 5// 6// Code generated by Microsoft (R) AutoRest Code Generator. 7// Changes may cause incorrect behavior and will be lost if the code is regenerated. 8 9import ( 10 "context" 11 "github.com/Azure/go-autorest/autorest" 12 "github.com/Azure/go-autorest/autorest/azure" 13 "github.com/Azure/go-autorest/tracing" 14 "net/http" 15) 16 17// Client is the describes the interface for the per-tenant enclave service. 18type Client struct { 19 BaseClient 20} 21 22// NewClient creates an instance of the Client client. 23func NewClient() Client { 24 return Client{New()} 25} 26 27// AttestOpenEnclave processes an OpenEnclave report , producing an artifact. The type of artifact produced is 28// dependent upon attestation policy. 29// Parameters: 30// instanceURL - the attestation instance base URI, for example https://mytenant.attest.azure.net. 31// request - request object containing the quote 32func (client Client) AttestOpenEnclave(ctx context.Context, instanceURL string, request AttestOpenEnclaveRequest) (result Response, err error) { 33 if tracing.IsEnabled() { 34 ctx = tracing.StartSpan(ctx, fqdn+"/Client.AttestOpenEnclave") 35 defer func() { 36 sc := -1 37 if result.Response.Response != nil { 38 sc = result.Response.Response.StatusCode 39 } 40 tracing.EndSpan(ctx, sc, err) 41 }() 42 } 43 req, err := client.AttestOpenEnclavePreparer(ctx, instanceURL, request) 44 if err != nil { 45 err = autorest.NewErrorWithError(err, "attestation.Client", "AttestOpenEnclave", nil, "Failure preparing request") 46 return 47 } 48 49 resp, err := client.AttestOpenEnclaveSender(req) 50 if err != nil { 51 result.Response = autorest.Response{Response: resp} 52 err = autorest.NewErrorWithError(err, "attestation.Client", "AttestOpenEnclave", resp, "Failure sending request") 53 return 54 } 55 56 result, err = client.AttestOpenEnclaveResponder(resp) 57 if err != nil { 58 err = autorest.NewErrorWithError(err, "attestation.Client", "AttestOpenEnclave", resp, "Failure responding to request") 59 return 60 } 61 62 return 63} 64 65// AttestOpenEnclavePreparer prepares the AttestOpenEnclave request. 66func (client Client) AttestOpenEnclavePreparer(ctx context.Context, instanceURL string, request AttestOpenEnclaveRequest) (*http.Request, error) { 67 urlParameters := map[string]interface{}{ 68 "instanceUrl": instanceURL, 69 } 70 71 const APIVersion = "2020-10-01" 72 queryParameters := map[string]interface{}{ 73 "api-version": APIVersion, 74 } 75 76 preparer := autorest.CreatePreparer( 77 autorest.AsContentType("application/json; charset=utf-8"), 78 autorest.AsPost(), 79 autorest.WithCustomBaseURL("{instanceUrl}", urlParameters), 80 autorest.WithPath("/attest/OpenEnclave"), 81 autorest.WithJSON(request), 82 autorest.WithQueryParameters(queryParameters)) 83 return preparer.Prepare((&http.Request{}).WithContext(ctx)) 84} 85 86// AttestOpenEnclaveSender sends the AttestOpenEnclave request. The method will close the 87// http.Response Body if it receives an error. 88func (client Client) AttestOpenEnclaveSender(req *http.Request) (*http.Response, error) { 89 return client.Send(req, autorest.DoRetryForStatusCodes(client.RetryAttempts, client.RetryDuration, autorest.StatusCodesForRetry...)) 90} 91 92// AttestOpenEnclaveResponder handles the response to the AttestOpenEnclave request. The method always 93// closes the http.Response Body. 94func (client Client) AttestOpenEnclaveResponder(resp *http.Response) (result Response, err error) { 95 err = autorest.Respond( 96 resp, 97 azure.WithErrorUnlessStatusCode(http.StatusOK), 98 autorest.ByUnmarshallingJSON(&result), 99 autorest.ByClosing()) 100 result.Response = autorest.Response{Response: resp} 101 return 102} 103 104// AttestSgxEnclave processes an SGX enclave quote, producing an artifact. The type of artifact produced is dependent 105// upon attestation policy. 106// Parameters: 107// instanceURL - the attestation instance base URI, for example https://mytenant.attest.azure.net. 108// request - request object containing the quote 109func (client Client) AttestSgxEnclave(ctx context.Context, instanceURL string, request AttestSgxEnclaveRequest) (result Response, err error) { 110 if tracing.IsEnabled() { 111 ctx = tracing.StartSpan(ctx, fqdn+"/Client.AttestSgxEnclave") 112 defer func() { 113 sc := -1 114 if result.Response.Response != nil { 115 sc = result.Response.Response.StatusCode 116 } 117 tracing.EndSpan(ctx, sc, err) 118 }() 119 } 120 req, err := client.AttestSgxEnclavePreparer(ctx, instanceURL, request) 121 if err != nil { 122 err = autorest.NewErrorWithError(err, "attestation.Client", "AttestSgxEnclave", nil, "Failure preparing request") 123 return 124 } 125 126 resp, err := client.AttestSgxEnclaveSender(req) 127 if err != nil { 128 result.Response = autorest.Response{Response: resp} 129 err = autorest.NewErrorWithError(err, "attestation.Client", "AttestSgxEnclave", resp, "Failure sending request") 130 return 131 } 132 133 result, err = client.AttestSgxEnclaveResponder(resp) 134 if err != nil { 135 err = autorest.NewErrorWithError(err, "attestation.Client", "AttestSgxEnclave", resp, "Failure responding to request") 136 return 137 } 138 139 return 140} 141 142// AttestSgxEnclavePreparer prepares the AttestSgxEnclave request. 143func (client Client) AttestSgxEnclavePreparer(ctx context.Context, instanceURL string, request AttestSgxEnclaveRequest) (*http.Request, error) { 144 urlParameters := map[string]interface{}{ 145 "instanceUrl": instanceURL, 146 } 147 148 const APIVersion = "2020-10-01" 149 queryParameters := map[string]interface{}{ 150 "api-version": APIVersion, 151 } 152 153 preparer := autorest.CreatePreparer( 154 autorest.AsContentType("application/json; charset=utf-8"), 155 autorest.AsPost(), 156 autorest.WithCustomBaseURL("{instanceUrl}", urlParameters), 157 autorest.WithPath("/attest/SgxEnclave"), 158 autorest.WithJSON(request), 159 autorest.WithQueryParameters(queryParameters)) 160 return preparer.Prepare((&http.Request{}).WithContext(ctx)) 161} 162 163// AttestSgxEnclaveSender sends the AttestSgxEnclave request. The method will close the 164// http.Response Body if it receives an error. 165func (client Client) AttestSgxEnclaveSender(req *http.Request) (*http.Response, error) { 166 return client.Send(req, autorest.DoRetryForStatusCodes(client.RetryAttempts, client.RetryDuration, autorest.StatusCodesForRetry...)) 167} 168 169// AttestSgxEnclaveResponder handles the response to the AttestSgxEnclave request. The method always 170// closes the http.Response Body. 171func (client Client) AttestSgxEnclaveResponder(resp *http.Response) (result Response, err error) { 172 err = autorest.Respond( 173 resp, 174 azure.WithErrorUnlessStatusCode(http.StatusOK), 175 autorest.ByUnmarshallingJSON(&result), 176 autorest.ByClosing()) 177 result.Response = autorest.Response{Response: resp} 178 return 179} 180 181// AttestTpm processes attestation evidence from a VBS enclave, producing an attestation result. The attestation result 182// produced is dependent upon the attestation policy. 183// Parameters: 184// instanceURL - the attestation instance base URI, for example https://mytenant.attest.azure.net. 185// request - request object 186func (client Client) AttestTpm(ctx context.Context, instanceURL string, request TpmAttestationRequest) (result TpmAttestationResponse, err error) { 187 if tracing.IsEnabled() { 188 ctx = tracing.StartSpan(ctx, fqdn+"/Client.AttestTpm") 189 defer func() { 190 sc := -1 191 if result.Response.Response != nil { 192 sc = result.Response.Response.StatusCode 193 } 194 tracing.EndSpan(ctx, sc, err) 195 }() 196 } 197 req, err := client.AttestTpmPreparer(ctx, instanceURL, request) 198 if err != nil { 199 err = autorest.NewErrorWithError(err, "attestation.Client", "AttestTpm", nil, "Failure preparing request") 200 return 201 } 202 203 resp, err := client.AttestTpmSender(req) 204 if err != nil { 205 result.Response = autorest.Response{Response: resp} 206 err = autorest.NewErrorWithError(err, "attestation.Client", "AttestTpm", resp, "Failure sending request") 207 return 208 } 209 210 result, err = client.AttestTpmResponder(resp) 211 if err != nil { 212 err = autorest.NewErrorWithError(err, "attestation.Client", "AttestTpm", resp, "Failure responding to request") 213 return 214 } 215 216 return 217} 218 219// AttestTpmPreparer prepares the AttestTpm request. 220func (client Client) AttestTpmPreparer(ctx context.Context, instanceURL string, request TpmAttestationRequest) (*http.Request, error) { 221 urlParameters := map[string]interface{}{ 222 "instanceUrl": instanceURL, 223 } 224 225 const APIVersion = "2020-10-01" 226 queryParameters := map[string]interface{}{ 227 "api-version": APIVersion, 228 } 229 230 preparer := autorest.CreatePreparer( 231 autorest.AsContentType("application/json; charset=utf-8"), 232 autorest.AsPost(), 233 autorest.WithCustomBaseURL("{instanceUrl}", urlParameters), 234 autorest.WithPath("/attest/Tpm"), 235 autorest.WithJSON(request), 236 autorest.WithQueryParameters(queryParameters)) 237 return preparer.Prepare((&http.Request{}).WithContext(ctx)) 238} 239 240// AttestTpmSender sends the AttestTpm request. The method will close the 241// http.Response Body if it receives an error. 242func (client Client) AttestTpmSender(req *http.Request) (*http.Response, error) { 243 return client.Send(req, autorest.DoRetryForStatusCodes(client.RetryAttempts, client.RetryDuration, autorest.StatusCodesForRetry...)) 244} 245 246// AttestTpmResponder handles the response to the AttestTpm request. The method always 247// closes the http.Response Body. 248func (client Client) AttestTpmResponder(resp *http.Response) (result TpmAttestationResponse, err error) { 249 err = autorest.Respond( 250 resp, 251 azure.WithErrorUnlessStatusCode(http.StatusOK), 252 autorest.ByUnmarshallingJSON(&result), 253 autorest.ByClosing()) 254 result.Response = autorest.Response{Response: resp} 255 return 256} 257