@@ -39,6 +39,7 @@ const DEFAULT_FILESYSTEM_ENABLE = true
3939const DEFAULT_FILESYSTEM_BASE_DIR = "/"
4040const DEFAULT_VERIFICATION_SCRIPT_PATH = ""
4141const DEFAULT_UPDATE_PROGRESS_ENABLE = true
42+ const DEFAULT_METADATA_FILE_PATH = ""
4243
4344type RDFMConfig struct {
4445 // Path to the device type file
@@ -101,6 +102,9 @@ type RDFMConfig struct {
101102
102103 // Is reporting update progress enabled? Default: true
103104 UpdateProgressEnable bool `json:",omitempty"`
105+
106+ // Path to the file with device metadata. Default: ""
107+ MetadataFilePath string `json:",omitempty"`
104108}
105109
106110var rdfmConfigInstance * RDFMConfig
@@ -152,6 +156,7 @@ func LoadConfig(mainConfigFile string, overlayConfigFile string) (*RDFMConfig, *
152156 FileSystemBaseDir : DEFAULT_FILESYSTEM_BASE_DIR ,
153157 VerificationScriptPath : DEFAULT_VERIFICATION_SCRIPT_PATH ,
154158 UpdateProgressEnable : DEFAULT_UPDATE_PROGRESS_ENABLE ,
159+ MetadataFilePath : DEFAULT_METADATA_FILE_PATH ,
155160 }
156161
157162 // Load Mender config
@@ -227,3 +232,21 @@ func LoadTagsConfig(path string) ([]string, error) {
227232
228233 return config , nil
229234}
235+
236+ func LoadMetadataFile (path string ) (map [string ]interface {}, error ) {
237+ if _ , err := os .Stat (path ); errors .Is (err , os .ErrNotExist ) {
238+ return make (map [string ]interface {}), errors .New (err .Error ())
239+ }
240+
241+ content , err := ioutil .ReadFile (path )
242+ if err != nil {
243+ return make (map [string ]interface {}), errors .New (err .Error ())
244+ }
245+
246+ var metadata map [string ]interface {}
247+ if err := json .Unmarshal (content , & metadata ); err != nil {
248+ return make (map [string ]interface {}), errors .New ("Error parsing metadata file: " + err .Error ())
249+ }
250+
251+ return metadata , nil
252+ }
0 commit comments