1//
2// Copyright (c) 2018, Joyent, Inc. All rights reserved.
3//
4// This Source Code Form is subject to the terms of the Mozilla Public
5// License, v. 2.0. If a copy of the MPL was not distributed with this
6// file, You can obtain one at http://mozilla.org/MPL/2.0/.
7//
8
9package compute
10
11import (
12	"net/http"
13
14	triton "github.com/joyent/triton-go"
15	"github.com/joyent/triton-go/client"
16)
17
18type ComputeClient struct {
19	Client *client.Client
20}
21
22func newComputeClient(client *client.Client) *ComputeClient {
23	return &ComputeClient{
24		Client: client,
25	}
26}
27
28// NewClient returns a new client for working with Compute endpoints and
29// resources within CloudAPI
30func NewClient(config *triton.ClientConfig) (*ComputeClient, error) {
31	// TODO: Utilize config interface within the function itself
32	client, err := client.New(
33		config.TritonURL,
34		config.MantaURL,
35		config.AccountName,
36		config.Signers...,
37	)
38	if err != nil {
39		return nil, err
40	}
41	return newComputeClient(client), nil
42}
43
44// SetHeaders allows a consumer of the current client to set custom headers for
45// the next backend HTTP request sent to CloudAPI
46func (c *ComputeClient) SetHeader(header *http.Header) {
47	c.Client.RequestHeader = header
48}
49
50// Datacenters returns a Compute client used for accessing functions pertaining
51// to DataCenter functionality in the Triton API.
52func (c *ComputeClient) Datacenters() *DataCentersClient {
53	return &DataCentersClient{c.Client}
54}
55
56// Images returns a Compute client used for accessing functions pertaining to
57// Images functionality in the Triton API.
58func (c *ComputeClient) Images() *ImagesClient {
59	return &ImagesClient{c.Client}
60}
61
62// Machine returns a Compute client used for accessing functions pertaining to
63// machine functionality in the Triton API.
64func (c *ComputeClient) Instances() *InstancesClient {
65	return &InstancesClient{c.Client}
66}
67
68// Packages returns a Compute client used for accessing functions pertaining to
69// Packages functionality in the Triton API.
70func (c *ComputeClient) Packages() *PackagesClient {
71	return &PackagesClient{c.Client}
72}
73
74// Services returns a Compute client used for accessing functions pertaining to
75// Services functionality in the Triton API.
76func (c *ComputeClient) Services() *ServicesClient {
77	return &ServicesClient{c.Client}
78}
79
80// Snapshots returns a Compute client used for accessing functions pertaining to
81// Snapshots functionality in the Triton API.
82func (c *ComputeClient) Snapshots() *SnapshotsClient {
83	return &SnapshotsClient{c.Client}
84}
85
86// Snapshots returns a Compute client used for accessing functions pertaining to
87// Snapshots functionality in the Triton API.
88func (c *ComputeClient) Volumes() *VolumesClient {
89	return &VolumesClient{c.Client}
90}
91