| 
 | 1 | +package sysdig  | 
 | 2 | + | 
 | 3 | +import (  | 
 | 4 | +	"context"  | 
 | 5 | +	"crypto/sha256"  | 
 | 6 | +	"fmt"  | 
 | 7 | +	"github.com/hashicorp/terraform-plugin-sdk/v2/diag"  | 
 | 8 | +	"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"  | 
 | 9 | +)  | 
 | 10 | + | 
 | 11 | +func dataSourceSysdigSecureConnection() *schema.Resource {  | 
 | 12 | + | 
 | 13 | +	return &schema.Resource{  | 
 | 14 | +		ReadContext: dataSourceSecureConnectionRead,  | 
 | 15 | +		Schema: map[string]*schema.Schema{  | 
 | 16 | +			"secure_url": {  | 
 | 17 | +				Type:        schema.TypeString,  | 
 | 18 | +				Computed:    true,  | 
 | 19 | +				Description: "Sysdig Secure URL basepath to where backend requests will be sent",  | 
 | 20 | +			},  | 
 | 21 | +			"secure_api_token": {  | 
 | 22 | +				Type:        schema.TypeString,  | 
 | 23 | +				Computed:    true,  | 
 | 24 | +				Sensitive:   true,  | 
 | 25 | +				Description: "Sysdig Secure authentication api token",  | 
 | 26 | +			},  | 
 | 27 | +		},  | 
 | 28 | +	}  | 
 | 29 | +}  | 
 | 30 | + | 
 | 31 | +func dataSourceSecureConnectionRead(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics {  | 
 | 32 | + | 
 | 33 | +	endpoint, err := meta.(SysdigClients).GetSecureEndpoint()  | 
 | 34 | +	if err != nil {  | 
 | 35 | +		return diag.FromErr(err)  | 
 | 36 | +	}  | 
 | 37 | + | 
 | 38 | +	apiToken, err := meta.(SysdigClients).GetSecureApiToken()  | 
 | 39 | +	if err != nil {  | 
 | 40 | +		return diag.FromErr(err)  | 
 | 41 | +	}  | 
 | 42 | + | 
 | 43 | +	d.SetId(fmt.Sprintf("%x", sha256.Sum256([]byte(fmt.Sprintf("%s,%s", endpoint, apiToken)))))  | 
 | 44 | + | 
 | 45 | +	err = d.Set("secure_url", endpoint)  | 
 | 46 | +	if err != nil {  | 
 | 47 | +		return diag.FromErr(err)  | 
 | 48 | +	}  | 
 | 49 | + | 
 | 50 | +	err = d.Set("secure_api_token", apiToken)  | 
 | 51 | +	if err != nil {  | 
 | 52 | +		return diag.FromErr(err)  | 
 | 53 | +	}  | 
 | 54 | +	return nil  | 
 | 55 | +}  | 
0 commit comments