Skip to content

Commit 988073b

Browse files
Snowblock API v0
Implemented the API v0 that serves as the reference for the legacy Python (backwards compatible) implementation with the following interfaces and types: - <I> `Snowblock` - <T> `Task` - <I> `TaskConfiguration` - <I> `TaskRegistry` - <I> `TaskRunner` Note that API v0 is a legacy implementation to keep the compatibility with the original Python implementation and will be superseded with API v1 with snowsaw version 1.0.0! Epic GH-33 Resolves GH-70
1 parent dea6ab5 commit 988073b

File tree

5 files changed

+108
-0
lines changed

5 files changed

+108
-0
lines changed

pkg/api/snowblock/constants.go

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
// Copyright (C) 2017-present Arctic Ice Studio <[email protected]>
2+
// Copyright (C) 2017-present Sven Greb <[email protected]>
3+
//
4+
// Project: snowsaw
5+
// Repository: https://github.com/arcticicestudio/snowsaw
6+
// License: MIT
7+
8+
// Author: Arctic Ice Studio <[email protected]>
9+
// Author: Sven Greb <[email protected]>
10+
// Since: 0.4.0
11+
12+
package snowblock
13+
14+
const (
15+
// ConfigurationFileName is the name of a snowblock configuration file.
16+
ConfigurationFileName = "snowblock"
17+
18+
// Version is the version of the snowblock API.
19+
Version int = 0
20+
)

pkg/api/snowblock/registry.go

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
// Copyright (C) 2017-present Arctic Ice Studio <[email protected]>
2+
// Copyright (C) 2017-present Sven Greb <[email protected]>
3+
//
4+
// Project: snowsaw
5+
// Repository: https://github.com/arcticicestudio/snowsaw
6+
// License: MIT
7+
8+
// Author: Arctic Ice Studio <[email protected]>
9+
// Author: Sven Greb <[email protected]>
10+
// Since: 0.4.0
11+
12+
package snowblock
13+
14+
// TaskRegistry is a registry for available task runner.
15+
type TaskRegistry interface {
16+
// Add validates and adds the given task runner to the registry.
17+
Add(TaskRunner) error
18+
19+
// GetAll returns a list of all currently registered task runners.
20+
GetAll() map[string]TaskRunner
21+
}

pkg/api/snowblock/runner.go

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
// Copyright (C) 2017-present Arctic Ice Studio <[email protected]>
2+
// Copyright (C) 2017-present Sven Greb <[email protected]>
3+
//
4+
// Project: snowsaw
5+
// Repository: https://github.com/arcticicestudio/snowsaw
6+
// License: MIT
7+
8+
// Author: Arctic Ice Studio <[email protected]>
9+
// Author: Sven Greb <[email protected]>
10+
// Since: 0.4.0
11+
12+
package snowblock
13+
14+
// TaskRunner processes a specific task.
15+
type TaskRunner interface {
16+
// GetTaskName returns the name of the task this runner can process.
17+
GetTaskName() string
18+
19+
// Run processes a task using the given task instructions.
20+
// The snowblockPath parameter is the path of the snowblock used as contextual information.
21+
Run(instructions TaskConfiguration, snowblockPath string) error
22+
}

pkg/api/snowblock/snowblock.go

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
// Copyright (C) 2017-present Arctic Ice Studio <[email protected]>
2+
// Copyright (C) 2017-present Sven Greb <[email protected]>
3+
//
4+
// Project: snowsaw
5+
// Repository: https://github.com/arcticicestudio/snowsaw
6+
// License: MIT
7+
8+
// Author: Arctic Ice Studio <[email protected]>
9+
// Author: Sven Greb <[email protected]>
10+
// Since: 0.4.0
11+
12+
// Package snowblock provides the snowblock API.
13+
//
14+
// Note: API v0 is a legacy implementation to keep the compatibility with the original Python implementation and will be
15+
// superseded with API v1 with snowsaw version 1.0.0!
16+
package snowblock
17+
18+
// Snowblock represents a snowblock.
19+
type Snowblock interface {
20+
// Dispatch handles the processing of the snowblock by dispatching the configured TaskConfiguration to a registered
21+
// TaskRunner that can handle it.
22+
Dispatch() error
23+
24+
// Validate ensures the snowblock exists and the configuration is valid.
25+
// The taskRunner parameter is a map of registered task runners that are able to process the task instructions.
26+
Validate(taskRunner map[string]TaskRunner) error
27+
}

pkg/api/snowblock/task.go

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
// Copyright (C) 2017-present Arctic Ice Studio <[email protected]>
2+
// Copyright (C) 2017-present Sven Greb <[email protected]>
3+
//
4+
// Project: snowsaw
5+
// Repository: https://github.com/arcticicestudio/snowsaw
6+
// License: MIT
7+
8+
// Author: Arctic Ice Studio <[email protected]>
9+
// Author: Sven Greb <[email protected]>
10+
// Since: 0.4.0
11+
12+
package snowblock
13+
14+
// Task represents a single task of a snowblock configuration.
15+
type Task map[string]interface{}
16+
17+
// TaskConfiguration represents the configuration of a single task.
18+
type TaskConfiguration interface{}

0 commit comments

Comments
 (0)