-
-
Notifications
You must be signed in to change notification settings - Fork 17
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add ability to load content from folders
- Loading branch information
Showing
6 changed files
with
155 additions
and
60 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
package cmd | ||
|
||
import ( | ||
"errors" | ||
"fmt" | ||
"os" | ||
|
||
"k8s.io/apiextensions-apiserver/pkg/apis/apiextensions/v1beta1" | ||
"k8s.io/apimachinery/pkg/util/yaml" | ||
) | ||
|
||
type FileHandler struct { | ||
location string | ||
} | ||
|
||
func (h *FileHandler) CRDs() ([]*v1beta1.CustomResourceDefinition, error) { | ||
if _, err := os.Stat(h.location); os.IsNotExist(err) { | ||
return nil, fmt.Errorf("file under '%s' does not exist", h.location) | ||
} | ||
content, err := os.ReadFile(h.location) | ||
if err != nil { | ||
return nil, fmt.Errorf("failed to read file: %w", err) | ||
} | ||
|
||
crd := &v1beta1.CustomResourceDefinition{} | ||
if err := yaml.Unmarshal(content, crd); err != nil { | ||
return nil, errors.New("failed to unmarshal into custom resource definition") | ||
} | ||
|
||
return []*v1beta1.CustomResourceDefinition{crd}, nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
package cmd |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
package cmd | ||
|
||
import ( | ||
"errors" | ||
"fmt" | ||
"net/http" | ||
|
||
"github.com/Skarlso/crd-to-sample-yaml/pkg/fetcher" | ||
"k8s.io/apiextensions-apiserver/pkg/apis/apiextensions/v1beta1" | ||
"k8s.io/apimachinery/pkg/util/yaml" | ||
) | ||
|
||
type URLHandler struct { | ||
url string | ||
} | ||
|
||
func (h *URLHandler) CRDs() ([]*v1beta1.CustomResourceDefinition, error) { | ||
f := fetcher.NewFetcher(http.DefaultClient) | ||
content, err := f.Fetch(h.url) | ||
if err != nil { | ||
return nil, fmt.Errorf("failed to fetch content: %w", err) | ||
} | ||
|
||
crd := &v1beta1.CustomResourceDefinition{} | ||
if err := yaml.Unmarshal(content, crd); err != nil { | ||
return nil, errors.New("failed to unmarshal into custom resource definition") | ||
} | ||
|
||
return []*v1beta1.CustomResourceDefinition{crd}, nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters