-
Notifications
You must be signed in to change notification settings - Fork 88
chore: package dependencies debt #656
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,61 @@ | ||
| // Copyright 2022 Red Hat, Inc. | ||
| // | ||
| // Licensed under the Apache License, Version 2.0 (the "License"); | ||
| // you may not use this file except in compliance with the License. | ||
| // You may obtain a copy of the License at | ||
| // | ||
| // http://www.apache.org/licenses/LICENSE-2.0 | ||
| // | ||
| // Unless required by applicable law or agreed to in writing, software | ||
| // distributed under the License is distributed on an "AS IS" BASIS, | ||
| // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| // See the License for the specific language governing permissions and | ||
| // limitations under the License. | ||
| package translator | ||
|
|
||
| import ( | ||
| "fmt" | ||
|
|
||
| "github.com/coreos/go-semver/semver" | ||
| ) | ||
|
|
||
| type commonFields struct { | ||
| Variant string `yaml:"variant"` | ||
| Version semver.Version `yaml:"version"` | ||
| } | ||
|
|
||
| func (c *commonFields) UnmarshalYAML(unmarshal func(interface{}) error) error { | ||
| type plain commonFields | ||
| var raw plain | ||
|
|
||
| if err := unmarshal(&raw); err != nil { | ||
| return err | ||
| } | ||
|
|
||
| if raw.Variant == "" { | ||
| return fmt.Errorf("variant cannot be empty") | ||
| } | ||
|
|
||
| *c = commonFields(raw) | ||
| return nil | ||
| } | ||
|
|
||
| func (c *commonFields) asKey() string { | ||
| return fmt.Sprintf("%s+%s", c.Variant, c.Version.String()) | ||
| } | ||
|
|
||
| func newCF(variant, version string) (commonFields, error) { | ||
| if variant == "" { | ||
| return commonFields{}, fmt.Errorf("variant cannot be empty") | ||
| } | ||
|
|
||
| v, err := semver.NewVersion(version) | ||
| if err != nil { | ||
| return commonFields{}, fmt.Errorf("invalid version: %w", err) | ||
| } | ||
|
|
||
| return commonFields{ | ||
| Variant: variant, | ||
| Version: *v, | ||
| }, nil | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,23 @@ | ||
| // Copyright 2022 Red Hat, Inc. | ||
| // | ||
| // Licensed under the Apache License, Version 2.0 (the "License"); | ||
| // you may not use this file except in compliance with the License. | ||
| // You may obtain a copy of the License at | ||
| // | ||
| // http://www.apache.org/licenses/LICENSE-2.0 | ||
| // | ||
| // Unless required by applicable law or agreed to in writing, software | ||
| // distributed under the License is distributed on an "AS IS" BASIS, | ||
| // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| // See the License for the specific language governing permissions and | ||
| // limitations under the License. | ||
| package translator | ||
|
|
||
| import ( | ||
| "github.com/coreos/butane/config/common" | ||
| "github.com/coreos/vcontext/report" | ||
| ) | ||
|
|
||
| type Translator interface { | ||
| TranslateBytes(input []byte, options common.TranslateBytesOptions) ([]byte, report.Report, error) | ||
| } | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Actually we prob, want a new type that is used in translator
with "variant, version,ignition version, description, and maybe isexperimental"
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. sounds good, one of my first idea was to re-use as the key to the registry, I guess it can/should be the base for the new
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ah that would make sense. Yeah its basically the building block of what we need. |
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,54 @@ | ||
| // Copyright 2022 Red Hat, Inc. | ||
| // | ||
| // Licensed under the Apache License, Version 2.0 (the "License"); | ||
| // you may not use this file except in compliance with the License. | ||
| // You may obtain a copy of the License at | ||
| // | ||
| // http://www.apache.org/licenses/LICENSE-2.0 | ||
| // | ||
| // Unless required by applicable law or agreed to in writing, software | ||
| // distributed under the License is distributed on an "AS IS" BASIS, | ||
| // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| // See the License for the specific language governing permissions and | ||
| // limitations under the License. | ||
| package translator | ||
|
|
||
| import ( | ||
| "fmt" | ||
|
|
||
| "github.com/coreos/butane/config/common" | ||
| "github.com/coreos/vcontext/report" | ||
| "gopkg.in/yaml.v3" | ||
| ) | ||
|
|
||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I was thinking we would have a set(register), get, list, then maybe we could add metadata to the interface. I.e a |
||
| var TranslatorRegistry = &Registry{ | ||
| translators: make(map[string]Translator), | ||
| } | ||
|
|
||
| type Registry struct { | ||
| translators map[string]Translator | ||
| } | ||
|
|
||
| func (r *Registry) RegisterTranslator(variant, version string, trans Translator) { | ||
| cf, err := newCF(variant, version) | ||
| if err != nil { | ||
| panic(fmt.Sprintf("tried to register a translator with an invalid key (%s+%s)", variant, version)) | ||
| } | ||
| if _, ok := r.translators[cf.asKey()]; ok { | ||
| panic(fmt.Sprintf("tried to reregister existing translator (%s+%s)", variant, version)) | ||
| } | ||
| r.translators[cf.asKey()] = trans | ||
| } | ||
|
|
||
| func (r *Registry) TranslateBytes(input []byte, options common.TranslateBytesOptions) ([]byte, report.Report, error) { | ||
| // first determine version; this will ignore most fields | ||
| cf := commonFields{} | ||
| if err := yaml.Unmarshal(input, &cf); err != nil { | ||
| return nil, report.Report{}, common.ErrUnmarshal{ | ||
| Detail: err.Error(), | ||
| } | ||
| } | ||
|
|
||
| translator := r.translators[cf.asKey()] | ||
| return translator.TranslateBytes(input, options) | ||
| } | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, this is an interface but i think it needs to be expanded.
So im pretty sure what we are hitting a cycle on is validation, and you can see that the
translatehas already been inverted but we need to do the same forvalidateI believe.We might need more then just validate tho.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ok for validate too, I think the rest will come as I implement it. It's hard to plan that much in advance 😅
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
100% agree'd. I think after we add validate and metadata we should be good atleast to start