Skip to content

Commit

Permalink
feat: allow unspecified group fields (#47)
Browse files Browse the repository at this point in the history
  • Loading branch information
tenstad authored Dec 2, 2024
1 parent 455a5c6 commit 0293409
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 34 deletions.
24 changes: 12 additions & 12 deletions internal/sdk/cloudian/sdk.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,19 +19,19 @@ type Client struct {
}

type Group struct {
Active string `json:"active"`
Active *string `json:"active,omitempty"`
GroupID string `json:"groupId"`
GroupName string `json:"groupName"`
LDAPEnabled bool `json:"ldapEnabled"`
LDAPGroup string `json:"ldapGroup"`
LDAPMatchAttribute string `json:"ldapMatchAttribute"`
LDAPSearch string `json:"ldapSearch"`
LDAPSearchUserBase string `json:"ldapSearchUserBase"`
LDAPServerURL string `json:"ldapServerURL"`
LDAPUserDNTemplate string `json:"ldapUserDNTemplate"`
S3EndpointsHTTP []string `json:"s3endpointshttp"`
S3EndpointsHTTPS []string `json:"s3endpointshttps"`
S3WebSiteEndpoints []string `json:"s3websiteendpoints"`
GroupName *string `json:"groupName,omitempty"`
LDAPEnabled *bool `json:"ldapEnabled,omitempty"`
LDAPGroup *string `json:"ldapGroup,omitempty"`
LDAPMatchAttribute *string `json:"ldapMatchAttribute,omitempty"`
LDAPSearch *string `json:"ldapSearch,omitempty"`
LDAPSearchUserBase *string `json:"ldapSearchUserBase,omitempty"`
LDAPServerURL *string `json:"ldapServerURL,omitempty"`
LDAPUserDNTemplate *string `json:"ldapUserDNTemplate,omitempty"`
S3EndpointsHTTP []string `json:"s3endpointshttp,omitempty"`
S3EndpointsHTTPS []string `json:"s3endpointshttps,omitempty"`
S3WebSiteEndpoints []string `json:"s3websiteendpoints,omitempty"`
}

type User struct {
Expand Down
40 changes: 18 additions & 22 deletions internal/sdk/cloudian/sdk_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,6 @@ func TestRealisticGroupSerialization(t *testing.T) {
"groupId": "QA",
"groupName": "Quality Assurance Group",
"ldapEnabled": false,
"ldapGroup": "",
"ldapMatchAttribute": "",
"ldapSearch": "",
"ldapSearchUserBase": "",
"ldapServerURL": "",
"ldapUserDNTemplate": "",
"s3endpointshttp": ["ALL"],
"s3endpointshttps": ["ALL"],
"s3websiteendpoints": ["ALL"]
Expand Down Expand Up @@ -95,20 +89,22 @@ func TestUnmarshalUsers(t *testing.T) {
}

func (group Group) Generate(rand *rand.Rand, size int) reflect.Value {
active := "true"
ldapEnabled := true
return reflect.ValueOf(Group{
Active: "true",
GroupID: randomString(16),
Active: &active,
GroupID: *randomString(16),
GroupName: randomString(32),
LDAPEnabled: false,
LDAPEnabled: &ldapEnabled,
LDAPGroup: randomString(8),
LDAPMatchAttribute: "",
LDAPSearch: "",
LDAPSearchUserBase: "",
LDAPServerURL: "",
LDAPUserDNTemplate: "",
S3EndpointsHTTP: []string{"ALL"},
S3EndpointsHTTPS: []string{"ALL"},
S3WebSiteEndpoints: []string{"ALL"},
LDAPMatchAttribute: randomString(8),
LDAPSearch: randomString(8),
LDAPSearchUserBase: randomString(8),
LDAPServerURL: randomString(8),
LDAPUserDNTemplate: randomString(8),
S3EndpointsHTTP: []string{*randomString(8), *randomString(8)},
S3EndpointsHTTPS: []string{*randomString(8), *randomString(8)},
S3WebSiteEndpoints: []string{*randomString(8), *randomString(8)},
})
}

Expand Down Expand Up @@ -136,8 +132,7 @@ func TestGroupSerialization(t *testing.T) {
}

var deserialized Group
err = json.Unmarshal(data, &deserialized)
if err != nil {
if err = json.Unmarshal(data, &deserialized); err != nil {
return false
}

Expand All @@ -149,13 +144,14 @@ func TestGroupSerialization(t *testing.T) {
}
}

const charset = "abcdefghijklmnopqrstuvwxyzæøåABCDEFGHIJKLMNOPQRSTUVWXYZÆØÅ-. "
const charset = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789-_"

func randomString(length int) string {
func randomString(length int) *string {
var sb strings.Builder
runes := []rune(charset)
for i := 0; i < length; i++ {
sb.WriteRune(runes[rand.Intn(len(runes))])
}
return sb.String()
str := sb.String()
return &str
}

0 comments on commit 0293409

Please sign in to comment.