From 4f76d3a556b26a67c4e5fe735bd8a3f9f3c60dde Mon Sep 17 00:00:00 2001 From: James Bardin Date: Wed, 25 Oct 2017 15:27:29 -0400 Subject: [PATCH] remove models dependency from the regresp That isn't needed by terraform, and can be left in a registry package. --- registry/response/module.go | 100 ------------------------------------ 1 file changed, 100 deletions(-) diff --git a/registry/response/module.go b/registry/response/module.go index e3d47094b..3bd2b3df2 100644 --- a/registry/response/module.go +++ b/registry/response/module.go @@ -1,10 +1,7 @@ package response import ( - "fmt" "time" - - "github.com/hashicorp/terraform-registry/api/models" ) // Module is the response structure with the data for a single module version. @@ -94,100 +91,3 @@ type ModuleResource struct { Name string `json:"name"` Type string `json:"type"` } - -// NewModule creates a Module response object from a model. -func NewModule(mv *models.ModuleVersion) *Module { - m := mv.ModuleProvider.Module - mp := mv.ModuleProvider - - // Build the full module - return &Module{ - ID: fmt.Sprintf( - "%s/%s/%s/%s", - m.Namespace, - m.Name, - mp.Provider, - mv.Version), - - // Base metadata - Owner: m.User.Username, - Namespace: m.Namespace, - Name: m.Name, - Version: mv.Version, - Provider: mv.ModuleProvider.Provider, - Description: mv.Description, - Source: mp.Source, - PublishedAt: mv.PublishedAt, - Downloads: int(mp.Downloads), - Verified: m.Verified, - } -} - -// NewModuleDetail creates a ModuleDetail response object from a model. -func NewModuleDetail(mv *models.ModuleVersion) *ModuleDetail { - m := NewModule(mv) - - // Build the submodule response objects - var submodules []*ModuleSubmodule - var submoduleRoot *ModuleSubmodule - for _, sub := range mv.Submodules { - resp := NewModuleSubmodule(&sub) - - if sub.Root() { - submoduleRoot = resp - } else { - submodules = append(submodules, resp) - } - } - return &ModuleDetail{ - Module: *m, - Root: submoduleRoot, - Submodules: submodules, - } -} - -// NewModuleSubmodule creates a ModuleSubmodule response object from a model. -func NewModuleSubmodule(m *models.ModuleSubmodule) *ModuleSubmodule { - inputs := make([]*ModuleInput, 0, len(m.Variables)) - for _, v := range m.Variables { - inputs = append(inputs, &ModuleInput{ - Name: v.Name, - Description: v.Description.String, - Default: v.Default.String, - }) - } - - outputs := make([]*ModuleOutput, 0, len(m.Outputs)) - for _, v := range m.Outputs { - outputs = append(outputs, &ModuleOutput{ - Name: v.Name, - Description: v.Description.String, - }) - } - - deps := make([]*ModuleDep, 0, len(m.Dependencies)) - for _, v := range m.Dependencies { - deps = append(deps, &ModuleDep{ - Name: v.Name, - Source: v.Source, - }) - } - - resources := make([]*ModuleResource, 0, len(m.Resources)) - for _, v := range m.Resources { - resources = append(resources, &ModuleResource{ - Name: v.Name, - Type: v.Type, - }) - } - - return &ModuleSubmodule{ - Path: m.Path, - Readme: m.Readme, - Empty: m.Empty, - Inputs: inputs, - Outputs: outputs, - Dependencies: deps, - Resources: resources, - } -}