kable

package
v0.0.5 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 11, 2021 License: MIT Imports: 12 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ConcepRepoDataSchema = map[string]*schema.Schema{
	"name": {
		Type:     schema.TypeString,
		Required: true,
	},
	"url": {
		Type:     schema.TypeString,
		Required: true,
	},
	"ref": {
		Type:     schema.TypeString,
		Optional: true,
	},
	"username": {
		Type:     schema.TypeString,
		Optional: true,
	},
	"password": {
		Type:      schema.TypeString,
		Optional:  true,
		Sensitive: true,
	},
}
View Source
var ConceptDataSource = func() *schema.Resource {
	out := schema.Resource{
		Schema: map[string]*schema.Schema{
			"repo": {
				Type: schema.TypeSet,
				Elem: &schema.Resource{
					Schema: ConcepRepoDataSchema,
				},
				Optional:    true,
				Description: "The repository to get the resource from",
			},
			"id": {
				Type:        schema.TypeString,
				Required:    true,
				Description: "The concept identifier.",
			},
			"inputs": {
				Type:        schema.TypeSet,
				Required:    true,
				Description: "The key/value list of inputs to use.",
				Elem: &schema.Resource{
					Schema: map[string]*schema.Schema{
						"name": {
							Type:     schema.TypeString,
							Required: true,
						},
						"value": {
							Type:     schema.TypeString,
							Required: true,
						},
					},
				},
			}, "sensitive_inputs": {
				Type:        schema.TypeSet,
				Required:    true,
				Description: "The key/value list of sensitive inputs to use.",
				Elem: &schema.Resource{
					Schema: map[string]*schema.Schema{
						"name": {
							Type:     schema.TypeString,
							Required: true,
						},
						"value": {
							Type:      schema.TypeString,
							Required:  true,
							Sensitive: true,
						},
					},
				},
			},
			"target_type": {
				Type:        schema.TypeString,
				Optional:    true,
				Default:     "yaml",
				Description: "The type of the rendered output. (defaults to 'yaml')",
			},
			"rendered": {
				Type:     schema.TypeString,
				Computed: true,

				Description: "The rendered output of the concept.",
			},
		},
		ReadContext: ConceptRead,
		Description: "The concept data source allows for rendering a concept from a repository",
	}

	return &out
}
View Source
var ConceptRead = func(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics {
	conceptPath := d.Get("id").(string)
	targetType := d.Get("target_type").(string)

	var mods []repositories.RegistryModification

	for _, repo := range d.Get("repo").(*schema.Set).List() {
		rmap := repo.(map[string]interface{})
		name := rmap["name"].(string)
		url := rmap["url"].(string)
		ref := rmap["ref"].(string)
		r := repositories.Repository{
			Name: name,
			GitRepository: repositories.GitRepository{
				URL: url,
			},
		}
		if ref != "" {
			r.GitRef = ref
		}
		addRepoMod, err := repositories.AddRepository(r)
		if err != nil {
			return diag.FromErr(err)
		}
		mods = append(mods, addRepoMod)

		user := rmap["username"].(string)
		pass := rmap["password"].(string)
		if user != "" && pass != "" {
			authmod, err := repositories.StoreRepoAuth(url, repositories.AuthPair{Username: user, Password: pass})
			if err != nil {
				return diag.FromErr(err)
			}
			mods = append(mods, authmod)
		}
	}

	if err := repositories.UpdateRegistry(mods...); err != nil {
		return diag.FromErr(err)
	}

	conceptIdentifier := concepts.ConceptIdentifier(conceptPath)
	avs, err := assertValues(d)
	if err != nil {
		return diag.FromErr(err)
	}

	if err := renderConcept(d, conceptIdentifier.String(), avs, targetType, false); err != nil {
		return diag.FromErr(err)
	}

	return nil
}
View Source
var LocalConceptDataSource = func() *schema.Resource {
	return &schema.Resource{
		ReadContext: LocalConceptRead,
		Schema: map[string]*schema.Schema{
			"path": {
				Type:        schema.TypeString,
				Required:    true,
				Description: "The path to the concept directory.",
			},
			"inputs": {
				Type:        schema.TypeSet,
				Required:    true,
				Description: "The key/value list of inputs to use.",
				Elem: &schema.Resource{
					Schema: map[string]*schema.Schema{
						"name": {
							Type:     schema.TypeString,
							Required: true,
						},
						"value": {
							Type:     schema.TypeString,
							Required: true,
						},
					},
				},
			}, "sensitive_inputs": {
				Type:        schema.TypeSet,
				Required:    true,
				Description: "The key/value list of sensitive inputs to use.",
				Elem: &schema.Resource{
					Schema: map[string]*schema.Schema{
						"name": {
							Type:     schema.TypeString,
							Required: true,
						},
						"value": {
							Type:      schema.TypeString,
							Required:  true,
							Sensitive: true,
						},
					},
				},
			},
			"target_type": {
				Type:        schema.TypeString,
				Optional:    true,
				Default:     "yaml",
				Description: "The type of the rendered output. (defaults to 'yaml')",
			},
			"rendered": {
				Type:     schema.TypeString,
				Computed: true,

				Description: "The rendered output of the concept.",
			},
		},
		Description: "The concept data source allows for rendering a concept from a repository",
	}
}
View Source
var LocalConceptRead = func(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics {

	wd, err := os.Getwd()
	if err != nil {
		return diag.FromErr(err)
	}
	conceptPath := filepath.Join(wd, d.Get("path").(string))
	targetType := d.Get("target_type").(string)

	avs, err := assertValues(d)
	if err != nil {
		return diag.FromErr(err)
	}

	if err := renderConcept(d, conceptPath, avs, targetType, true); err != nil {
		return diag.FromErr(err)
	}

	return nil
}
View Source
var Provider = func() *schema.Provider {
	return &schema.Provider{
		DataSourcesMap: map[string]*schema.Resource{
			"kable_concept":       ConceptDataSource(),
			"kable_local_concept": LocalConceptDataSource(),
		},
	}
}

Functions

This section is empty.

Types

This section is empty.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL