mirror of
https://github.com/ysoftdevs/terraform-provider-bitbucketserver.git
synced 2026-04-01 06:53:07 +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
|
||||
}
|
||||
29
bitbucket/data_application_properties_test.go
Normal file
29
bitbucket/data_application_properties_test.go
Normal file
@@ -0,0 +1,29 @@
|
||||
package bitbucket
|
||||
|
||||
import (
|
||||
"testing"
|
||||
|
||||
"github.com/hashicorp/terraform/helper/resource"
|
||||
)
|
||||
|
||||
func TestAccBitbucketDataApplicationProperties(t *testing.T) {
|
||||
config := `
|
||||
data "bitbucketserver_application_properties" "main" {}
|
||||
`
|
||||
|
||||
resource.Test(t, resource.TestCase{
|
||||
PreCheck: func() { testAccPreCheck(t) },
|
||||
Providers: testAccProviders,
|
||||
Steps: []resource.TestStep{
|
||||
{
|
||||
Config: config,
|
||||
Check: resource.ComposeTestCheckFunc(
|
||||
resource.TestCheckResourceAttr("data.bitbucketserver_application_properties.main", "version", "6.7.0"),
|
||||
resource.TestCheckResourceAttr("data.bitbucketserver_application_properties.main", "build_number", "6007000"),
|
||||
resource.TestCheckResourceAttr("data.bitbucketserver_application_properties.main", "build_date", "1569809627115"),
|
||||
resource.TestCheckResourceAttr("data.bitbucketserver_application_properties.main", "display_name", "Bitbucket"),
|
||||
),
|
||||
},
|
||||
},
|
||||
})
|
||||
}
|
||||
@@ -28,6 +28,9 @@ func Provider() terraform.ResourceProvider {
|
||||
},
|
||||
},
|
||||
ConfigureFunc: providerConfigure,
|
||||
DataSourcesMap: map[string]*schema.Resource{
|
||||
"bitbucketserver_application_properties": dataSourceApplicationProperties(),
|
||||
},
|
||||
ResourcesMap: map[string]*schema.Resource{
|
||||
"bitbucketserver_admin_license": resourceAdminLicense(),
|
||||
"bitbucketserver_admin_mail_server": resourceAdminMailServer(),
|
||||
|
||||
Reference in New Issue
Block a user