From c0bc32deae7c3d8c353b05876c6eeeb3534a989f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Thorben=20G=C3=BCnther?= Date: Wed, 29 Dec 2021 02:12:02 +0100 Subject: [PATCH] api: Add settings field to version --- api/graph/api/generated.go | 289 +++++++++++++++++++++++++++++++++- api/graph/model/models_gen.go | 5 + api/graph/schema.graphqls | 8 + api/graph/schema.resolvers.go | 7 + 4 files changed, 308 insertions(+), 1 deletion(-) diff --git a/api/graph/api/generated.go b/api/graph/api/generated.go index c681f1c..a3b94a9 100644 --- a/api/graph/api/generated.go +++ b/api/graph/api/generated.go @@ -168,6 +168,10 @@ type ComplexityRoot struct { Results func(childComplexity int) int } + Settings struct { + SSHUser func(childComplexity int) int + } + Signature struct { Email func(childComplexity int) int Name func(childComplexity int) int @@ -233,6 +237,7 @@ type ComplexityRoot struct { Major func(childComplexity int) int Minor func(childComplexity int) int Patch func(childComplexity int) int + Settings func(childComplexity int) int } } @@ -892,6 +897,13 @@ func (e *executableSchema) Complexity(typeName, field string, childComplexity in return e.complexity.RepositoryCursor.Results(childComplexity), true + case "Settings.sshUser": + if e.complexity.Settings.SSHUser == nil { + break + } + + return e.complexity.Settings.SSHUser(childComplexity), true + case "Signature.email": if e.complexity.Signature.Email == nil { break @@ -1208,6 +1220,13 @@ func (e *executableSchema) Complexity(typeName, field string, childComplexity in return e.complexity.Version.Patch(childComplexity), true + case "Version.settings": + if e.complexity.Version.Settings == nil { + break + } + + return e.complexity.Version.Settings(childComplexity), true + } return 0, false } @@ -1310,6 +1329,9 @@ type Version { # Optional features features: Features! + + # Config settings + settings: Settings! } # Describes the status of optional features @@ -1317,6 +1339,11 @@ type Features { artifacts: Boolean! } +# Instance specific settings +type Settings { + sshUser: String! +} + enum AccessMode { # Read-only RO @@ -5429,6 +5456,41 @@ func (ec *executionContext) _RepositoryCursor_cursor(ctx context.Context, field return ec.marshalOCursor2ᚖgitᚗsrᚗhtᚋאsircmpwnᚋcoreᚑgoᚋmodelᚐCursor(ctx, field.Selections, res) } +func (ec *executionContext) _Settings_sshUser(ctx context.Context, field graphql.CollectedField, obj *model.Settings) (ret graphql.Marshaler) { + defer func() { + if r := recover(); r != nil { + ec.Error(ctx, ec.Recover(ctx, r)) + ret = graphql.Null + } + }() + fc := &graphql.FieldContext{ + Object: "Settings", + Field: field, + Args: nil, + IsMethod: false, + IsResolver: false, + } + + ctx = graphql.WithFieldContext(ctx, fc) + resTmp, err := ec.ResolverMiddleware(ctx, func(rctx context.Context) (interface{}, error) { + ctx = rctx // use context from middleware stack in children + return obj.SSHUser, nil + }) + if err != nil { + ec.Error(ctx, err) + return graphql.Null + } + if resTmp == nil { + if !graphql.HasFieldError(ctx, fc) { + ec.Errorf(ctx, "must not be null") + } + return graphql.Null + } + res := resTmp.(string) + fc.Result = res + return ec.marshalNString2string(ctx, field.Selections, res) +} + func (ec *executionContext) _Signature_name(ctx context.Context, field graphql.CollectedField, obj *model.Signature) (ret graphql.Marshaler) { defer func() { if r := recover(); r != nil { @@ -6962,6 +7024,41 @@ func (ec *executionContext) _Version_features(ctx context.Context, field graphql return ec.marshalNFeatures2ᚖgitᚗsrᚗhtᚋאsircmpwnᚋgitᚗsrᚗhtᚋapiᚋgraphᚋmodelᚐFeatures(ctx, field.Selections, res) } +func (ec *executionContext) _Version_settings(ctx context.Context, field graphql.CollectedField, obj *model.Version) (ret graphql.Marshaler) { + defer func() { + if r := recover(); r != nil { + ec.Error(ctx, ec.Recover(ctx, r)) + ret = graphql.Null + } + }() + fc := &graphql.FieldContext{ + Object: "Version", + Field: field, + Args: nil, + IsMethod: false, + IsResolver: false, + } + + ctx = graphql.WithFieldContext(ctx, fc) + resTmp, err := ec.ResolverMiddleware(ctx, func(rctx context.Context) (interface{}, error) { + ctx = rctx // use context from middleware stack in children + return obj.Settings, nil + }) + if err != nil { + ec.Error(ctx, err) + return graphql.Null + } + if resTmp == nil { + if !graphql.HasFieldError(ctx, fc) { + ec.Errorf(ctx, "must not be null") + } + return graphql.Null + } + res := resTmp.(*model.Settings) + fc.Result = res + return ec.marshalNSettings2ᚖgitᚗsrᚗhtᚋאsircmpwnᚋgitᚗsrᚗhtᚋapiᚋgraphᚋmodelᚐSettings(ctx, field.Selections, res) +} + func (ec *executionContext) ___Directive_name(ctx context.Context, field graphql.CollectedField, obj *introspection.Directive) (ret graphql.Marshaler) { defer func() { if r := recover(); r != nil { @@ -7099,6 +7196,41 @@ func (ec *executionContext) ___Directive_args(ctx context.Context, field graphql return ec.marshalN__InputValue2ᚕgithubᚗcomᚋ99designsᚋgqlgenᚋgraphqlᚋintrospectionᚐInputValueᚄ(ctx, field.Selections, res) } +func (ec *executionContext) ___Directive_isRepeatable(ctx context.Context, field graphql.CollectedField, obj *introspection.Directive) (ret graphql.Marshaler) { + defer func() { + if r := recover(); r != nil { + ec.Error(ctx, ec.Recover(ctx, r)) + ret = graphql.Null + } + }() + fc := &graphql.FieldContext{ + Object: "__Directive", + Field: field, + Args: nil, + IsMethod: false, + IsResolver: false, + } + + ctx = graphql.WithFieldContext(ctx, fc) + resTmp, err := ec.ResolverMiddleware(ctx, func(rctx context.Context) (interface{}, error) { + ctx = rctx // use context from middleware stack in children + return obj.IsRepeatable, nil + }) + if err != nil { + ec.Error(ctx, err) + return graphql.Null + } + if resTmp == nil { + if !graphql.HasFieldError(ctx, fc) { + ec.Errorf(ctx, "must not be null") + } + return graphql.Null + } + res := resTmp.(bool) + fc.Result = res + return ec.marshalNBoolean2bool(ctx, field.Selections, res) +} + func (ec *executionContext) ___EnumValue_name(ctx context.Context, field graphql.CollectedField, obj *introspection.EnumValue) (ret graphql.Marshaler) { defer func() { if r := recover(); r != nil { @@ -8051,7 +8183,10 @@ func (ec *executionContext) ___Type_ofType(ctx context.Context, field graphql.Co func (ec *executionContext) unmarshalInputFilter(ctx context.Context, obj interface{}) (model1.Filter, error) { var it model1.Filter - var asMap = obj.(map[string]interface{}) + asMap := map[string]interface{}{} + for k, v := range obj.(map[string]interface{}) { + asMap[k] = v + } if _, present := asMap["count"]; !present { asMap["count"] = 20 @@ -8949,6 +9084,33 @@ func (ec *executionContext) _RepositoryCursor(ctx context.Context, sel ast.Selec return out } +var settingsImplementors = []string{"Settings"} + +func (ec *executionContext) _Settings(ctx context.Context, sel ast.SelectionSet, obj *model.Settings) graphql.Marshaler { + fields := graphql.CollectFields(ec.OperationContext, sel, settingsImplementors) + + out := graphql.NewFieldSet(fields) + var invalids uint32 + for i, field := range fields { + switch field.Name { + case "__typename": + out.Values[i] = graphql.MarshalString("Settings") + case "sshUser": + out.Values[i] = ec._Settings_sshUser(ctx, field, obj) + if out.Values[i] == graphql.Null { + invalids++ + } + default: + panic("unknown field " + strconv.Quote(field.Name)) + } + } + out.Dispatch() + if invalids > 0 { + return graphql.Null + } + return out +} + var signatureImplementors = []string{"Signature"} func (ec *executionContext) _Signature(ctx context.Context, sel ast.SelectionSet, obj *model.Signature) graphql.Marshaler { @@ -9326,6 +9488,11 @@ func (ec *executionContext) _Version(ctx context.Context, sel ast.SelectionSet, if out.Values[i] == graphql.Null { invalids++ } + case "settings": + out.Values[i] = ec._Version_settings(ctx, field, obj) + if out.Values[i] == graphql.Null { + invalids++ + } default: panic("unknown field " + strconv.Quote(field.Name)) } @@ -9365,6 +9532,11 @@ func (ec *executionContext) ___Directive(ctx context.Context, sel ast.SelectionS if out.Values[i] == graphql.Null { invalids++ } + case "isRepeatable": + out.Values[i] = ec.___Directive_isRepeatable(ctx, field, obj) + if out.Values[i] == graphql.Null { + invalids++ + } default: panic("unknown field " + strconv.Quote(field.Name)) } @@ -9620,6 +9792,13 @@ func (ec *executionContext) marshalNACL2ᚕᚖgitᚗsrᚗhtᚋאsircmpwnᚋgit } wg.Wait() + + for _, e := range ret { + if e == graphql.Null { + return graphql.Null + } + } + return ret } @@ -9715,6 +9894,13 @@ func (ec *executionContext) marshalNArtifact2ᚕᚖgitᚗsrᚗhtᚋאsircmpwnᚋ } wg.Wait() + + for _, e := range ret { + if e == graphql.Null { + return graphql.Null + } + } + return ret } @@ -9791,6 +9977,13 @@ func (ec *executionContext) marshalNCommit2ᚕᚖgitᚗsrᚗhtᚋאsircmpwnᚋgi } wg.Wait() + + for _, e := range ret { + if e == graphql.Null { + return graphql.Null + } + } + return ret } @@ -9912,6 +10105,7 @@ func (ec *executionContext) marshalNObject2ᚕgitᚗsrᚗhtᚋאsircmpwnᚋgit } wg.Wait() + return ret } @@ -9959,6 +10153,13 @@ func (ec *executionContext) marshalNReference2ᚕᚖgitᚗsrᚗhtᚋאsircmpwn } wg.Wait() + + for _, e := range ret { + if e == graphql.Null { + return graphql.Null + } + } + return ret } @@ -10028,6 +10229,13 @@ func (ec *executionContext) marshalNRepository2ᚕᚖgitᚗsrᚗhtᚋאsircmpwn } wg.Wait() + + for _, e := range ret { + if e == graphql.Null { + return graphql.Null + } + } + return ret } @@ -10055,6 +10263,16 @@ func (ec *executionContext) marshalNRepositoryCursor2ᚖgitᚗsrᚗhtᚋאsircmp return ec._RepositoryCursor(ctx, sel, v) } +func (ec *executionContext) marshalNSettings2ᚖgitᚗsrᚗhtᚋאsircmpwnᚋgitᚗsrᚗhtᚋapiᚋgraphᚋmodelᚐSettings(ctx context.Context, sel ast.SelectionSet, v *model.Settings) graphql.Marshaler { + if v == nil { + if !graphql.HasFieldError(ctx, graphql.GetFieldContext(ctx)) { + ec.Errorf(ctx, "must not be null") + } + return graphql.Null + } + return ec._Settings(ctx, sel, v) +} + func (ec *executionContext) marshalNSignature2ᚖgitᚗsrᚗhtᚋאsircmpwnᚋgitᚗsrᚗhtᚋapiᚋgraphᚋmodelᚐSignature(ctx context.Context, sel ast.SelectionSet, v *model.Signature) graphql.Marshaler { if v == nil { if !graphql.HasFieldError(ctx, graphql.GetFieldContext(ctx)) { @@ -10139,6 +10357,13 @@ func (ec *executionContext) marshalNTreeEntry2ᚕᚖgitᚗsrᚗhtᚋאsircmpwn } wg.Wait() + + for _, e := range ret { + if e == graphql.Null { + return graphql.Null + } + } + return ret } @@ -10257,6 +10482,13 @@ func (ec *executionContext) marshalN__Directive2ᚕgithubᚗcomᚋ99designsᚋgq } wg.Wait() + + for _, e := range ret { + if e == graphql.Null { + return graphql.Null + } + } + return ret } @@ -10330,6 +10562,13 @@ func (ec *executionContext) marshalN__DirectiveLocation2ᚕstringᚄ(ctx context } wg.Wait() + + for _, e := range ret { + if e == graphql.Null { + return graphql.Null + } + } + return ret } @@ -10379,6 +10618,13 @@ func (ec *executionContext) marshalN__InputValue2ᚕgithubᚗcomᚋ99designsᚋg } wg.Wait() + + for _, e := range ret { + if e == graphql.Null { + return graphql.Null + } + } + return ret } @@ -10420,6 +10666,13 @@ func (ec *executionContext) marshalN__Type2ᚕgithubᚗcomᚋ99designsᚋgqlgen } wg.Wait() + + for _, e := range ret { + if e == graphql.Null { + return graphql.Null + } + } + return ret } @@ -10612,6 +10865,12 @@ func (ec *executionContext) marshalOString2ᚕstringᚄ(ctx context.Context, sel ret[i] = ec.marshalNString2string(ctx, sel, v[i]) } + for _, e := range ret { + if e == graphql.Null { + return graphql.Null + } + } + return ret } @@ -10712,6 +10971,13 @@ func (ec *executionContext) marshalO__EnumValue2ᚕgithubᚗcomᚋ99designsᚋgq } wg.Wait() + + for _, e := range ret { + if e == graphql.Null { + return graphql.Null + } + } + return ret } @@ -10752,6 +11018,13 @@ func (ec *executionContext) marshalO__Field2ᚕgithubᚗcomᚋ99designsᚋgqlgen } wg.Wait() + + for _, e := range ret { + if e == graphql.Null { + return graphql.Null + } + } + return ret } @@ -10792,6 +11065,13 @@ func (ec *executionContext) marshalO__InputValue2ᚕgithubᚗcomᚋ99designsᚋg } wg.Wait() + + for _, e := range ret { + if e == graphql.Null { + return graphql.Null + } + } + return ret } @@ -10839,6 +11119,13 @@ func (ec *executionContext) marshalO__Type2ᚕgithubᚗcomᚋ99designsᚋgqlgen } wg.Wait() + + for _, e := range ret { + if e == graphql.Null { + return graphql.Null + } + } + return ret } diff --git a/api/graph/model/models_gen.go b/api/graph/model/models_gen.go index baf9936..7f27b8d 100644 --- a/api/graph/model/models_gen.go +++ b/api/graph/model/models_gen.go @@ -48,6 +48,10 @@ type RepositoryCursor struct { Cursor *model.Cursor `json:"cursor"` } +type Settings struct { + SSHUser string `json:"sshUser"` +} + type Signature struct { Name string `json:"name"` Email string `json:"email"` @@ -78,6 +82,7 @@ type Version struct { Patch int `json:"patch"` DeprecationDate *time.Time `json:"deprecationDate"` Features *Features `json:"features"` + Settings *Settings `json:"settings"` } type AccessKind string diff --git a/api/graph/schema.graphqls b/api/graph/schema.graphqls index 1a4f95d..7c3374d 100644 --- a/api/graph/schema.graphqls +++ b/api/graph/schema.graphqls @@ -36,6 +36,9 @@ type Version { # Optional features features: Features! + + # Config settings + settings: Settings! } # Describes the status of optional features @@ -43,6 +46,11 @@ type Features { artifacts: Boolean! } +# Instance specific settings +type Settings { + sshUser: String! +} + enum AccessMode { # Read-only RO diff --git a/api/graph/schema.resolvers.go b/api/graph/schema.resolvers.go index ee00307..b7e1546 100644 --- a/api/graph/schema.resolvers.go +++ b/api/graph/schema.resolvers.go @@ -624,6 +624,9 @@ func (r *queryResolver) Version(ctx context.Context) (*model.Version, error) { bucket, _ := conf.Get("git.sr.ht", "s3-bucket") artifacts := upstream != "" && accessKey != "" && secretKey != "" && bucket != "" + sshUser, _ := conf.Get("git.sr.ht::dispatch", "/usr/bin/gitsrht-keys") + sshUser = strings.Split(sshUser, ":")[0] + return &model.Version{ Major: 0, Minor: 0, @@ -633,6 +636,10 @@ func (r *queryResolver) Version(ctx context.Context) (*model.Version, error) { Features: &model.Features{ Artifacts: artifacts, }, + + Settings: &model.Settings{ + SSHUser: sshUser, + }, }, nil } -- 2.38.4