-
Notifications
You must be signed in to change notification settings - Fork 77
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Support configurable output formats * Remove legacy, support --only-spec
- Loading branch information
1 parent
3dba642
commit 1646298
Showing
17 changed files
with
186 additions
and
129 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
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 |
---|---|---|
@@ -1,28 +1,30 @@ | ||
package config | ||
|
||
type GrafanaConfig struct { | ||
URL string `yaml:"url"` | ||
User string `yaml:"user"` | ||
Token string `yaml:"token"` | ||
URL string `yaml:"url" mapstructure:"url"` | ||
User string `yaml:"user" mapstructure:"user"` | ||
Token string `yaml:"token" mapstructure:"token"` | ||
} | ||
|
||
type MimirConfig struct { | ||
Address string `yaml:"address"` | ||
TenantID int64 `yaml:"tenant-id"` | ||
ApiKey string `yaml:"api-key"` | ||
Address string `yaml:"address" mapstructure:"address"` | ||
TenantID int64 `yaml:"tenant-id" mapstructure:"tenant-id"` | ||
ApiKey string `yaml:"api-key" mapstructure:"api-key"` | ||
} | ||
|
||
type SyntheticMonitoringConfig struct { | ||
Token string `yaml:"token"` | ||
StackID int64 `yaml:"stack-id"` | ||
LogsID int64 `yaml:"logs-id"` | ||
MetricsID int64 `yaml:"metrics-id"` | ||
Token string `yaml:"token" mapstructure:"token"` | ||
StackID int64 `yaml:"stack-id" mapstructure:"stack-id"` | ||
LogsID int64 `yaml:"logs-id" mapstructure:"logs-id"` | ||
MetricsID int64 `yaml:"metrics-id" mapstructure:"metrics-id"` | ||
} | ||
|
||
type Context struct { | ||
Name string `yaml:"name"` | ||
Grafana GrafanaConfig `yaml:"grafana"` | ||
Mimir MimirConfig `yaml:"mimir"` | ||
SyntheticMonitoring SyntheticMonitoringConfig `yaml:"synthetic-monitoring"` | ||
Targets []string `yaml:"targets"` | ||
Name string `yaml:"name" mapstructure:"name"` | ||
Grafana GrafanaConfig `yaml:"grafana" mapstructure:"grafana"` | ||
Mimir MimirConfig `yaml:"mimir" mapstructure:"mimir"` | ||
SyntheticMonitoring SyntheticMonitoringConfig `yaml:"synthetic-monitoring" mapstructure:"synthetic-monitoring"` | ||
Targets []string `yaml:"targets" mapstructure:"targets"` | ||
OutputFormat string `yaml:"output-format" mapstructure:"output-format"` | ||
OnlySpec bool `yaml:"only-spec" mapstructure:"only-spec"` | ||
} |
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
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
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
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
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
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,65 @@ | ||
package grizzly | ||
|
||
import ( | ||
"os" | ||
"path/filepath" | ||
) | ||
|
||
func Format(resourcePath string, resource *Resource, format string, onlySpec bool) ([]byte, string, string, error) { | ||
var content string | ||
var filename string | ||
var extension string | ||
var err error | ||
|
||
spec := resource | ||
if onlySpec { | ||
s := Resource(resource.Spec()) | ||
spec = &s | ||
} | ||
|
||
switch format { | ||
case "yaml": | ||
extension = "yaml" | ||
filename, err = getFilename(resourcePath, resource, extension) | ||
if err != nil { | ||
return nil, "", "", err | ||
} | ||
content, err = spec.YAML() | ||
case "json": | ||
extension = "json" | ||
filename, err = getFilename(resourcePath, resource, extension) | ||
if err != nil { | ||
return nil, "", "", err | ||
} | ||
content, err = spec.JSON() | ||
default: | ||
extension = "yaml" | ||
filename, err = getFilename(resourcePath, resource, extension) | ||
if err != nil { | ||
return nil, "", "", err | ||
} | ||
content, err = spec.YAML() | ||
} | ||
return []byte(content), filename, extension, err | ||
} | ||
|
||
func getFilename(resourcePath string, resource *Resource, extension string) (string, error) { | ||
handler, err := Registry.GetHandler(resource.Kind()) | ||
if err != nil { | ||
return "", err | ||
} | ||
return filepath.Join(resourcePath, handler.ResourceFilePath(*resource, extension)), nil | ||
} | ||
|
||
func WriteFile(filename string, content []byte) error { | ||
dir := filepath.Dir(filename) | ||
err := os.MkdirAll(dir, 0755) | ||
if err != nil { | ||
return err | ||
} | ||
err = os.WriteFile(filename, content, 0644) | ||
if err != nil { | ||
return err | ||
} | ||
return nil | ||
} |
Oops, something went wrong.