github.com/quay/claircore@v1.5.28/aws/internal/alas/updates.go (about)

     1  // Copyright 2019 RedHat
     2  //
     3  // Licensed under the Apache License, Version 2.0 (the "License");
     4  // you may not use this file except in compliance with the License.
     5  // You may obtain a copy of the License at
     6  //
     7  //     http://www.apache.org/licenses/LICENSE-2.0
     8  //
     9  // Unless required by applicable law or agreed to in writing, software
    10  // distributed under the License is distributed on an "AS IS" BASIS,
    11  // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    12  // See the License for the specific language governing permissions and
    13  // limitations under the License.
    14  
    15  package alas
    16  
    17  import (
    18  	"encoding/xml"
    19  	"fmt"
    20  	"time"
    21  )
    22  
    23  type Updates struct {
    24  	Updates []Update `xml:"update"`
    25  }
    26  
    27  type Update struct {
    28  	Author      string      `xml:"author,attr"`
    29  	From        string      `xml:"from,attr"`
    30  	Status      string      `xml:"status,attr"`
    31  	Type        string      `xml:"type,attr"`
    32  	Version     string      `xml:"version,attr"`
    33  	ID          string      `xml:"id"`
    34  	Title       string      `xml:"title"`
    35  	Issued      DateElem    `xml:"issued"`
    36  	Updated     DateElem    `xml:"updated"`
    37  	Severity    string      `xml:"severity"`
    38  	Description string      `xml:"description"`
    39  	References  []Reference `xml:"references>reference"`
    40  	Packages    []Package   `xml:"pkglist>collection>package"`
    41  }
    42  
    43  type DateElem struct {
    44  	Date `xml:"date,attr"`
    45  }
    46  
    47  type Date time.Time
    48  
    49  var _ xml.UnmarshalerAttr = (*Date)(nil)
    50  
    51  // UnmarshalXMLAttr implements [xml.UnmarshalerAttr].
    52  func (d *Date) UnmarshalXMLAttr(attr xml.Attr) (err error) {
    53  	if attr.Name.Local != `date` {
    54  		return fmt.Errorf("unexpected attr name: %q", attr.Name.Local)
    55  	}
    56  	fmts := []string{
    57  		"2006-01-02 15:04", time.DateTime,
    58  	}
    59  	var t time.Time
    60  	for _, f := range fmts {
    61  		t, err = time.Parse(f, attr.Value)
    62  		if err == nil {
    63  			break
    64  		}
    65  	}
    66  	if err != nil {
    67  		return fmt.Errorf("parsing date attr: %w", err)
    68  	}
    69  	*d = Date(t)
    70  	return nil
    71  }
    72  
    73  type Reference struct {
    74  	Href  string `xml:"href,attr"`
    75  	ID    string `xml:"id,attr"`
    76  	Title string `xml:"title,attr"`
    77  	Type  string `xml:"type,attr"`
    78  }
    79  
    80  type Package struct {
    81  	Name     string `xml:"name,attr"`
    82  	Epoch    string `xml:"epoch,attr"`
    83  	Version  string `xml:"version,attr"`
    84  	Release  string `xml:"release,attr"`
    85  	Arch     string `xml:"arch,attr"`
    86  	Filename string `xml:"filename"`
    87  }