-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
#6 unified project setup, added graphql project, added repositories a…
…nd tags endpoint
- Loading branch information
Showing
36 changed files
with
803 additions
and
123 deletions.
There are no files selected for viewing
16 changes: 16 additions & 0 deletions
16
.idea/runConfigurations/go_build_github_com_harbourrocks_harbour_cmd_harbour_gateway.xml
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
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,46 @@ | ||
package app | ||
|
||
import ( | ||
server "github.com/harbourrocks/harbour/pkg/harbourgateway" | ||
"github.com/harbourrocks/harbour/pkg/harbourgateway/configuration" | ||
"github.com/harbourrocks/harbour/pkg/logconfig" | ||
"github.com/harbourrocks/harbour/pkg/redisconfig" | ||
"github.com/sirupsen/logrus" | ||
"github.com/spf13/cobra" | ||
"github.com/spf13/viper" | ||
) | ||
|
||
// NewGatewayServerCommand creates a *cobra.Command object with default parameters | ||
func NewGatewayServerCommand() *cobra.Command { | ||
cmd := &cobra.Command{ | ||
Use: "harbour-gateway", | ||
Long: `The harbour.rocks Gateway server manages | ||
all incoming http requests.`, | ||
RunE: func(cmd *cobra.Command, args []string) error { | ||
|
||
// load OIDC config | ||
s := configuration.ParseViperConfig() | ||
|
||
// configure logging | ||
l := logconfig.ParseViperConfig() | ||
logconfig.ConfigureLog(l) | ||
|
||
logrus.Info("Harbour Gateway configured") | ||
|
||
// test redis connection | ||
redisconfig.TestConnection(s.Redis) | ||
|
||
return server.RunGatewayServer(s) | ||
}, | ||
} | ||
|
||
return cmd | ||
} | ||
|
||
func init() { | ||
cobra.OnInitialize(initCobra) | ||
} | ||
|
||
func initCobra() { | ||
viper.AutomaticEnv() | ||
} |
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 main | ||
|
||
import ( | ||
"os" | ||
|
||
"github.com/harbourrocks/harbour/cmd/harbour-gateway/app" | ||
) | ||
|
||
func main() { | ||
cmd := app.NewGatewayServerCommand() | ||
|
||
if err := cmd.Execute(); err != nil { | ||
os.Exit(1) | ||
} | ||
} |
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,17 @@ | ||
version: '3.3' | ||
services: | ||
registry: | ||
container_name: standalone-registry | ||
image: registry:2 | ||
ports: | ||
- 5000:5000 | ||
# environment: | ||
# REGISTRY_HTTP_TLS_CERTIFICATE: /certs/domain.crt | ||
# REGISTRY_HTTP_TLS_KEY: /certs/domain.key | ||
# REGISTRY_AUTH: htpasswd | ||
# REGISTRY_AUTH_HTPASSWD_PATH: /auth/htpasswd | ||
# REGISTRY_AUTH_HTPASSWD_REALM: Registry Realm | ||
# volumes: | ||
# - /path/data:/var/lib/registry | ||
# - /path/certs:/certs | ||
# - /path/auth:/auth |
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
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
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
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,35 @@ | ||
package configuration | ||
|
||
import ( | ||
"github.com/harbourrocks/harbour/pkg/auth" | ||
"github.com/harbourrocks/harbour/pkg/redisconfig" | ||
"github.com/harbourrocks/harbour/pkg/registry" | ||
) | ||
|
||
// Options defines all options available to configure the Gateway server. | ||
type Options struct { | ||
Redis redisconfig.RedisOptions | ||
OIDCConfig auth.OIDCConfig | ||
DockerRegistry registry.RegistryConfig | ||
} | ||
|
||
// NewDefaultOptions returns the default options | ||
func NewDefaultOptions() *Options { | ||
s := Options{ | ||
Redis: redisconfig.NewDefaultRedisOptions(), | ||
OIDCConfig: auth.DefaultConfig(), | ||
} | ||
|
||
return &s | ||
} | ||
|
||
// ParseViperConfig tries to map a viper configuration | ||
func ParseViperConfig() *Options { | ||
s := NewDefaultOptions() | ||
|
||
s.OIDCConfig = auth.ParseViperConfig() | ||
s.Redis = redisconfig.ParseViperConfig() | ||
s.DockerRegistry = registry.ParseViperConfig() | ||
|
||
return s | ||
} |
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,48 @@ | ||
package graphql | ||
|
||
import ( | ||
"github.com/graphql-go/graphql" | ||
"github.com/harbourrocks/harbour/pkg/apiclient" | ||
"github.com/harbourrocks/harbour/pkg/harbourgateway/configuration" | ||
"github.com/harbourrocks/harbour/pkg/harbourgateway/model" | ||
"github.com/harbourrocks/harbour/pkg/registry/models" | ||
) | ||
|
||
var repositoryListType = graphql.NewList(repositoryType) | ||
var repositoryType = graphql.NewObject( | ||
graphql.ObjectConfig{ | ||
Name: "Repository", | ||
Description: "All repositories of the registry.", | ||
Fields: graphql.Fields{ | ||
"name": &graphql.Field{ | ||
Type: graphql.String, | ||
Description: "The name of the docker registry repository. " + | ||
"This can contain slashes", | ||
}, | ||
}, | ||
}, | ||
) | ||
|
||
func RepositoriesField(options configuration.Options) *graphql.Field { | ||
return &graphql.Field{ | ||
Type: repositoryListType, | ||
Resolve: func(p graphql.ResolveParams) (interface{}, error) { | ||
// query repositories from docker registry | ||
var regRepositories models.Repositories | ||
_, err := apiclient.Get(options.DockerRegistry.RepositoriesURL(), ®Repositories) | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
// map docker registry response to harbour response | ||
var response = make([]model.Repository, len(regRepositories.Repositories)) | ||
for i, repository := range regRepositories.Repositories { | ||
response[i] = model.Repository{ | ||
Name: repository, | ||
} | ||
} | ||
|
||
return response, err | ||
}, | ||
} | ||
} |
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,67 @@ | ||
package graphql | ||
|
||
import ( | ||
"github.com/graphql-go/graphql" | ||
"github.com/harbourrocks/harbour/pkg/apiclient" | ||
"github.com/harbourrocks/harbour/pkg/harbourgateway/configuration" | ||
"github.com/harbourrocks/harbour/pkg/harbourgateway/model" | ||
"github.com/harbourrocks/harbour/pkg/registry/models" | ||
) | ||
|
||
var tagListType = graphql.NewList(tagType) | ||
var tagType = graphql.NewObject( | ||
graphql.ObjectConfig{ | ||
Name: "Tag", | ||
Fields: graphql.Fields{ | ||
"name": &graphql.Field{ | ||
Type: graphql.String, | ||
Description: "The name of the tag. The tag combined with the repository " + | ||
"is a unique identifier for an image", | ||
}, | ||
"repository": &graphql.Field{ | ||
Type: repositoryType, | ||
Description: "The repository of the tag.", | ||
}, | ||
}, | ||
}, | ||
) | ||
|
||
func TagsField(options configuration.Options) *graphql.Field { | ||
return &graphql.Field{ | ||
Type: tagListType, | ||
Description: "All tags of a specified repository.", | ||
Args: graphql.FieldConfigArgument{ | ||
"repository": &graphql.ArgumentConfig{ | ||
Type: graphql.String, | ||
Description: "Defines the repository of which the tags should be returned.", | ||
}, | ||
}, | ||
Resolve: func(p graphql.ResolveParams) (interface{}, error) { | ||
// parse query parameter | ||
repositoryQuery, isOK := p.Args["repository"].(string) | ||
if !isOK { | ||
return nil, nil | ||
} | ||
|
||
// query tags of repository from docker registry | ||
var regTags models.Tags | ||
_, err := apiclient.Get(options.DockerRegistry.RepositoryTagsURL(repositoryQuery), ®Tags) | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
// map docker registry response to harbour response | ||
var response = make([]model.Tag, len(regTags.Tags)) | ||
for i, repository := range regTags.Tags { | ||
response[i] = model.Tag{ | ||
Name: repository, | ||
Repository: model.Repository{ | ||
Name: regTags.Name, | ||
}, | ||
} | ||
} | ||
|
||
return response, err | ||
}, | ||
} | ||
} |
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 handler | ||
|
||
import ( | ||
"encoding/json" | ||
"fmt" | ||
"github.com/graphql-go/graphql" | ||
traits2 "github.com/harbourrocks/harbour/pkg/harbourgateway/traits" | ||
"github.com/harbourrocks/harbour/pkg/httphandler/traits" | ||
) | ||
|
||
func executeQuery(query string, schema graphql.Schema) *graphql.Result { | ||
result := graphql.Do(graphql.Params{ | ||
Schema: schema, | ||
RequestString: query, | ||
}) | ||
|
||
if len(result.Errors) > 0 { | ||
fmt.Printf("wrong result, unexpected errors: %v", result.Errors) | ||
} | ||
|
||
return result | ||
} | ||
|
||
// GraphQLModel is specific for one handler | ||
type GraphQLModel struct { | ||
traits.HttpModel | ||
traits.IdTokenModel | ||
traits2.GraphQLModel | ||
} | ||
|
||
func (h GraphQLModel) Handle() (err error) { | ||
r := h.GetRequest() | ||
w := h.GetResponse() | ||
s := h.GetSchema() | ||
|
||
result := executeQuery(r.URL.Query().Get("query"), s) | ||
return json.NewEncoder(w).Encode(result) | ||
} |
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,7 @@ | ||
package model | ||
|
||
// Repository represents a repository on the docker registry | ||
// A repository is identified by its name | ||
type Repository struct { | ||
Name string `json:"name"` | ||
} |
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,8 @@ | ||
package model | ||
|
||
// Tag represents a tagged image in a specific repository | ||
// A tag is identified by its name | ||
type Tag struct { | ||
Name string `json:"Name"` | ||
Repository Repository `json:"repository"` | ||
} |
Oops, something went wrong.