-
Notifications
You must be signed in to change notification settings - Fork 5
/
api.go
134 lines (106 loc) · 4.37 KB
/
api.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
// SPDX-FileCopyrightText: Copyright (c) 2023-2024, CIQ, Inc. All rights reserved
// SPDX-License-Identifier: Apache-2.0
package apiv1
import (
"context"
"regexp"
"google.golang.org/protobuf/types/known/durationpb"
)
const (
RepositoryRegex = "^(artifacts/ostree/[a-z0-9]+(?:[/._-][a-z0-9]+)*)$"
URLPath = "/artifacts/ostree/api/v1"
)
var repositoryMatcher = regexp.MustCompile(RepositoryRegex)
func RepositoryMatch(repository string) bool {
return repositoryMatcher.MatchString(repository)
}
type Page struct {
Size int
Token string
}
type OSTreeRepositoryProperties struct {
// Remotes - The remote repositories to mirror.
Remotes []OSTreeRemoteProperties `json:"remotes"`
}
type OSTreeRef struct {
// Name - The name of the ref.
Name string `json:"name"`
// Commit - The commit hash of the ref.
Commit string `json:"commit"`
}
type OSTreeRemoteProperties struct {
// Name - The name of the remote repository.
Name string `json:"name"`
// RemoteURL - The http url of the remote repository.
RemoteURL string `json:"remote_url"`
// GPGVerify - Whether to verify the GPG signature of the repository.
NoGPGVerify bool `json:"no_gpg_verify"`
}
type OSTreeRepositorySyncRequest struct {
// Remote - The name of the remote to sync.
// Remote and EphemeralRemote are mutually exclusive. EphemeralRemote takes precedence.
Remote string `json:"remote"`
// EphemeralRemote - A remote to add to the repository in Beskar for the duration of the sync.
// Remote and EphemeralRemote are mutually exclusive. EphemeralRemote takes precedence.
EphemeralRemote *OSTreeRemoteProperties `json:"ephemeral_remote"`
// Refs - The branches/refs to mirror. Leave empty to mirror all branches/refs.
Refs []string `json:"refs"`
// Depth - The depth of the mirror. Defaults is 0, -1 means infinite.
Depth int `json:"depth"`
// Timeout - The timeout for the sync in seconds. Default is 1 hour.
Timeout *durationpb.Duration `json:"timeout"`
}
// Mirror sync status.
type SyncStatus struct {
Syncing bool `json:"syncing"`
StartTime string `json:"start_time"`
EndTime string `json:"end_time"`
SyncError string `json:"sync_error"`
SyncedRefs []OSTreeRef `json:"synced_refs"`
// TODO: Implement these
// The data for these is present when performing a pull via the ostree cli, so it is in the libostree code base.
// SyncedMetadata int `json:"synced_metadata"`
// SyncedObjects int `json:"synced_objects"`
}
// OSTree is used for managing ostree repositories.
// This is the API documentation of OSTree.
//
//kun:oas title=OSTree Repository Management API
//kun:oas version=1.0.0
//kun:oas basePath=/artifacts/ostree/api/v1
//kun:oas docsPath=/doc/swagger.yaml
//kun:oas tags=ostree
type OSTree interface {
// Create an OSTree repository.
//kun:op POST /repository
//kun:success statusCode=200
CreateRepository(ctx context.Context, repository string, properties *OSTreeRepositoryProperties) (err error)
// Delete a OSTree repository.
//kun:op DELETE /repository
//kun:success statusCode=202
DeleteRepository(ctx context.Context, repository string) (err error)
// List OSTree repository refs (A.K.A. Branches).
//kun:op GET /repository/refs
//kun:success statusCode=200
ListRepositoryRefs(ctx context.Context, repository string) (refs []OSTreeRef, err error)
// Add a new remote to the OSTree repository.
//kun:op POST /repository/remote
//kun:success statusCode=200
AddRemote(ctx context.Context, repository string, properties *OSTreeRemoteProperties) (err error)
// Updates a remote in the OSTree repository. If it doesn't exist it will be created.
//kun:op PUT /repository/remote
//kun:success statusCode=200
UpdateRemote(ctx context.Context, repository string, remoteName string, properties *OSTreeRemoteProperties) (err error)
// Delete an existing remote to the OSTree repository.
//kun:op DELETE /repository/remote
//kun:success statusCode=200
DeleteRemote(ctx context.Context, repository string, remoteName string) (err error)
// Sync an ostree repository with one of the configured remotes.
//kun:op POST /repository/sync
//kun:success statusCode=202
SyncRepository(ctx context.Context, repository string, properties *OSTreeRepositorySyncRequest) (err error)
// Get OSTree repository sync status.
//kun:op GET /repository/sync
//kun:success statusCode=200
GetRepositorySyncStatus(ctx context.Context, repository string) (syncStatus *SyncStatus, err error)
}