forked from hashicorp/terraform-provider-azurerm
-
Notifications
You must be signed in to change notification settings - Fork 0
/
source_control_token_data_source.go
86 lines (71 loc) · 2.38 KB
/
source_control_token_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
82
83
84
85
86
package appservice
import (
"context"
"fmt"
"time"
"github.com/kevinklinger/terraform-provider-azurerm/v2/internal/sdk"
"github.com/kevinklinger/terraform-provider-azurerm/v2/internal/services/appservice/parse"
"github.com/kevinklinger/terraform-provider-azurerm/v2/internal/tf/pluginsdk"
"github.com/kevinklinger/terraform-provider-azurerm/v2/internal/tf/validation"
"github.com/kevinklinger/terraform-provider-azurerm/v2/utils"
)
type AppServiceSourceControlTokenDataSource struct{}
var _ sdk.DataSource = AppServiceSourceControlTokenDataSource{}
func (d AppServiceSourceControlTokenDataSource) Arguments() map[string]*pluginsdk.Schema {
return map[string]*pluginsdk.Schema{
"type": {
Type: pluginsdk.TypeString,
Required: true,
ValidateFunc: validation.StringInSlice([]string{
"Bitbucket",
"Dropbox",
"GitHub",
"OneDrive",
}, false),
},
}
}
func (d AppServiceSourceControlTokenDataSource) Attributes() map[string]*pluginsdk.Schema {
return map[string]*pluginsdk.Schema{
"token": {
Type: pluginsdk.TypeString,
Sensitive: true,
Computed: true,
},
"token_secret": {
Type: pluginsdk.TypeString,
Sensitive: true,
Computed: true,
},
}
}
func (d AppServiceSourceControlTokenDataSource) ModelObject() interface{} {
return &AppServiceSourceControlTokenModel{}
}
func (d AppServiceSourceControlTokenDataSource) ResourceType() string {
return "azurerm_source_control_token"
}
func (d AppServiceSourceControlTokenDataSource) Read() sdk.ResourceFunc {
return sdk.ResourceFunc{
Timeout: 5 * time.Minute,
Func: func(ctx context.Context, metadata sdk.ResourceMetaData) error {
client := metadata.Client.AppService.BaseClient
var sourceControlToken AppServiceSourceControlTokenModel
if err := metadata.Decode(&sourceControlToken); err != nil {
return fmt.Errorf("decoding %+v", err)
}
id := parse.NewAppServiceSourceControlTokenID(sourceControlToken.Type)
resp, err := client.GetSourceControl(ctx, id.Type)
if err != nil {
return fmt.Errorf("reading %s: %+v", id, err)
}
if resp.SourceControlProperties == nil {
return fmt.Errorf("reading properties of %s", id)
}
sourceControlToken.Token = utils.NormalizeNilableString(resp.Token)
sourceControlToken.TokenSecret = utils.NormalizeNilableString(resp.TokenSecret)
metadata.SetID(id)
return metadata.Encode(&sourceControlToken)
},
}
}