-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #79 from siemens/feat/configurableExternalRef
feat(external_ref): Make external_ref fields configurable Reviewed-by: [email protected] Tested-by: [email protected]
- Loading branch information
Showing
15 changed files
with
219 additions
and
53 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
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,8 @@ | ||
// SPDX-FileCopyrightText: 2024 Dearsh Oberoi <[email protected]> | ||
// SPDX-FileCopyrightText: 2024 Siemens AG | ||
// | ||
// SPDX-License-Identifier: GPL-2.0-only | ||
|
||
package main | ||
|
||
//go:generate go run gen_external_ref_schema.go |
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,87 @@ | ||
// SPDX-FileCopyrightText: 2024 Dearsh Oberoi <[email protected]> | ||
// SPDX-FileCopyrightText: 2024 Siemens AG | ||
// | ||
// SPDX-License-Identifier: GPL-2.0-only | ||
|
||
//go:build ignore | ||
|
||
package main | ||
|
||
import ( | ||
"errors" | ||
"fmt" | ||
"log" | ||
"os" | ||
|
||
"path/filepath" | ||
|
||
"github.com/dave/jennifer/jen" | ||
"gopkg.in/yaml.v3" | ||
) | ||
|
||
var ( | ||
PATH_EXTERNAL_REF_CONFIG_FILE = filepath.FromSlash("../../external_ref_fields.yaml") | ||
PATH_EXTERNAL_REF_STRUCT_FILE = filepath.FromSlash("../../pkg/models/external_ref_structs.go") | ||
) | ||
|
||
// ExternalRefFieldMetadata is the metadata about the extra fields saved as json in the license external_ref column | ||
type ExternalRefFieldMetaData struct { | ||
StructFieldName string `yaml:"struct_field_name"` | ||
Type string `yaml:"type"` | ||
Name string `yaml:"name"` | ||
} | ||
|
||
// ExternalRefFields is the list of metadata of all extra fields | ||
type ExternalRefFields struct { | ||
Fields []ExternalRefFieldMetaData `yaml:"fields"` | ||
} | ||
|
||
func main() { | ||
externalRefFields := ExternalRefFields{} | ||
|
||
fieldsMetadata, err := os.ReadFile(PATH_EXTERNAL_REF_CONFIG_FILE) | ||
if err != nil { | ||
log.Fatalf("Failed to instantiate json schema for external ref in license: %v", err) | ||
} | ||
|
||
err = yaml.Unmarshal(fieldsMetadata, &externalRefFields) | ||
if err != nil { | ||
log.Fatalf("Failed to instantiate json schema for external ref in license: %v", err) | ||
} | ||
|
||
// REUSE-IgnoreStart | ||
|
||
f := jen.NewFile("models") | ||
f.Comment("SPDX-FileCopyrightText: FOSSology Community\nSPDX-License-Identifier: GPL-2.0-only\n\nThis file is autogenerated. Please do not edit it.\n") | ||
|
||
// REUSE-IgnoreStart | ||
|
||
var fields []jen.Code | ||
|
||
for _, f := range externalRefFields.Fields { | ||
field := jen.Id(f.StructFieldName).Op("*") | ||
if f.StructFieldName == "" { | ||
err = errors.New("field struct_field_name is missing in external_ref_fields.yaml") | ||
} | ||
switch f.Type { | ||
case "boolean": | ||
field = field.Bool() | ||
case "string": | ||
field = field.String() | ||
case "int": | ||
field = field.Int64() | ||
default: | ||
err = fmt.Errorf("type %s in external_ref_fields.yaml is not supported", f.Type) | ||
} | ||
if err != nil { | ||
log.Fatalf("Failed to instantiate json schema for external ref in license: %v", err) | ||
return | ||
} | ||
field = field.Tag(map[string]string{"json": fmt.Sprintf("%s,omitempty", f.Name)}) | ||
fields = append(fields, field) | ||
} | ||
|
||
f.Type().Id("LicenseDBSchemaExtension").Struct(fields...) | ||
f.Save(PATH_EXTERNAL_REF_STRUCT_FILE) | ||
|
||
} |
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,16 @@ | ||
# SPDX-License-Identifier: GPL-2.0-only | ||
# SPDX-FileCopyrightText: FOSSology contributors | ||
|
||
fields: | ||
- name: "license_suffix" | ||
type: "string" | ||
struct_field_name: "LicenseSuffix" | ||
label: "License Suffix" | ||
formComponentPath: "../components/dynamic/inputField" | ||
componentType: "input" | ||
- name: "license_explanation" | ||
type: "string" | ||
struct_field_name: "LicenseExplanation" | ||
label: "License Explanation" | ||
formComponentPath: "../components/dynamic/inputField" | ||
componentType: "input" |
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 was deleted.
Oops, something went wrong.