Skip to content

Commit

Permalink
definitions: Auto inject http_client_options for all services (#321)
Browse files Browse the repository at this point in the history
Signed-off-by: Xuanwo <github@xuanwo.io>
  • Loading branch information
Xuanwo authored May 14, 2020
1 parent 4703949 commit 23b12df
Show file tree
Hide file tree
Showing 20 changed files with 131 additions and 111 deletions.
1 change: 0 additions & 1 deletion definitions/services/azblob.hcl
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ service {
}
op "new" {
required = ["credential", "endpoint"]
optional = ["http_client_options"]
}
}

Expand Down
1 change: 0 additions & 1 deletion definitions/services/cos.hcl
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ service {
}
op "new" {
required = ["credential"]
optional = ["http_client_options"]
}
}

Expand Down
2 changes: 1 addition & 1 deletion definitions/services/dropbox.hcl
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ storage {
}
op "new" {
required = ["credential"]
optional = ["http_client_options", "work_dir"]
optional = ["work_dir"]
}
op "read" {
optional = ["size"]
Expand Down
1 change: 0 additions & 1 deletion definitions/services/gcs.hcl
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ service {
}
op "new" {
required = ["credential", "project"]
optional = ["http_client_options"]
}
}

Expand Down
1 change: 0 additions & 1 deletion definitions/services/kodo.hcl
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ service {
}
op "new" {
required = ["credential"]
optional = ["http_client_options"]
}
}

Expand Down
1 change: 0 additions & 1 deletion definitions/services/oss.hcl
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ service {
}
op "new" {
required = ["credential", "endpoint"]
optional = ["http_client_options"]
}
}

Expand Down
2 changes: 1 addition & 1 deletion definitions/services/qingstor.hcl
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ service {
}
op "new" {
required = ["credential"]
optional = ["endpoint", "http_client_options"]
optional = ["endpoint"]
}
}

Expand Down
2 changes: 1 addition & 1 deletion definitions/services/s3.hcl
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ service {
}
op "new" {
required = ["credential"]
optional = ["endpoint", "http_client_options"]
optional = ["endpoint"]
}
}

Expand Down
2 changes: 1 addition & 1 deletion definitions/services/uss.hcl
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,6 @@ storage {
}
op "new" {
required = ["credential", "name"]
optional = ["http_client_options", "work_dir"]
optional = ["work_dir"]
}
}
24 changes: 24 additions & 0 deletions internal/cmd/definitions/parse.go
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,30 @@ func injectContext(ops []*Op) {
}
}

func injectHTTPClientOptions(srv *Service) {
// We don't need to inject http client into fs
if srv.Name == "fs" {
return
}

fn := func(ops []*Op) {
for _, op := range ops {
if op.Name != "new" {
continue
}
op.Generated = append(op.Generated, "http_client_options")
break
}
}

// If service exist, inject into service level; Or inject into storage level.
if len(srv.Service) > 0 {
fn(srv.Service)
} else {
fn(srv.Storage)
}
}

func parseHCL(src []byte, filename string, in interface{}) (err error) {
var diags hcl.Diagnostics
defer func() {
Expand Down
1 change: 1 addition & 0 deletions internal/cmd/definitions/type.go
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,7 @@ func (srv *Service) Handle() {
injectReadCallbackFunc(srv.Storage)
injectContext(srv.Service)
injectContext(srv.Storage)
injectHTTPClientOptions(srv)
return
}

Expand Down
20 changes: 10 additions & 10 deletions services/azblob/generated.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

20 changes: 10 additions & 10 deletions services/cos/generated.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

26 changes: 13 additions & 13 deletions services/dropbox/generated.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

20 changes: 10 additions & 10 deletions services/gcs/generated.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

20 changes: 10 additions & 10 deletions services/kodo/generated.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

1 comment on commit 23b12df

@vercel
Copy link

@vercel vercel bot commented on 23b12df May 14, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.