/
object_storage_namespace_data_source.go
81 lines (64 loc) · 1.96 KB
/
object_storage_namespace_data_source.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
// Copyright (c) 2017, 2019, Oracle and/or its affiliates. All rights reserved.
package provider
import (
"context"
"github.com/hashicorp/terraform/helper/schema"
oci_object_storage "github.com/oracle/oci-go-sdk/objectstorage"
)
func ObjectStorageNamespaceDataSource() *schema.Resource {
return &schema.Resource{
Read: readSingularObjectStorageNamespace,
Schema: map[string]*schema.Schema{
"compartment_id": {
Type: schema.TypeString,
Optional: true,
},
// Computed
// @CODEGEN 2/2018: No computed values are generated because the generator doesn't know what to do with
// responses that aren't reference types.
// In this case, the response from service is a string so manually add a field for it.
"namespace": {
Type: schema.TypeString,
Computed: true,
},
},
}
}
func readSingularObjectStorageNamespace(d *schema.ResourceData, m interface{}) error {
sync := &ObjectStorageNamespaceDataSourceCrud{}
sync.D = d
sync.Client = m.(*OracleClients).objectStorageClient
return ReadResource(sync)
}
type ObjectStorageNamespaceDataSourceCrud struct {
D *schema.ResourceData
Client *oci_object_storage.ObjectStorageClient
Res *oci_object_storage.GetNamespaceResponse
}
func (s *ObjectStorageNamespaceDataSourceCrud) VoidState() {
s.D.SetId("")
}
func (s *ObjectStorageNamespaceDataSourceCrud) Get() error {
request := oci_object_storage.GetNamespaceRequest{}
if compartmentId, ok := s.D.GetOkExists("compartment_id"); ok {
tmp := compartmentId.(string)
request.CompartmentId = &tmp
}
request.RequestMetadata.RetryPolicy = getRetryPolicy(false, "object_storage")
response, err := s.Client.GetNamespace(context.Background(), request)
if err != nil {
return err
}
s.Res = &response
return nil
}
func (s *ObjectStorageNamespaceDataSourceCrud) SetData() error {
if s.Res == nil {
return nil
}
s.D.SetId(GenerateDataSourceID())
if s.Res.Value != nil {
s.D.Set("namespace", *s.Res.Value)
}
return nil
}