/
identity_authentication_policy_data_source.go
72 lines (55 loc) · 1.84 KB
/
identity_authentication_policy_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
// Copyright (c) 2017, 2019, Oracle and/or its affiliates. All rights reserved.
package provider
import (
"context"
"github.com/hashicorp/terraform/helper/schema"
oci_identity "github.com/oracle/oci-go-sdk/identity"
)
func IdentityAuthenticationPolicyDataSource() *schema.Resource {
fieldMap := make(map[string]*schema.Schema)
fieldMap["compartment_id"] = &schema.Schema{
Type: schema.TypeString,
Required: true,
}
return GetSingularDataSourceItemSchema(IdentityAuthenticationPolicyResource(), fieldMap, readSingularIdentityAuthenticationPolicy)
}
func readSingularIdentityAuthenticationPolicy(d *schema.ResourceData, m interface{}) error {
sync := &IdentityAuthenticationPolicyDataSourceCrud{}
sync.D = d
sync.Client = m.(*OracleClients).identityClient
return ReadResource(sync)
}
type IdentityAuthenticationPolicyDataSourceCrud struct {
D *schema.ResourceData
Client *oci_identity.IdentityClient
Res *oci_identity.GetAuthenticationPolicyResponse
}
func (s *IdentityAuthenticationPolicyDataSourceCrud) VoidState() {
s.D.SetId("")
}
func (s *IdentityAuthenticationPolicyDataSourceCrud) Get() error {
request := oci_identity.GetAuthenticationPolicyRequest{}
if compartmentId, ok := s.D.GetOkExists("compartment_id"); ok {
tmp := compartmentId.(string)
request.CompartmentId = &tmp
}
request.RequestMetadata.RetryPolicy = getRetryPolicy(false, "identity")
response, err := s.Client.GetAuthenticationPolicy(context.Background(), request)
if err != nil {
return err
}
s.Res = &response
return nil
}
func (s *IdentityAuthenticationPolicyDataSourceCrud) SetData() error {
if s.Res == nil {
return nil
}
s.D.SetId(GenerateDataSourceID())
if s.Res.PasswordPolicy != nil {
s.D.Set("password_policy", []interface{}{PasswordPolicyToMap(s.Res.PasswordPolicy)})
} else {
s.D.Set("password_policy", nil)
}
return nil
}