Added resource.bitbucketserver_plugin

This commit is contained in:
Gavin Bunney
2019-10-14 11:38:39 -07:00
parent 78aafda47e
commit 6d0d523a9b
35 changed files with 967 additions and 246 deletions

View File

@@ -1,51 +1,9 @@
package bitbucket
import (
"encoding/json"
"fmt"
"github.com/hashicorp/terraform/helper/schema"
"io/ioutil"
)
type Plugin struct {
Key string `json:"key,omitempty"`
Enabled bool `json:"enabled,omitempty"`
EnabledByDefault bool `json:"enabledByDefault,omitempty"`
Version string `json:"version,omitempty"`
Description string `json:"description,omitempty"`
Name string `json:"name,omitempty"`
UserInstalled bool `json:"userInstalled,omitempty"`
Optional bool `json:"optional,omitempty"`
Vendor struct {
Name string `json:"name,omitempty"`
MarketplaceLink string `json:"marketplaceLink,omitempty"`
Link string `json:"link,omitempty"`
} `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,
@@ -103,7 +61,7 @@ func dataSourcePlugin() *schema.Resource {
},
},
},
"license": {
"applied_license": {
Type: schema.TypeList,
Computed: true,
MaxItems: 1,
@@ -198,82 +156,6 @@ func dataSourcePlugin() *schema.Resource {
}
func dataSourcePluginRead(d *schema.ResourceData, m interface{}) error {
client := m.(*BitbucketClient)
req, err := client.Get(fmt.Sprintf("/rest/plugins/1.0/%s-key", d.Get("key").(string)))
if err != nil {
return err
}
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)
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
d.SetId(d.Get("key").(string))
return resourcePluginRead(d, m)
}