Skip to content

Commit e0586fe

Browse files
authored
fix: Add descriptions to JSON schema (#14647)
See invopop/jsonschema#112 (cloudquery/jsonschema#9) Blocked by cloudquery/codegen#60
1 parent 3e4d981 commit e0586fe

19 files changed

Lines changed: 1413 additions & 814 deletions

File tree

plugins/source/aws/Makefile

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,8 @@ gen-docs: build
4848

4949
.PHONY: gen-spec-schema
5050
gen-spec-schema:
51+
# required for loading comments from AWS SDK
52+
go mod vendor
5153
go run client/spec/gen/main.go
5254

5355
# All gen targets

plugins/source/aws/client/organizations.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,7 @@ func loadAccounts(ctx context.Context, awsPluginSpec *spec.Spec, accountsApi ser
8686

8787
accounts = append(accounts, spec.Account{
8888
ID: *account.Id,
89+
AccountName: aws.ToString(account.Name),
8990
RoleARN: roleArn.String(),
9091
RoleSessionName: awsPluginSpec.Organization.ChildAccountRoleSessionName,
9192
ExternalID: awsPluginSpec.Organization.ChildAccountExternalID,
@@ -98,7 +99,7 @@ func loadAccounts(ctx context.Context, awsPluginSpec *spec.Spec, accountsApi ser
9899
}
99100

100101
// Get Accounts for specific Organizational Units
101-
func getOUAccounts(ctx context.Context, accountsApi services.OrganizationsClient, awsOrg *spec.Org, region string) ([]orgTypes.Account, error) {
102+
func getOUAccounts(ctx context.Context, accountsApi services.OrganizationsClient, awsOrg *spec.Organization, region string) ([]orgTypes.Account, error) {
102103
q := awsOrg.OrganizationUnits
103104
var ou string
104105
var rawAccounts []orgTypes.Account
@@ -159,7 +160,7 @@ func getOUAccounts(ctx context.Context, accountsApi services.OrganizationsClient
159160
}
160161

161162
// Get All accounts in a specific organization
162-
func getAllAccounts(ctx context.Context, accountsApi services.OrganizationsClient, org *spec.Org, region string) ([]orgTypes.Account, error) {
163+
func getAllAccounts(ctx context.Context, accountsApi services.OrganizationsClient, org *spec.Organization, region string) ([]orgTypes.Account, error) {
163164
var rawAccounts []orgTypes.Account
164165
accountsPaginator := organizations.NewListAccountsPaginator(accountsApi, &organizations.ListAccountsInput{})
165166
for accountsPaginator.HasMorePages() {

plugins/source/aws/client/organizations_test.go

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,7 @@ func Test_loadAccounts(t *testing.T) {
119119
{
120120
name: "all_accounts",
121121
spec: &spec.Spec{
122-
Organization: &spec.Org{
122+
Organization: &spec.Organization{
123123
AdminAccount: &spec.Account{},
124124
},
125125
},
@@ -128,7 +128,7 @@ func Test_loadAccounts(t *testing.T) {
128128
{
129129
name: "all_accounts_with_skip_member_accounts",
130130
spec: &spec.Spec{
131-
Organization: &spec.Org{
131+
Organization: &spec.Organization{
132132
AdminAccount: &spec.Account{},
133133
SkipMemberAccounts: []string{"id-child2-account", "id-parent1-account", "id-parent2-account", "id-top-level-account"},
134134
},
@@ -138,7 +138,7 @@ func Test_loadAccounts(t *testing.T) {
138138
{
139139
name: "org_root",
140140
spec: &spec.Spec{
141-
Organization: &spec.Org{
141+
Organization: &spec.Organization{
142142
OrganizationUnits: []string{"root"},
143143
AdminAccount: &spec.Account{},
144144
},
@@ -148,7 +148,7 @@ func Test_loadAccounts(t *testing.T) {
148148
{
149149
name: "ou_parent1",
150150
spec: &spec.Spec{
151-
Organization: &spec.Org{
151+
Organization: &spec.Organization{
152152
OrganizationUnits: []string{"ou-parent1"},
153153
AdminAccount: &spec.Account{},
154154
},
@@ -158,7 +158,7 @@ func Test_loadAccounts(t *testing.T) {
158158
{
159159
name: "ou_parent1_and_parent2",
160160
spec: &spec.Spec{
161-
Organization: &spec.Org{
161+
Organization: &spec.Organization{
162162
OrganizationUnits: []string{"ou-parent1", "ou-parent2"},
163163
AdminAccount: &spec.Account{},
164164
},
@@ -168,7 +168,7 @@ func Test_loadAccounts(t *testing.T) {
168168
{
169169
name: "ou_parent1_skip_child1",
170170
spec: &spec.Spec{
171-
Organization: &spec.Org{
171+
Organization: &spec.Organization{
172172
OrganizationUnits: []string{"ou-parent1"},
173173
SkipMemberAccounts: []string{"id-child1-account"},
174174
AdminAccount: &spec.Account{},
@@ -179,7 +179,7 @@ func Test_loadAccounts(t *testing.T) {
179179
{
180180
name: "ou_root_skip_parent1",
181181
spec: &spec.Spec{
182-
Organization: &spec.Org{
182+
Organization: &spec.Organization{
183183
OrganizationUnits: []string{"root"},
184184
SkipOrganizationalUnits: []string{"ou-parent1"},
185185
AdminAccount: &spec.Account{},
@@ -190,7 +190,7 @@ func Test_loadAccounts(t *testing.T) {
190190
{
191191
name: "ou_root_skip_parent1",
192192
spec: &spec.Spec{
193-
Organization: &spec.Org{
193+
Organization: &spec.Organization{
194194
OrganizationUnits: []string{"root"},
195195
SkipOrganizationalUnits: []string{"ou-parent1"},
196196
AdminAccount: &spec.Account{},
@@ -201,7 +201,7 @@ func Test_loadAccounts(t *testing.T) {
201201
{
202202
name: "ou_root_and_parent1",
203203
spec: &spec.Spec{
204-
Organization: &spec.Org{
204+
Organization: &spec.Organization{
205205
OrganizationUnits: []string{"root", "ou-parent1"},
206206
SkipOrganizationalUnits: []string{},
207207
AdminAccount: &spec.Account{},

plugins/source/aws/client/spec/account.go

Lines changed: 39 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,45 @@
11
package spec
22

3+
// This is used to specify one or more accounts to extract information from.
34
type Account struct {
4-
ID string `json:"id" jsonschema:"required,minLength=1"`
5-
AccountName string `json:"account_name,omitempty"`
6-
LocalProfile string `json:"local_profile,omitempty"`
7-
RoleARN string `json:"role_arn,omitempty" jsonschema:"pattern=^arn(:[^:\n]*){5}([:/].*)?$"`
8-
RoleSessionName string `json:"role_session_name,omitempty"`
9-
ExternalID string `json:"external_id,omitempty"`
10-
DefaultRegion string `json:"default_region,omitempty"`
11-
Regions []string `json:"regions,omitempty" jsonschema:"minLength=1"`
5+
// Will be used as an alias in the source plugin and in the logs.
6+
ID string `json:"id" jsonschema:"required,minLength=1"`
7+
8+
// Will be used as an alias in the source plugin and in the logs.
9+
AccountName string `json:"account_name,omitempty"`
10+
11+
// [Local profile](https://docs.aws.amazon.com/cli/latest/userguide/cli-configure-files.html) to use to authenticate this account with.
12+
// Please note this should be set to the name of the profile.
13+
//
14+
// For example, with the following credentials file:
15+
//
16+
// ```ini copy
17+
// [default]
18+
// aws_access_key_id=xxxx
19+
// aws_secret_access_key=xxxx
20+
//
21+
// [user1]
22+
// aws_access_key_id=xxxx
23+
// aws_secret_access_key=xxxx
24+
// ```
25+
//
26+
// `local_profile` should be set to either `default` or `user1`.
27+
LocalProfile string `json:"local_profile,omitempty"`
28+
29+
// If specified will use this to assume role.
30+
RoleARN string `json:"role_arn,omitempty" jsonschema:"pattern=^(arn(:[^:\n]*){5}([:/].*)?)?$"`
31+
32+
// If specified will use this session name when assume role to `role_arn`.
33+
RoleSessionName string `json:"role_session_name,omitempty"`
34+
35+
// If specified will use this when assuming role to `role_arn`.
36+
ExternalID string `json:"external_id,omitempty"`
37+
38+
// If specified, this region will be used as the default region for the account.
39+
DefaultRegion string `json:"default_region,omitempty" jsonschema:"minLength=1,default=us-east-1"`
40+
41+
// Regions to use for this account. Defaults to global `regions` setting.
42+
Regions []string `json:"regions,omitempty" jsonschema:"minLength=1"`
1243

1344
// explicitly ignore in JSON parsing, as this is filled in later
1445
Source AccountSource `json:"-"`

0 commit comments

Comments
 (0)