Skip to content
This repository was archived by the owner on Mar 11, 2025. It is now read-only.

Commit 7e38291

Browse files
authored
Merge pull request #76 from philips-software/feature/docker-repositories
Docker Registry: Add repositories management
2 parents 1dd882e + 49f290d commit 7e38291

File tree

7 files changed

+162
-26
lines changed

7 files changed

+162
-26
lines changed

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,10 @@ All notable changes to this project will be documented in this file.
44
The format is based on [Keep a Changelog](http://keepachangelog.com/)
55
and this project adheres to [Semantic Versioning](http://semver.org/).
66

7+
# v0.48.0
8+
9+
- Docker Registry: service keys, namespace and repository management
10+
711
# v0.47.0
812

913
- Logging: Add traceId and spanId fields

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ The current implement covers only a subset of HSDP APIs. Basically, we implement
5555
- [x] Docker Registry
5656
- [x] Service Keys management
5757
- [x] Namespace management
58-
- [ ] Repository management
58+
- [x] Repository management
5959
- [x] IronIO tasks, codes and schedules management ([examples](iron/README.md))
6060
- [x] Clinical Data Lake (CDL) management
6161
- [x] Research Studies

console/docker/client.go

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,8 +40,9 @@ type Client struct {
4040

4141
debugFile *os.File
4242

43-
ServiceKeys *ServiceKeysService
44-
Namespaces *NamespacesService
43+
ServiceKeys *ServiceKeysService
44+
Namespaces *NamespacesService
45+
Repositories *RepositoriesService
4546
}
4647

4748
// NewClient returns a new HSDP Docker Registry API client. A configured console client
@@ -72,6 +73,7 @@ func newClient(consoleClient *console.Client, config *Config) (*Client, error) {
7273
c.gql = graphql.NewClient(config.DockerAPIURL, consoleClient.Client)
7374
c.ServiceKeys = &ServiceKeysService{client: c}
7475
c.Namespaces = &NamespacesService{client: c}
76+
c.Repositories = &RepositoriesService{client: c}
7577

7678
return c, nil
7779
}

console/docker/namespaces_service.go

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -149,6 +149,23 @@ func (s *NamespacesService) AddNamespaceUser(ctx context.Context, namespaceID, u
149149
return &mutation.AddUserToNamespace, nil
150150
}
151151

152+
func (s *NamespacesService) GetRepositories(ctx context.Context, namespaceId string) (*[]Repository, error) {
153+
var query struct {
154+
Resources struct {
155+
Repositories []Repository
156+
} `graphql:"namespace(id: $namespaceId)"`
157+
}
158+
err := s.client.gql.Query(ctx, &query, map[string]interface{}{
159+
"namespaceId": graphql.String(namespaceId),
160+
})
161+
if err != nil {
162+
return nil, err
163+
}
164+
repositories := make([]Repository, 0)
165+
repositories = append(repositories, query.Resources.Repositories...)
166+
return &repositories, nil
167+
}
168+
152169
func (s *NamespacesService) DeleteNamespaceUser(ctx context.Context, namespaceID, username string) error {
153170
var mutation struct {
154171
DeleteUserFromNamespace bool `graphql:"removeUserFromNamespace(namespaceId: $namespaceId, userId: $userId)"`
Lines changed: 127 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,127 @@
1+
package docker
2+
3+
import (
4+
"context"
5+
"fmt"
6+
"time"
7+
8+
"github.com/hasura/go-graphql-client"
9+
)
10+
11+
type RepositoriesService struct {
12+
client *Client
13+
}
14+
15+
type Repository struct {
16+
ID string `json:"id"`
17+
NamespaceId string `json:"namespaceId"`
18+
Name string `json:"name"`
19+
NumPulls int `json:"numPulls"`
20+
NumTags int `json:"numTags"`
21+
}
22+
23+
type Tag struct {
24+
ID int `json:"id"`
25+
Name string `json:"name"`
26+
CompressedSize int `json:"compressedSize"`
27+
UpdatedAt time.Time `json:"updatedAt"`
28+
NumPulls int `json:"numPulls"`
29+
Digest string `json:"digest"`
30+
ImageId string `json:"imageId"`
31+
}
32+
33+
type RepositoryInput struct {
34+
NamespaceID string `json:"namespaceId"`
35+
Name string `json:"name"`
36+
}
37+
38+
type RepositoryDetailsInput struct {
39+
ShortDescription string `json:"shortDescription"`
40+
FullDescription string `json:"fullDescription"`
41+
}
42+
43+
type RepositoryResult struct {
44+
ID string `json:"id"`
45+
Name string `json:"name"`
46+
NamespaceID string `json:"namespaceId"`
47+
}
48+
49+
func (r *RepositoriesService) CreateRepository(ctx context.Context, repository RepositoryInput, details RepositoryDetailsInput) (*RepositoryResult, error) {
50+
var mutation struct {
51+
Repository RepositoryResult `graphql:"createRepository(repository: $repository, details: $details)"`
52+
}
53+
err := r.client.gql.Mutate(ctx, &mutation, map[string]interface{}{
54+
"repository": repository,
55+
"details": details,
56+
})
57+
if err != nil {
58+
return nil, err
59+
}
60+
if mutation.Repository.ID == "" {
61+
return nil, fmt.Errorf("error creating repository")
62+
}
63+
return &mutation.Repository, nil
64+
}
65+
66+
func (r *RepositoriesService) UpdateRepository(ctx context.Context, repository Repository, details RepositoryDetailsInput) (*RepositoryDetailsInput, error) {
67+
var mutation struct {
68+
Resources struct {
69+
Details RepositoryDetailsInput
70+
} `graphql:"updateRepository(id: $id, details: $details)"`
71+
}
72+
err := r.client.gql.Mutate(ctx, &mutation, map[string]interface{}{
73+
"id": graphql.String(repository.ID),
74+
"details": details,
75+
})
76+
if err != nil {
77+
return nil, err
78+
}
79+
return &mutation.Resources.Details, nil
80+
}
81+
82+
func (r *RepositoriesService) DeleteRepository(ctx context.Context, repository Repository) error {
83+
var mutation struct {
84+
DeleteRepository bool `graphql:"deleteRepository(id: $id)"`
85+
}
86+
err := r.client.gql.Mutate(ctx, &mutation, map[string]interface{}{
87+
"id": graphql.String(repository.ID),
88+
})
89+
if err != nil {
90+
return fmt.Errorf("eror deleting repository: %w", err)
91+
}
92+
if !mutation.DeleteRepository {
93+
return fmt.Errorf("failed to delete repository")
94+
}
95+
return nil
96+
}
97+
98+
func (r *RepositoriesService) GetRepository(ctx context.Context, namespaceId, name string) (*Repository, error) {
99+
var query struct {
100+
Repository Repository `graphql:"repository(namespaceId: $namespaceId, name: $name)"`
101+
}
102+
err := r.client.gql.Query(ctx, &query, map[string]interface{}{
103+
"namespaceId": graphql.String(namespaceId),
104+
"name": graphql.String(name),
105+
})
106+
if err != nil {
107+
return nil, err
108+
}
109+
return &query.Repository, nil
110+
}
111+
112+
func (r *RepositoriesService) GetTags(ctx context.Context, repositoryId string) (*[]Tag, error) {
113+
var query struct {
114+
Tags []Tag `graphql:"tags(repositoryId: $repositoryId, page: $page, limit: $limit, orderBy: UPDATED_AT)"`
115+
}
116+
err := r.client.gql.Query(ctx, &query, map[string]interface{}{
117+
"repositoryId": graphql.String(repositoryId),
118+
"page": graphql.Int(1),
119+
"limit": graphql.Int(1000),
120+
})
121+
if err != nil {
122+
return nil, err
123+
}
124+
tags := make([]Tag, 0)
125+
tags = append(tags, query.Tags...)
126+
return &tags, nil
127+
}

console/docker/service_keys_service.go

Lines changed: 8 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -45,30 +45,16 @@ func (a *ServiceKeysService) GetServiceKeys(ctx context.Context) (*[]ServiceKeyN
4545
}
4646

4747
func (a *ServiceKeysService) GetServiceKeyByID(ctx context.Context, id int) (*ServiceKeyNode, error) {
48-
// TODO: https://github.com/philips-internal/hsdp-docker-api/pull/3
49-
/*
50-
var query struct {
51-
ServiceKeyNode ServiceKeyNode `graphql:"serviceKey(id: $keyId)"`
52-
}
53-
err := a.client.gql.Query(ctx, &query, map[string]interface{}{
54-
"keyId": graphql.String(strconv.Itoa(id)),
55-
})
56-
if err != nil {
57-
return nil, fmt.Errorf("service key read: %w", err)
58-
}
59-
return &query.ServiceKeyNode, nil
60-
*/
61-
// Simulate for now
62-
keys, err := a.GetServiceKeys(ctx)
63-
if err != nil {
64-
return nil, err
48+
var query struct {
49+
ServiceKeyNode ServiceKeyNode `graphql:"serviceKey(id: $keyId)"`
6550
}
66-
for _, k := range *keys {
67-
if k.ID == id {
68-
return &k, nil
69-
}
51+
err := a.client.gql.Query(ctx, &query, map[string]interface{}{
52+
"keyId": graphql.Int(id),
53+
})
54+
if err != nil {
55+
return nil, fmt.Errorf("service key read: %w", err)
7056
}
71-
return nil, fmt.Errorf("simulated serviceKey(id: $id) did not find a match for '%d'", id)
57+
return &query.ServiceKeyNode, nil
7258
}
7359

7460
func (a *ServiceKeysService) CreateServiceKey(ctx context.Context, description string) (*ServiceKey, error) {

internal/version.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
package internal
22

33
const (
4-
LibraryVersion = "0.47.0"
4+
LibraryVersion = "0.48.0"
55
)

0 commit comments

Comments
 (0)