Skip to content

Commit

Permalink
manifest wip
Browse files Browse the repository at this point in the history
  • Loading branch information
tsebastiani committed Oct 10, 2024
1 parent 249722b commit daf893c
Show file tree
Hide file tree
Showing 10 changed files with 277 additions and 179 deletions.
14 changes: 0 additions & 14 deletions internal/providers/offline_scenario_provider.go

This file was deleted.

30 changes: 0 additions & 30 deletions internal/providers/provider_factory.go

This file was deleted.

119 changes: 0 additions & 119 deletions internal/providers/quay_scenario_provider.go

This file was deleted.

5 changes: 0 additions & 5 deletions internal/providers/scenario_provider.go

This file was deleted.

38 changes: 38 additions & 0 deletions pkg/provider/factory/provider_factory.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
package factory

import (
"github.com/krkn-chaos/krknctl/internal/config"
"github.com/krkn-chaos/krknctl/pkg/provider/models"
"github.com/krkn-chaos/krknctl/pkg/provider/offline"
"github.com/krkn-chaos/krknctl/pkg/provider/quay"
)

type ScenarioProvider interface {
GetScenarios() (*[]models.ScenarioTag, error)
}

type Mode int64

const (
Online = iota
Offline
)

type ProviderFactory struct {
Config *config.Config
}

func NewProviderFactory(config *config.Config) *ProviderFactory {
return &ProviderFactory{Config: config}
}

func (p *ProviderFactory) NewInstance(mode Mode) ScenarioProvider {
switch mode {
case Online:
return &quay.ScenarioProvider{Config: p.Config}
case Offline:
return &offline.ScenarioProvider{Config: p.Config}
default:
return nil
}
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package providers
package models

import (
"github.com/krkn-chaos/krknctl/pkg/typing"
Expand Down
15 changes: 15 additions & 0 deletions pkg/provider/offline/offline_scenario_provider.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
package offline

import (
"errors"
"github.com/krkn-chaos/krknctl/internal/config"
"github.com/krkn-chaos/krknctl/pkg/provider/models"
)

type ScenarioProvider struct {
Config *config.Config
}

func (p *ScenarioProvider) GetScenarios() (*[]models.ScenarioTag, error) {
return nil, errors.New("not yet implemented")
}
103 changes: 103 additions & 0 deletions pkg/provider/quay/quay_models.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,103 @@
package quay

import (
"encoding/json"
"fmt"
"strings"
"time"
)

type TagPage struct {
Tags []Tag `json:"tags"`
Page int `json:"page"`
HasAdditional bool `json:"has_additional"`
}

type Tag struct {
Name string `json:"name"`
Reversion bool `json:"reversion"`
StartTimeStamp int64 `json:"start_ts"`
ManifestDigest string `json:"manifest_digest"`
IsManifestList bool `json:"is_manifest_list"`
Size int64 `json:"size"`
LastModified time.Time `json:"last_modified"`
}

type tagAlias Tag

func (q *Tag) UnmarshalJSON(bytes []byte) error {
aux := &struct {
LastModified string `json:"last_modified"`
*tagAlias
}{
tagAlias: (*tagAlias)(q),
}
if err := json.Unmarshal(bytes, &aux); err != nil {
return err
}

layout := "Mon, 02 Jan 2006 15:04:05 -0700"
parsedTime, err := time.Parse(layout, aux.LastModified)
if err != nil {
return err
}

q.LastModified = parsedTime

return nil
}

type Manifest struct {
Digest string `json:"digest"`
IsManifestList bool `json:"is_manifest_list"`
ManifestData string `json:"manifest_data"`
ConfigMediaType string `json:"config_media_type"`
LayerCompressedSize string `json:"layer_compressed_size"`
Layers []Layer `json:"layers"`
}

func (m *Manifest) GetKrknctlLabel(label string) *string {
for _, v := range m.Layers {
for _, c := range v.Command {
if strings.Contains(c, fmt.Sprintf("#(nop) LABEL %s", label)) {
return &c
}
}
}
return nil
}

type Layer struct {
Index int64 `json:"index"`
CompressedSize int64 `json:"compressed_size"`
IsRemote bool `json:"is_remote"`
Command []string `json:"command"`
Comment string `json:"comment"`
Author string `json:"author"`
BlobDigest string `json:"blob_digest"`
CreatedDateTime time.Time `json:"created_datetime"`
}

type layerAlias Layer

func (l *Layer) UnmarshalJSON(bytes []byte) error {
aux := &struct {
CreatedDateTime string `json:"created_datetime"`
*layerAlias
}{
layerAlias: (*layerAlias)(l),
}
if err := json.Unmarshal(bytes, &aux); err != nil {
return err
}

layout := "Mon, 02 Jan 2006 15:04:05 -0700"
parsedTime, err := time.Parse(layout, aux.CreatedDateTime)
if err != nil {
return err
}

l.CreatedDateTime = parsedTime

return nil
}
Loading

0 comments on commit daf893c

Please sign in to comment.