-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
249722b
commit daf893c
Showing
10 changed files
with
277 additions
and
179 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
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,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 | ||
} | ||
} |
2 changes: 1 addition & 1 deletion
2
internal/providers/scenario_models.go → pkg/provider/models/models.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 |
---|---|---|
@@ -1,4 +1,4 @@ | ||
package providers | ||
package models | ||
|
||
import ( | ||
"github.com/krkn-chaos/krknctl/pkg/typing" | ||
|
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,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") | ||
} |
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,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 | ||
} |
Oops, something went wrong.