mirror of
https://github.com/ysoftdevs/terraform-provider-bitbucketserver.git
synced 2026-03-26 19:31:07 +01:00
Added license details to data.plugin
This commit is contained in:
@@ -23,6 +23,29 @@ type Plugin struct {
|
||||
} `json:"vendor,omitempty"`
|
||||
}
|
||||
|
||||
type PluginLicense struct {
|
||||
Valid bool `json:"valid,omitempty"`
|
||||
Evaluation bool `json:"evaluation,omitempty"`
|
||||
NearlyExpired bool `json:"nearlyExpired,omitempty"`
|
||||
MaintenanceExpiryDate jsonTime `json:"maintenanceExpiryDate,omitempty"`
|
||||
MaintenanceExpired bool `json:"maintenanceExpired,omitempty"`
|
||||
LicenseType string `json:"licenseType,omitempty"`
|
||||
ExpiryDate jsonTime `json:"expiryDate,omitempty"`
|
||||
RawLicense string `json:"rawLicense,omitempty"`
|
||||
Renewable bool `json:"renewable,omitempty"`
|
||||
OrganizationName string `json:"organizationName,omitempty"`
|
||||
ContactEmail string `json:"contactEmail,omitempty"`
|
||||
Enterprise bool `json:"enterprise,omitempty"`
|
||||
DataCenter bool `json:"dataCenter,omitempty"`
|
||||
Subscription bool `json:"subscription,omitempty"`
|
||||
Active bool `json:"active,omitempty"`
|
||||
AutoRenewal bool `json:"autoRenewal,omitempty"`
|
||||
Upgradable bool `json:"upgradable,omitempty"`
|
||||
Crossgradeable bool `json:"crossgradeable,omitempty"`
|
||||
PurchasePastServerCutoffDate bool `json:"purchasePastServerCutoffDate,omitempty"`
|
||||
SupportEntitlementNumber string `json:"supportEntitlementNumber,omitempty"`
|
||||
}
|
||||
|
||||
func dataSourcePlugin() *schema.Resource {
|
||||
return &schema.Resource{
|
||||
Read: dataSourcePluginRead,
|
||||
@@ -60,17 +83,115 @@ func dataSourcePlugin() *schema.Resource {
|
||||
Type: schema.TypeBool,
|
||||
Computed: true,
|
||||
},
|
||||
"vendor_name": {
|
||||
Type: schema.TypeString,
|
||||
"vendor": {
|
||||
Type: schema.TypeMap,
|
||||
Computed: true,
|
||||
Elem: &schema.Resource{
|
||||
Schema: map[string]*schema.Schema{
|
||||
"name": {
|
||||
Type: schema.TypeString,
|
||||
Computed: true,
|
||||
},
|
||||
"link": {
|
||||
Type: schema.TypeString,
|
||||
Computed: true,
|
||||
},
|
||||
"marketplace_link": {
|
||||
Type: schema.TypeString,
|
||||
Computed: true,
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
"vendor_link": {
|
||||
Type: schema.TypeString,
|
||||
Computed: true,
|
||||
},
|
||||
"vendor_marketplace_link": {
|
||||
Type: schema.TypeString,
|
||||
"license": {
|
||||
Type: schema.TypeList,
|
||||
Computed: true,
|
||||
MaxItems: 1,
|
||||
Elem: &schema.Resource{
|
||||
Schema: map[string]*schema.Schema{
|
||||
"valid": {
|
||||
Type: schema.TypeBool,
|
||||
Computed: true,
|
||||
},
|
||||
"evaluation": {
|
||||
Type: schema.TypeBool,
|
||||
Computed: true,
|
||||
},
|
||||
"nearly_expired": {
|
||||
Type: schema.TypeBool,
|
||||
Computed: true,
|
||||
},
|
||||
"maintenance_expiry_date": {
|
||||
Type: schema.TypeString,
|
||||
Computed: true,
|
||||
},
|
||||
"maintenance_expired": {
|
||||
Type: schema.TypeBool,
|
||||
Computed: true,
|
||||
},
|
||||
"license_type": {
|
||||
Type: schema.TypeString,
|
||||
Computed: true,
|
||||
},
|
||||
"expiry_date": {
|
||||
Type: schema.TypeString,
|
||||
Computed: true,
|
||||
},
|
||||
"raw_license": {
|
||||
Type: schema.TypeString,
|
||||
Computed: true,
|
||||
Sensitive: true,
|
||||
},
|
||||
"renewable": {
|
||||
Type: schema.TypeBool,
|
||||
Computed: true,
|
||||
},
|
||||
"organization_name": {
|
||||
Type: schema.TypeString,
|
||||
Computed: true,
|
||||
},
|
||||
"contact_email": {
|
||||
Type: schema.TypeString,
|
||||
Computed: true,
|
||||
},
|
||||
"enterprise": {
|
||||
Type: schema.TypeBool,
|
||||
Computed: true,
|
||||
},
|
||||
"data_center": {
|
||||
Type: schema.TypeBool,
|
||||
Computed: true,
|
||||
},
|
||||
"subscription": {
|
||||
Type: schema.TypeBool,
|
||||
Computed: true,
|
||||
},
|
||||
"active": {
|
||||
Type: schema.TypeBool,
|
||||
Computed: true,
|
||||
},
|
||||
"auto_renewal": {
|
||||
Type: schema.TypeBool,
|
||||
Computed: true,
|
||||
},
|
||||
"upgradable": {
|
||||
Type: schema.TypeBool,
|
||||
Computed: true,
|
||||
},
|
||||
"crossgradeable": {
|
||||
Type: schema.TypeBool,
|
||||
Computed: true,
|
||||
},
|
||||
"purchase_past_server_cutoff_date": {
|
||||
Type: schema.TypeBool,
|
||||
Computed: true,
|
||||
},
|
||||
"support_entitlement_number": {
|
||||
Type: schema.TypeString,
|
||||
Computed: true,
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
}
|
||||
@@ -83,32 +204,76 @@ func dataSourcePluginRead(d *schema.ResourceData, m interface{}) error {
|
||||
return err
|
||||
}
|
||||
|
||||
if req.StatusCode == 200 {
|
||||
var plugin Plugin
|
||||
|
||||
var plugin Plugin
|
||||
|
||||
body, readErr := ioutil.ReadAll(req.Body)
|
||||
if readErr != nil {
|
||||
return readErr
|
||||
}
|
||||
|
||||
decodeErr := json.Unmarshal(body, &plugin)
|
||||
if decodeErr != nil {
|
||||
return decodeErr
|
||||
}
|
||||
|
||||
d.SetId(plugin.Key)
|
||||
_ = d.Set("enabled", plugin.Enabled)
|
||||
_ = d.Set("enabled_by_default", plugin.EnabledByDefault)
|
||||
_ = d.Set("version", plugin.Version)
|
||||
_ = d.Set("description", plugin.Description)
|
||||
_ = d.Set("name", plugin.Name)
|
||||
_ = d.Set("user_installed", plugin.UserInstalled)
|
||||
_ = d.Set("optional", plugin.Optional)
|
||||
_ = d.Set("vendor_name", plugin.Vendor.Name)
|
||||
_ = d.Set("vendor_link", plugin.Vendor.Link)
|
||||
_ = d.Set("vendor_marketplace_link", plugin.Vendor.MarketplaceLink)
|
||||
body, readErr := ioutil.ReadAll(req.Body)
|
||||
if readErr != nil {
|
||||
return readErr
|
||||
}
|
||||
|
||||
decodeErr := json.Unmarshal(body, &plugin)
|
||||
if decodeErr != nil {
|
||||
return decodeErr
|
||||
}
|
||||
|
||||
d.SetId(plugin.Key)
|
||||
_ = d.Set("enabled", plugin.Enabled)
|
||||
_ = d.Set("enabled_by_default", plugin.EnabledByDefault)
|
||||
_ = d.Set("version", plugin.Version)
|
||||
_ = d.Set("description", plugin.Description)
|
||||
_ = d.Set("name", plugin.Name)
|
||||
_ = d.Set("user_installed", plugin.UserInstalled)
|
||||
_ = d.Set("optional", plugin.Optional)
|
||||
|
||||
vendor := map[string]string{
|
||||
"name": plugin.Vendor.Name,
|
||||
"link": plugin.Vendor.Link,
|
||||
"marketplace_link": plugin.Vendor.MarketplaceLink,
|
||||
}
|
||||
_ = d.Set("vendor", vendor)
|
||||
|
||||
// Hit the license API to get license details
|
||||
|
||||
req, err = client.Get(fmt.Sprintf("/rest/plugins/1.0/%s-key/license", d.Get("key").(string)))
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
var pluginLicense PluginLicense
|
||||
|
||||
body, readErr = ioutil.ReadAll(req.Body)
|
||||
if readErr != nil {
|
||||
return readErr
|
||||
}
|
||||
|
||||
decodeErr = json.Unmarshal(body, &pluginLicense)
|
||||
if decodeErr != nil {
|
||||
return decodeErr
|
||||
}
|
||||
|
||||
license := [1]map[string]interface{}{{
|
||||
"valid": pluginLicense.Valid,
|
||||
"evaluation": pluginLicense.Evaluation,
|
||||
"nearly_expired": pluginLicense.NearlyExpired,
|
||||
"maintenance_expiry_date": pluginLicense.MaintenanceExpiryDate.String(),
|
||||
"maintenance_expired": pluginLicense.MaintenanceExpired,
|
||||
"license_type": pluginLicense.LicenseType,
|
||||
"expiry_date": pluginLicense.ExpiryDate.String(),
|
||||
"raw_license": pluginLicense.RawLicense,
|
||||
"renewable": pluginLicense.Renewable,
|
||||
"organization_name": pluginLicense.OrganizationName,
|
||||
"contact_email": pluginLicense.ContactEmail,
|
||||
"enterprise": pluginLicense.Enterprise,
|
||||
"data_center": pluginLicense.DataCenter,
|
||||
"subscription": pluginLicense.Subscription,
|
||||
"active": pluginLicense.Active,
|
||||
"auto_renewal": pluginLicense.AutoRenewal,
|
||||
"upgradable": pluginLicense.Upgradable,
|
||||
"crossgradeable": pluginLicense.Crossgradeable,
|
||||
"purchase_past_server_cutoff_date": pluginLicense.PurchasePastServerCutoffDate,
|
||||
"support_entitlement_number": pluginLicense.SupportEntitlementNumber,
|
||||
}}
|
||||
_ = d.Set("license", license)
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
@@ -6,7 +6,56 @@ import (
|
||||
"github.com/hashicorp/terraform/helper/resource"
|
||||
)
|
||||
|
||||
func TestAccBitbucketDataPlugin(t *testing.T) {
|
||||
func TestAccBitbucketDataPlugin_notifyer(t *testing.T) {
|
||||
config := `
|
||||
data "bitbucketserver_plugin" "test" {
|
||||
key = "nl.stefankohler.stash.stash-notification-plugin"
|
||||
}
|
||||
`
|
||||
|
||||
resource.Test(t, resource.TestCase{
|
||||
PreCheck: func() { testAccPreCheck(t) },
|
||||
Providers: testAccProviders,
|
||||
Steps: []resource.TestStep{
|
||||
{
|
||||
Config: config,
|
||||
Check: resource.ComposeTestCheckFunc(
|
||||
resource.TestCheckResourceAttr("data.bitbucketserver_plugin.test", "key", "nl.stefankohler.stash.stash-notification-plugin"),
|
||||
resource.TestCheckResourceAttr("data.bitbucketserver_plugin.test", "enabled", "true"),
|
||||
resource.TestCheckResourceAttr("data.bitbucketserver_plugin.test", "enabled_by_default", "true"),
|
||||
resource.TestCheckResourceAttrSet("data.bitbucketserver_plugin.test", "version"),
|
||||
resource.TestCheckResourceAttr("data.bitbucketserver_plugin.test", "name", "Notifyr - Notification for Bitbucket"),
|
||||
resource.TestCheckResourceAttr("data.bitbucketserver_plugin.test", "description", "Watch your repositories, branches, and tags and receive email notifications on changes."),
|
||||
resource.TestCheckResourceAttr("data.bitbucketserver_plugin.test", "user_installed", "true"),
|
||||
resource.TestCheckResourceAttr("data.bitbucketserver_plugin.test", "optional", "true"),
|
||||
resource.TestCheckResourceAttr("data.bitbucketserver_plugin.test", "vendor.name", "ASK Software"),
|
||||
resource.TestCheckResourceAttr("data.bitbucketserver_plugin.test", "vendor.link", "http://www.stefankohler.nl/"),
|
||||
resource.TestCheckResourceAttr("data.bitbucketserver_plugin.test", "vendor.marketplace_link", "http://www.stefankohler.nl/"),
|
||||
resource.TestCheckResourceAttr("data.bitbucketserver_plugin.test", "license.0.valid", "true"),
|
||||
resource.TestCheckResourceAttr("data.bitbucketserver_plugin.test", "license.0.evaluation", "true"),
|
||||
resource.TestCheckResourceAttr("data.bitbucketserver_plugin.test", "license.0.nearly_expired", "true"),
|
||||
resource.TestCheckResourceAttrSet("data.bitbucketserver_plugin.test", "license.0.maintenance_expiry_date"),
|
||||
resource.TestCheckResourceAttr("data.bitbucketserver_plugin.test", "license.0.maintenance_expired", "false"),
|
||||
resource.TestCheckResourceAttr("data.bitbucketserver_plugin.test", "license.0.license_type", "DEVELOPER"),
|
||||
resource.TestCheckResourceAttrSet("data.bitbucketserver_plugin.test", "license.0.expiry_date"),
|
||||
resource.TestCheckResourceAttr("data.bitbucketserver_plugin.test", "license.0.raw_license", "AAABCA0ODAoPeNpdj01PwkAURffzKyZxZ1IyUzARkllQ24gRaQMtGnaP8VEmtjPNfFT59yJVFyzfubkn796Ux0Bz6SmbUM5nbDzj97RISxozHpMUnbSq88poUaLztFEStUN6MJZ2TaiVpu/YY2M6tI6sQrtHmx8qd74EZ+TBIvyUU/AoYs7jiE0jzknWQxMuifA2IBlUbnQ7AulVjwN9AaU9atASs69O2dNFU4wXJLc1aOUGw9w34JwCTTZoe7RPqUgep2X0Vm0n0fNut4gSxl/Jcnj9nFb6Q5tP/Ueu3L+0PHW4ghZFmm2zZV5k6/95CbR7Y9bYGo/zGrV3Ir4jRbDyCA6vt34DO8p3SDAsAhQnJjLD5k9Fr3uaIzkXKf83o5vDdQIUe4XequNCC3D+9ht9ZYhNZFKmnhc=X02dh"),
|
||||
resource.TestCheckResourceAttr("data.bitbucketserver_plugin.test", "license.0.renewable", "false"),
|
||||
resource.TestCheckResourceAttr("data.bitbucketserver_plugin.test", "license.0.organization_name", "Atlassian"),
|
||||
resource.TestCheckResourceAttr("data.bitbucketserver_plugin.test", "license.0.enterprise", "false"),
|
||||
resource.TestCheckResourceAttr("data.bitbucketserver_plugin.test", "license.0.data_center", "false"),
|
||||
resource.TestCheckResourceAttr("data.bitbucketserver_plugin.test", "license.0.subscription", "false"),
|
||||
resource.TestCheckResourceAttr("data.bitbucketserver_plugin.test", "license.0.active", "true"),
|
||||
resource.TestCheckResourceAttr("data.bitbucketserver_plugin.test", "license.0.auto_renewal", "false"),
|
||||
resource.TestCheckResourceAttr("data.bitbucketserver_plugin.test", "license.0.upgradable", "false"),
|
||||
resource.TestCheckResourceAttr("data.bitbucketserver_plugin.test", "license.0.crossgradeable", "false"),
|
||||
resource.TestCheckResourceAttr("data.bitbucketserver_plugin.test", "license.0.purchase_past_server_cutoff_date", "true"),
|
||||
),
|
||||
},
|
||||
},
|
||||
})
|
||||
}
|
||||
|
||||
func TestAccBitbucketDataPlugin_upm(t *testing.T) {
|
||||
config := `
|
||||
data "bitbucketserver_plugin" "upm" {
|
||||
key = "com.atlassian.upm.atlassian-universal-plugin-manager-plugin"
|
||||
@@ -28,9 +77,11 @@ func TestAccBitbucketDataPlugin(t *testing.T) {
|
||||
resource.TestCheckResourceAttr("data.bitbucketserver_plugin.upm", "description", "This is the plugin that provides the Atlassian Universal Plugin Manager."),
|
||||
resource.TestCheckResourceAttr("data.bitbucketserver_plugin.upm", "user_installed", "false"),
|
||||
resource.TestCheckResourceAttr("data.bitbucketserver_plugin.upm", "optional", "false"),
|
||||
resource.TestCheckResourceAttr("data.bitbucketserver_plugin.upm", "vendor_name", "Atlassian"),
|
||||
resource.TestCheckResourceAttr("data.bitbucketserver_plugin.upm", "vendor_link", "http://www.atlassian.com"),
|
||||
resource.TestCheckResourceAttr("data.bitbucketserver_plugin.upm", "vendor_marketplace_link", "http://www.atlassian.com"),
|
||||
resource.TestCheckResourceAttr("data.bitbucketserver_plugin.upm", "vendor.name", "Atlassian"),
|
||||
resource.TestCheckResourceAttr("data.bitbucketserver_plugin.upm", "vendor.link", "http://www.atlassian.com"),
|
||||
resource.TestCheckResourceAttr("data.bitbucketserver_plugin.upm", "vendor.marketplace_link", "http://www.atlassian.com"),
|
||||
resource.TestCheckResourceAttr("data.bitbucketserver_plugin.upm", "license.0.valid", "false"),
|
||||
resource.TestCheckResourceAttr("data.bitbucketserver_plugin.upm", "license.0.active", "false"),
|
||||
),
|
||||
},
|
||||
},
|
||||
|
||||
Reference in New Issue
Block a user