ops_certificate_authority.go raw
1 // Copyright 2022-2025 The sacloud/iaas-api-go Authors
2 //
3 // Licensed under the Apache License, Version 2.0 (the "License");
4 // you may not use this file except in compliance with the License.
5 // You may obtain a copy of the License at
6 //
7 // http://www.apache.org/licenses/LICENSE-2.0
8 //
9 // Unless required by applicable law or agreed to in writing, software
10 // distributed under the License is distributed on an "AS IS" BASIS,
11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 // See the License for the specific language governing permissions and
13 // limitations under the License.
14
15 package fake
16
17 import (
18 "context"
19 "fmt"
20 "time"
21
22 "github.com/sacloud/iaas-api-go"
23 "github.com/sacloud/iaas-api-go/types"
24 )
25
26 // Find is fake implementation
27 func (o *CertificateAuthorityOp) Find(ctx context.Context, conditions *iaas.FindCondition) (*iaas.CertificateAuthorityFindResult, error) {
28 results, _ := find(o.key, iaas.APIDefaultZone, conditions)
29 var values []*iaas.CertificateAuthority
30 for _, res := range results {
31 dest := &iaas.CertificateAuthority{}
32 copySameNameField(res, dest)
33 values = append(values, dest)
34 }
35 return &iaas.CertificateAuthorityFindResult{
36 Total: len(results),
37 Count: len(results),
38 From: 0,
39 CertificateAuthorities: values,
40 }, nil
41 }
42
43 // Create is fake implementation
44 func (o *CertificateAuthorityOp) Create(ctx context.Context, param *iaas.CertificateAuthorityCreateRequest) (*iaas.CertificateAuthority, error) {
45 result := &iaas.CertificateAuthority{}
46 copySameNameField(param, result)
47 fill(result, fillID, fillCreatedAt)
48 result.Availability = types.Availabilities.Available
49
50 putCertificateAuthority(iaas.APIDefaultZone, result)
51 return result, nil
52 }
53
54 // Read is fake implementation
55 func (o *CertificateAuthorityOp) Read(ctx context.Context, id types.ID) (*iaas.CertificateAuthority, error) {
56 value := getCertificateAuthorityByID(iaas.APIDefaultZone, id)
57 if value == nil {
58 return nil, newErrorNotFound(o.key, id)
59 }
60 dest := &iaas.CertificateAuthority{}
61 copySameNameField(value, dest)
62 return dest, nil
63 }
64
65 // Update is fake implementation
66 func (o *CertificateAuthorityOp) Update(ctx context.Context, id types.ID, param *iaas.CertificateAuthorityUpdateRequest) (*iaas.CertificateAuthority, error) {
67 value, err := o.Read(ctx, id)
68 if err != nil {
69 return nil, err
70 }
71 copySameNameField(param, value)
72 fill(value, fillModifiedAt)
73
74 return value, nil
75 }
76
77 // Delete is fake implementation
78 func (o *CertificateAuthorityOp) Delete(ctx context.Context, id types.ID) error {
79 _, err := o.Read(ctx, id)
80 if err != nil {
81 return err
82 }
83
84 ds().Delete(o.key, iaas.APIDefaultZone, id)
85 return nil
86 }
87
88 func (o *CertificateAuthorityOp) Detail(ctx context.Context, id types.ID) (*iaas.CertificateAuthorityDetail, error) {
89 _, err := o.Read(ctx, id)
90 if err != nil {
91 return nil, err
92 }
93 return &iaas.CertificateAuthorityDetail{
94 Subject: "fake",
95 CertificateData: &iaas.CertificateData{
96 CertificatePEM: "...",
97 Subject: "fake",
98 SerialNumber: "...",
99 NotBefore: time.Time{},
100 NotAfter: time.Time{},
101 },
102 }, nil
103 }
104
105 func (o *CertificateAuthorityOp) ListClients(ctx context.Context, id types.ID) (*iaas.CertificateAuthorityListClientsResult, error) {
106 return nil, fmt.Errorf("not supported")
107 }
108
109 func (o *CertificateAuthorityOp) ReadClient(ctx context.Context, id types.ID, clientID string) (*iaas.CertificateAuthorityClient, error) {
110 return nil, fmt.Errorf("not supported")
111 }
112
113 func (o *CertificateAuthorityOp) HoldClient(ctx context.Context, id types.ID, clientID string) error {
114 return fmt.Errorf("not supported")
115 }
116
117 func (o *CertificateAuthorityOp) ResumeClient(ctx context.Context, id types.ID, clientID string) error {
118 return fmt.Errorf("not supported")
119 }
120
121 func (o *CertificateAuthorityOp) RevokeClient(ctx context.Context, id types.ID, clientID string) error {
122 return fmt.Errorf("not supported")
123 }
124
125 func (o *CertificateAuthorityOp) DenyClient(ctx context.Context, id types.ID, clientID string) error {
126 return fmt.Errorf("not supported")
127 }
128
129 func (o *CertificateAuthorityOp) ListServers(ctx context.Context, id types.ID) (*iaas.CertificateAuthorityListServersResult, error) {
130 return nil, fmt.Errorf("not supported")
131 }
132
133 func (o *CertificateAuthorityOp) ReadServer(ctx context.Context, id types.ID, serverID string) (*iaas.CertificateAuthorityServer, error) {
134 return nil, fmt.Errorf("not supported")
135 }
136
137 func (o *CertificateAuthorityOp) HoldServer(ctx context.Context, id types.ID, serverID string) error {
138 return fmt.Errorf("not supported")
139 }
140
141 func (o *CertificateAuthorityOp) ResumeServer(ctx context.Context, id types.ID, serverID string) error {
142 return fmt.Errorf("not supported")
143 }
144
145 func (o *CertificateAuthorityOp) RevokeServer(ctx context.Context, id types.ID, serverID string) error {
146 return fmt.Errorf("not supported")
147 }
148
149 func (o *CertificateAuthorityOp) AddClient(ctx context.Context, id types.ID, param *iaas.CertificateAuthorityAddClientParam) (*iaas.CertificateAuthorityAddClientOrServerResult, error) {
150 return nil, fmt.Errorf("not supported")
151 }
152
153 func (o *CertificateAuthorityOp) AddServer(ctx context.Context, id types.ID, param *iaas.CertificateAuthorityAddServerParam) (*iaas.CertificateAuthorityAddClientOrServerResult, error) {
154 return nil, fmt.Errorf("not supported")
155 }
156