Add new auth method to source (#2132)

This commit is contained in:
Dustin Decker 2023-11-28 10:58:11 -08:00 committed by GitHub
parent d552222385
commit ede0c39589
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 1017 additions and 960 deletions

File diff suppressed because it is too large Load diff

View file

@ -200,6 +200,186 @@ var _ interface {
ErrorName() string
} = LocalSourceValidationError{}
// Validate checks the field values on Artifactory with the rules defined in
// the proto definition for this message. If any rules are violated, the first
// error encountered is returned, or nil if there are no violations.
func (m *Artifactory) Validate() error {
return m.validate(false)
}
// ValidateAll checks the field values on Artifactory with the rules defined in
// the proto definition for this message. If any rules are violated, the
// result is a list of violation errors wrapped in ArtifactoryMultiError, or
// nil if none found.
func (m *Artifactory) ValidateAll() error {
return m.validate(true)
}
func (m *Artifactory) validate(all bool) error {
if m == nil {
return nil
}
var errors []error
if _, err := url.Parse(m.GetEndpoint()); err != nil {
err = ArtifactoryValidationError{
field: "Endpoint",
reason: "value must be a valid URI",
cause: err,
}
if !all {
return err
}
errors = append(errors, err)
}
switch m.Credential.(type) {
case *Artifactory_BasicAuth:
if all {
switch v := interface{}(m.GetBasicAuth()).(type) {
case interface{ ValidateAll() error }:
if err := v.ValidateAll(); err != nil {
errors = append(errors, ArtifactoryValidationError{
field: "BasicAuth",
reason: "embedded message failed validation",
cause: err,
})
}
case interface{ Validate() error }:
if err := v.Validate(); err != nil {
errors = append(errors, ArtifactoryValidationError{
field: "BasicAuth",
reason: "embedded message failed validation",
cause: err,
})
}
}
} else if v, ok := interface{}(m.GetBasicAuth()).(interface{ Validate() error }); ok {
if err := v.Validate(); err != nil {
return ArtifactoryValidationError{
field: "BasicAuth",
reason: "embedded message failed validation",
cause: err,
}
}
}
case *Artifactory_AccessToken:
// no validation rules for AccessToken
case *Artifactory_Unauthenticated:
if all {
switch v := interface{}(m.GetUnauthenticated()).(type) {
case interface{ ValidateAll() error }:
if err := v.ValidateAll(); err != nil {
errors = append(errors, ArtifactoryValidationError{
field: "Unauthenticated",
reason: "embedded message failed validation",
cause: err,
})
}
case interface{ Validate() error }:
if err := v.Validate(); err != nil {
errors = append(errors, ArtifactoryValidationError{
field: "Unauthenticated",
reason: "embedded message failed validation",
cause: err,
})
}
}
} else if v, ok := interface{}(m.GetUnauthenticated()).(interface{ Validate() error }); ok {
if err := v.Validate(); err != nil {
return ArtifactoryValidationError{
field: "Unauthenticated",
reason: "embedded message failed validation",
cause: err,
}
}
}
}
if len(errors) > 0 {
return ArtifactoryMultiError(errors)
}
return nil
}
// ArtifactoryMultiError is an error wrapping multiple validation errors
// returned by Artifactory.ValidateAll() if the designated constraints aren't met.
type ArtifactoryMultiError []error
// Error returns a concatenation of all the error messages it wraps.
func (m ArtifactoryMultiError) Error() string {
var msgs []string
for _, err := range m {
msgs = append(msgs, err.Error())
}
return strings.Join(msgs, "; ")
}
// AllErrors returns a list of validation violation errors.
func (m ArtifactoryMultiError) AllErrors() []error { return m }
// ArtifactoryValidationError is the validation error returned by
// Artifactory.Validate if the designated constraints aren't met.
type ArtifactoryValidationError struct {
field string
reason string
cause error
key bool
}
// Field function returns field value.
func (e ArtifactoryValidationError) Field() string { return e.field }
// Reason function returns reason value.
func (e ArtifactoryValidationError) Reason() string { return e.reason }
// Cause function returns cause value.
func (e ArtifactoryValidationError) Cause() error { return e.cause }
// Key function returns key value.
func (e ArtifactoryValidationError) Key() bool { return e.key }
// ErrorName returns error name.
func (e ArtifactoryValidationError) ErrorName() string { return "ArtifactoryValidationError" }
// Error satisfies the builtin error interface
func (e ArtifactoryValidationError) Error() string {
cause := ""
if e.cause != nil {
cause = fmt.Sprintf(" | caused by: %v", e.cause)
}
key := ""
if e.key {
key = "key for "
}
return fmt.Sprintf(
"invalid %sArtifactory.%s: %s%s",
key,
e.field,
e.reason,
cause)
}
var _ error = ArtifactoryValidationError{}
var _ interface {
Field() string
Reason() string
Key() bool
Cause() error
ErrorName() string
} = ArtifactoryValidationError{}
// Validate checks the field values on AzureStorage with the rules defined in
// the proto definition for this message. If any rules are violated, the first
// error encountered is returned, or nil if there are no violations.
@ -3904,155 +4084,6 @@ var _ interface {
ErrorName() string
} = TeamsValidationError{}
// Validate checks the field values on Artifactory with the rules defined in
// the proto definition for this message. If any rules are violated, the first
// error encountered is returned, or nil if there are no violations.
func (m *Artifactory) Validate() error {
return m.validate(false)
}
// ValidateAll checks the field values on Artifactory with the rules defined in
// the proto definition for this message. If any rules are violated, the
// result is a list of violation errors wrapped in ArtifactoryMultiError, or
// nil if none found.
func (m *Artifactory) ValidateAll() error {
return m.validate(true)
}
func (m *Artifactory) validate(all bool) error {
if m == nil {
return nil
}
var errors []error
if _, err := url.Parse(m.GetEndpoint()); err != nil {
err = ArtifactoryValidationError{
field: "Endpoint",
reason: "value must be a valid URI",
cause: err,
}
if !all {
return err
}
errors = append(errors, err)
}
switch m.Credential.(type) {
case *Artifactory_BasicAuth:
if all {
switch v := interface{}(m.GetBasicAuth()).(type) {
case interface{ ValidateAll() error }:
if err := v.ValidateAll(); err != nil {
errors = append(errors, ArtifactoryValidationError{
field: "BasicAuth",
reason: "embedded message failed validation",
cause: err,
})
}
case interface{ Validate() error }:
if err := v.Validate(); err != nil {
errors = append(errors, ArtifactoryValidationError{
field: "BasicAuth",
reason: "embedded message failed validation",
cause: err,
})
}
}
} else if v, ok := interface{}(m.GetBasicAuth()).(interface{ Validate() error }); ok {
if err := v.Validate(); err != nil {
return ArtifactoryValidationError{
field: "BasicAuth",
reason: "embedded message failed validation",
cause: err,
}
}
}
case *Artifactory_AccessToken:
// no validation rules for AccessToken
}
if len(errors) > 0 {
return ArtifactoryMultiError(errors)
}
return nil
}
// ArtifactoryMultiError is an error wrapping multiple validation errors
// returned by Artifactory.ValidateAll() if the designated constraints aren't met.
type ArtifactoryMultiError []error
// Error returns a concatenation of all the error messages it wraps.
func (m ArtifactoryMultiError) Error() string {
var msgs []string
for _, err := range m {
msgs = append(msgs, err.Error())
}
return strings.Join(msgs, "; ")
}
// AllErrors returns a list of validation violation errors.
func (m ArtifactoryMultiError) AllErrors() []error { return m }
// ArtifactoryValidationError is the validation error returned by
// Artifactory.Validate if the designated constraints aren't met.
type ArtifactoryValidationError struct {
field string
reason string
cause error
key bool
}
// Field function returns field value.
func (e ArtifactoryValidationError) Field() string { return e.field }
// Reason function returns reason value.
func (e ArtifactoryValidationError) Reason() string { return e.reason }
// Cause function returns cause value.
func (e ArtifactoryValidationError) Cause() error { return e.cause }
// Key function returns key value.
func (e ArtifactoryValidationError) Key() bool { return e.key }
// ErrorName returns error name.
func (e ArtifactoryValidationError) ErrorName() string { return "ArtifactoryValidationError" }
// Error satisfies the builtin error interface
func (e ArtifactoryValidationError) Error() string {
cause := ""
if e.cause != nil {
cause = fmt.Sprintf(" | caused by: %v", e.cause)
}
key := ""
if e.key {
key = "key for "
}
return fmt.Sprintf(
"invalid %sArtifactory.%s: %s%s",
key,
e.field,
e.reason,
cause)
}
var _ error = ArtifactoryValidationError{}
var _ interface {
Field() string
Reason() string
Key() bool
Cause() error
ErrorName() string
} = ArtifactoryValidationError{}
// Validate checks the field values on Syslog with the rules defined in the
// proto definition for this message. If any rules are violated, the first
// error encountered is returned, or nil if there are no violations.

View file

@ -62,6 +62,19 @@ message LocalSource {
string scan_period = 6;
}
// https://www.jfrog.com/confluence/display/JFROG/Artifactory+REST+API#ArtifactoryRESTAPI-RetrieveFolderorRepositoryArchive
message Artifactory {
string endpoint = 1 [(validate.rules).string.uri_ref = true];
oneof credential {
credentials.BasicAuth basic_auth = 2;
string access_token = 3;
credentials.Unauthenticated unauthenticated = 7;
}
repeated string repositories = 4;
repeated string include_paths = 5;
repeated string ignore_paths = 6;
}
message AzureStorage {
oneof credential {
string connection_string = 1;
@ -306,18 +319,6 @@ message Teams {
repeated string team_ids = 6;
}
// https://www.jfrog.com/confluence/display/JFROG/Artifactory+REST+API#ArtifactoryRESTAPI-RetrieveFolderorRepositoryArchive
message Artifactory {
string endpoint = 1 [(validate.rules).string.uri_ref = true];
oneof credential {
credentials.BasicAuth basic_auth = 2;
string access_token = 3;
}
repeated string repositories = 4;
repeated string include_paths = 5;
repeated string ignore_paths = 6;
}
message Syslog {
string protocol = 1;
string listenAddress = 2;