mirror of
https://github.com/ysoftdevs/terraform-provider-bitbucketserver.git
synced 2026-04-17 06:19:39 +02:00
Added data.bitbucketserver_application_properties
This commit is contained in:
71
bitbucket/data_application_properties.go
Normal file
71
bitbucket/data_application_properties.go
Normal file
@@ -0,0 +1,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.(*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
|
||||
}
|
||||
Reference in New Issue
Block a user