forked from ajones/terraform-provider-bitbucketserver
-
Notifications
You must be signed in to change notification settings - Fork 0
/
data_application_properties.go
71 lines (59 loc) · 1.62 KB
/
data_application_properties.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
package bitbucket
import (
"encoding/json"
"github.com/hashicorp/terraform/helper/schema"
"io/ioutil"
)
type ApplicationProperties struct {
Version string `json:"version,omitempty"`
BuildNumber string `json:"buildNumber,omitempty"`
BuildDate string `json:"buildDate,omitempty"`
DisplayName string `json:"displayName,omitempty"`
}
func dataSourceApplicationProperties() *schema.Resource {
return &schema.Resource{
Read: dataSourceApplicationPropertiesRead,
Schema: map[string]*schema.Schema{
"version": {
Type: schema.TypeString,
Computed: true,
},
"build_number": {
Type: schema.TypeString,
Computed: true,
},
"build_date": {
Type: schema.TypeString,
Computed: true,
},
"display_name": {
Type: schema.TypeString,
Computed: true,
},
},
}
}
func dataSourceApplicationPropertiesRead(d *schema.ResourceData, m interface{}) error {
client := m.(*BitbucketServerProvider).BitbucketClient
req, err := client.Get("/rest/api/1.0/application-properties")
if err != nil {
return err
}
if req.StatusCode == 200 {
var applicationProperties ApplicationProperties
body, readerr := ioutil.ReadAll(req.Body)
if readerr != nil {
return readerr
}
decodeerr := json.Unmarshal(body, &applicationProperties)
if decodeerr != nil {
return decodeerr
}
d.SetId(applicationProperties.Version)
_ = d.Set("version", applicationProperties.Version)
_ = d.Set("build_number", applicationProperties.BuildNumber)
_ = d.Set("build_date", applicationProperties.BuildDate)
_ = d.Set("display_name", applicationProperties.DisplayName)
}
return nil
}