1// Copyright 2021 Google LLC. 2// Use of this source code is governed by a BSD-style 3// license that can be found in the LICENSE file. 4 5// Code generated file. DO NOT EDIT. 6 7// Package baremetalsolution provides access to the Bare Metal Solution API. 8// 9// For product documentation, see: https://cloud.google.com/bare-metal 10// 11// Creating a client 12// 13// Usage example: 14// 15// import "google.golang.org/api/baremetalsolution/v1" 16// ... 17// ctx := context.Background() 18// baremetalsolutionService, err := baremetalsolution.NewService(ctx) 19// 20// In this example, Google Application Default Credentials are used for authentication. 21// 22// For information on how to create and obtain Application Default Credentials, see https://developers.google.com/identity/protocols/application-default-credentials. 23// 24// Other authentication options 25// 26// To use an API key for authentication (note: some APIs do not support API keys), use option.WithAPIKey: 27// 28// baremetalsolutionService, err := baremetalsolution.NewService(ctx, option.WithAPIKey("AIza...")) 29// 30// To use an OAuth token (e.g., a user token obtained via a three-legged OAuth flow), use option.WithTokenSource: 31// 32// config := &oauth2.Config{...} 33// // ... 34// token, err := config.Exchange(ctx, ...) 35// baremetalsolutionService, err := baremetalsolution.NewService(ctx, option.WithTokenSource(config.TokenSource(ctx, token))) 36// 37// See https://godoc.org/google.golang.org/api/option/ for details on options. 38package baremetalsolution // import "google.golang.org/api/baremetalsolution/v1" 39 40import ( 41 "bytes" 42 "context" 43 "encoding/json" 44 "errors" 45 "fmt" 46 "io" 47 "net/http" 48 "net/url" 49 "strconv" 50 "strings" 51 52 googleapi "google.golang.org/api/googleapi" 53 gensupport "google.golang.org/api/internal/gensupport" 54 option "google.golang.org/api/option" 55 internaloption "google.golang.org/api/option/internaloption" 56 htransport "google.golang.org/api/transport/http" 57) 58 59// Always reference these packages, just in case the auto-generated code 60// below doesn't. 61var _ = bytes.NewBuffer 62var _ = strconv.Itoa 63var _ = fmt.Sprintf 64var _ = json.NewDecoder 65var _ = io.Copy 66var _ = url.Parse 67var _ = gensupport.MarshalJSON 68var _ = googleapi.Version 69var _ = errors.New 70var _ = strings.Replace 71var _ = context.Canceled 72var _ = internaloption.WithDefaultEndpoint 73 74const apiId = "baremetalsolution:v1" 75const apiName = "baremetalsolution" 76const apiVersion = "v1" 77const basePath = "https://baremetalsolution.googleapis.com/" 78const mtlsBasePath = "https://baremetalsolution.mtls.googleapis.com/" 79 80// OAuth2 scopes used by this API. 81const ( 82 // See, edit, configure, and delete your Google Cloud data and see the 83 // email address for your Google Account. 84 CloudPlatformScope = "https://www.googleapis.com/auth/cloud-platform" 85) 86 87// NewService creates a new Service. 88func NewService(ctx context.Context, opts ...option.ClientOption) (*Service, error) { 89 scopesOption := option.WithScopes( 90 "https://www.googleapis.com/auth/cloud-platform", 91 ) 92 // NOTE: prepend, so we don't override user-specified scopes. 93 opts = append([]option.ClientOption{scopesOption}, opts...) 94 opts = append(opts, internaloption.WithDefaultEndpoint(basePath)) 95 opts = append(opts, internaloption.WithDefaultMTLSEndpoint(mtlsBasePath)) 96 client, endpoint, err := htransport.NewClient(ctx, opts...) 97 if err != nil { 98 return nil, err 99 } 100 s, err := New(client) 101 if err != nil { 102 return nil, err 103 } 104 if endpoint != "" { 105 s.BasePath = endpoint 106 } 107 return s, nil 108} 109 110// New creates a new Service. It uses the provided http.Client for requests. 111// 112// Deprecated: please use NewService instead. 113// To provide a custom HTTP client, use option.WithHTTPClient. 114// If you are using google.golang.org/api/googleapis/transport.APIKey, use option.WithAPIKey with NewService instead. 115func New(client *http.Client) (*Service, error) { 116 if client == nil { 117 return nil, errors.New("client is nil") 118 } 119 s := &Service{client: client, BasePath: basePath} 120 s.Projects = NewProjectsService(s) 121 return s, nil 122} 123 124type Service struct { 125 client *http.Client 126 BasePath string // API endpoint base URL 127 UserAgent string // optional additional User-Agent fragment 128 129 Projects *ProjectsService 130} 131 132func (s *Service) userAgent() string { 133 if s.UserAgent == "" { 134 return googleapi.UserAgent 135 } 136 return googleapi.UserAgent + " " + s.UserAgent 137} 138 139func NewProjectsService(s *Service) *ProjectsService { 140 rs := &ProjectsService{s: s} 141 rs.Locations = NewProjectsLocationsService(s) 142 return rs 143} 144 145type ProjectsService struct { 146 s *Service 147 148 Locations *ProjectsLocationsService 149} 150 151func NewProjectsLocationsService(s *Service) *ProjectsLocationsService { 152 rs := &ProjectsLocationsService{s: s} 153 rs.Instances = NewProjectsLocationsInstancesService(s) 154 return rs 155} 156 157type ProjectsLocationsService struct { 158 s *Service 159 160 Instances *ProjectsLocationsInstancesService 161} 162 163func NewProjectsLocationsInstancesService(s *Service) *ProjectsLocationsInstancesService { 164 rs := &ProjectsLocationsInstancesService{s: s} 165 return rs 166} 167 168type ProjectsLocationsInstancesService struct { 169 s *Service 170} 171 172// ResetInstanceRequest: Request for ResetInstance. 173type ResetInstanceRequest struct { 174} 175 176// ResetInstanceResponse: Response for ResetInstance. 177type ResetInstanceResponse struct { 178 // ServerResponse contains the HTTP response code and headers from the 179 // server. 180 googleapi.ServerResponse `json:"-"` 181} 182 183// method id "baremetalsolution.projects.locations.instances.resetInstance": 184 185type ProjectsLocationsInstancesResetInstanceCall struct { 186 s *Service 187 instance string 188 resetinstancerequest *ResetInstanceRequest 189 urlParams_ gensupport.URLParams 190 ctx_ context.Context 191 header_ http.Header 192} 193 194// ResetInstance: Perform an ungraceful, hard reset on a machine 195// (equivalent to shutting the power off, and then turning it back on). 196// 197// - instance: Name of the instance to reset. 198func (r *ProjectsLocationsInstancesService) ResetInstance(instance string, resetinstancerequest *ResetInstanceRequest) *ProjectsLocationsInstancesResetInstanceCall { 199 c := &ProjectsLocationsInstancesResetInstanceCall{s: r.s, urlParams_: make(gensupport.URLParams)} 200 c.instance = instance 201 c.resetinstancerequest = resetinstancerequest 202 return c 203} 204 205// Fields allows partial responses to be retrieved. See 206// https://developers.google.com/gdata/docs/2.0/basics#PartialResponse 207// for more information. 208func (c *ProjectsLocationsInstancesResetInstanceCall) Fields(s ...googleapi.Field) *ProjectsLocationsInstancesResetInstanceCall { 209 c.urlParams_.Set("fields", googleapi.CombineFields(s)) 210 return c 211} 212 213// Context sets the context to be used in this call's Do method. Any 214// pending HTTP request will be aborted if the provided context is 215// canceled. 216func (c *ProjectsLocationsInstancesResetInstanceCall) Context(ctx context.Context) *ProjectsLocationsInstancesResetInstanceCall { 217 c.ctx_ = ctx 218 return c 219} 220 221// Header returns an http.Header that can be modified by the caller to 222// add HTTP headers to the request. 223func (c *ProjectsLocationsInstancesResetInstanceCall) Header() http.Header { 224 if c.header_ == nil { 225 c.header_ = make(http.Header) 226 } 227 return c.header_ 228} 229 230func (c *ProjectsLocationsInstancesResetInstanceCall) doRequest(alt string) (*http.Response, error) { 231 reqHeaders := make(http.Header) 232 reqHeaders.Set("x-goog-api-client", "gl-go/"+gensupport.GoVersion()+" gdcl/20210915") 233 for k, v := range c.header_ { 234 reqHeaders[k] = v 235 } 236 reqHeaders.Set("User-Agent", c.s.userAgent()) 237 var body io.Reader = nil 238 body, err := googleapi.WithoutDataWrapper.JSONReader(c.resetinstancerequest) 239 if err != nil { 240 return nil, err 241 } 242 reqHeaders.Set("Content-Type", "application/json") 243 c.urlParams_.Set("alt", alt) 244 c.urlParams_.Set("prettyPrint", "false") 245 urls := googleapi.ResolveRelative(c.s.BasePath, "v1/{+instance}:resetInstance") 246 urls += "?" + c.urlParams_.Encode() 247 req, err := http.NewRequest("POST", urls, body) 248 if err != nil { 249 return nil, err 250 } 251 req.Header = reqHeaders 252 googleapi.Expand(req.URL, map[string]string{ 253 "instance": c.instance, 254 }) 255 return gensupport.SendRequest(c.ctx_, c.s.client, req) 256} 257 258// Do executes the "baremetalsolution.projects.locations.instances.resetInstance" call. 259// Exactly one of *ResetInstanceResponse or error will be non-nil. Any 260// non-2xx status code is an error. Response headers are in either 261// *ResetInstanceResponse.ServerResponse.Header or (if a response was 262// returned at all) in error.(*googleapi.Error).Header. Use 263// googleapi.IsNotModified to check whether the returned error was 264// because http.StatusNotModified was returned. 265func (c *ProjectsLocationsInstancesResetInstanceCall) Do(opts ...googleapi.CallOption) (*ResetInstanceResponse, error) { 266 gensupport.SetOptions(c.urlParams_, opts...) 267 res, err := c.doRequest("json") 268 if res != nil && res.StatusCode == http.StatusNotModified { 269 if res.Body != nil { 270 res.Body.Close() 271 } 272 return nil, &googleapi.Error{ 273 Code: res.StatusCode, 274 Header: res.Header, 275 } 276 } 277 if err != nil { 278 return nil, err 279 } 280 defer googleapi.CloseBody(res) 281 if err := googleapi.CheckResponse(res); err != nil { 282 return nil, err 283 } 284 ret := &ResetInstanceResponse{ 285 ServerResponse: googleapi.ServerResponse{ 286 Header: res.Header, 287 HTTPStatusCode: res.StatusCode, 288 }, 289 } 290 target := &ret 291 if err := gensupport.DecodeResponse(target, res); err != nil { 292 return nil, err 293 } 294 return ret, nil 295 // { 296 // "description": "Perform an ungraceful, hard reset on a machine (equivalent to shutting the power off, and then turning it back on).", 297 // "flatPath": "v1/projects/{projectsId}/locations/{locationsId}/instances/{instancesId}:resetInstance", 298 // "httpMethod": "POST", 299 // "id": "baremetalsolution.projects.locations.instances.resetInstance", 300 // "parameterOrder": [ 301 // "instance" 302 // ], 303 // "parameters": { 304 // "instance": { 305 // "description": "Required. Name of the instance to reset.", 306 // "location": "path", 307 // "pattern": "^projects/[^/]+/locations/[^/]+/instances/[^/]+$", 308 // "required": true, 309 // "type": "string" 310 // } 311 // }, 312 // "path": "v1/{+instance}:resetInstance", 313 // "request": { 314 // "$ref": "ResetInstanceRequest" 315 // }, 316 // "response": { 317 // "$ref": "ResetInstanceResponse" 318 // }, 319 // "scopes": [ 320 // "https://www.googleapis.com/auth/cloud-platform" 321 // ] 322 // } 323 324} 325