Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

go core libraries #716

Merged
merged 49 commits into from
Nov 1, 2021
Merged
Show file tree
Hide file tree
Changes from 47 commits
Commits
Show all changes
49 commits
Select commit Hold shift + click to select a range
14a5581
- adds azure identity go library
baywet Oct 13, 2021
ebe01ed
- adds http client implementation for go
baywet Oct 13, 2021
a24b364
- leverages reference to default factory for serialization in go requ…
baywet Oct 13, 2021
7684a1a
- adds workflows for go http and auth
baywet Oct 13, 2021
ca1a7c1
- adds json serialization writer for go
baywet Oct 14, 2021
5917fe7
- draft implementation of json parse node for go
baywet Oct 14, 2021
5d877ba
- draft implementation of json tree loading for go
baywet Oct 15, 2021
abd956f
- fixes content type detection for go response
baywet Oct 15, 2021
4882c6f
- fixes nullability on return types for go
baywet Oct 15, 2021
884932b
- adds readme for gson json serialization
baywet Oct 18, 2021
af6b1e6
- fixes an issue where go json serialization would attempt to seriali…
baywet Oct 19, 2021
fb5703c
- fixes parsable collections casting for go serialization
baywet Oct 19, 2021
9661630
- fixes a bug were objects serialization would be missing a comma for…
baywet Oct 19, 2021
2601e75
- fixes unit tests for go generation
baywet Oct 19, 2021
b6aff60
- adds changelog entry for go core libraries
baywet Oct 21, 2021
4f2cccf
- adds a telemetry handler for go
baywet Oct 21, 2021
d5e7c5e
- fixes telemetry handler definition
baywet Oct 21, 2021
42f8e9b
- fixes renamed merge reference
baywet Oct 22, 2021
f3df115
- renames the telemetry handler to make it more generic
baywet Oct 22, 2021
4d84c3e
- adds doc comment for go http
baywet Oct 22, 2021
20c1592
- fixes a bug where the middleware options would not be passed to the…
baywet Oct 22, 2021
e8b7a04
- fixes a bug where package name could contain invalid characters in go
baywet Oct 22, 2021
bf5eb1e
- fixes a bug where decimal would not be mapped
baywet Oct 25, 2021
48880ec
- fixes a typo in naming escpae in go
baywet Oct 25, 2021
98cdad8
- removes unecessary nil check in go
baywet Oct 25, 2021
c626f16
- adds vendor as a reserved name in go as using it as package name ca…
baywet Oct 25, 2021
fb48974
- adds doc comments to go abstractions
baywet Oct 25, 2021
0ea3018
- adds doc comment for go json and go azure
baywet Oct 25, 2021
50cc904
- fixes #746 adds support for go doc comment
baywet Oct 25, 2021
a3271fd
- adds clear instruction on pacakge feed for compliance
baywet Oct 25, 2021
5ca83a2
Revert "- adds clear instruction on pacakge feed for compliance"
baywet Oct 26, 2021
7b1a93d
- removes nuget.config files as they trigger the compliance analysis …
baywet Oct 26, 2021
9c6d907
- updates nuget config update script to generate the whole file
baywet Oct 26, 2021
f6d84f8
- fixes nuget config generation script
baywet Oct 27, 2021
e40949a
- fixes dotnet workflows for nuget.config cleanup
baywet Oct 27, 2021
7b73bc5
- fixes a bug where middleware chaining would not be done when the co…
baywet Oct 27, 2021
ca05f06
Update http/go/nethttp/middleware/callback_handler.go
baywet Oct 28, 2021
98b4c01
- revamps pipeline to leverage the transport approach
baywet Oct 28, 2021
e172356
- adds support for passing the options to middlewares
baywet Oct 28, 2021
e50c400
- adds retry handler for go
baywet Oct 28, 2021
bae0ac5
- fixes a bug where the retry handler would not exponentially backoff
baywet Oct 28, 2021
ae2719f
- addresses pull request feeback
baywet Oct 29, 2021
78d7b4e
- adds redirect handler to go http
baywet Oct 29, 2021
136126a
- fixes a bug where request options would not expand for go
baywet Oct 29, 2021
6335f62
- switches to request option wrapper object for Go generation
baywet Oct 29, 2021
2360279
Merge branch 'main' into feature/go-auth
baywet Nov 1, 2021
5032c16
- adds doc comments for retry and redirect handlers
baywet Nov 1, 2021
a142eb3
- updates parameters names to make it explicit
baywet Nov 1, 2021
783f4ea
- typo fix
baywet Nov 1, 2021
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/abstractions-go.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ jobs:
- uses: actions/checkout@v2.3.5
- uses: actions/setup-go@v2
with:
go-version: '^1.16.6'
go-version: '^1.17.2'
- name: Install dependencies
run: go install
working-directory: ${{ env.relativePath }}
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/authentication-dotnet-azure.yml
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ jobs:
name: drop
path: |
${{ env.relativePath }}/src/bin/Release/*.nupkg
- run: git checkout ${{ env.relativePath }}/nuget.config
- run: rm ${{ env.relativePath }}/nuget.config
if: always()
deploy:
if: ${{ github.event_name == 'push' && github.ref == 'refs/heads/main' }}
Expand Down
26 changes: 26 additions & 0 deletions .github/workflows/authentication-go-azure.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
name: Go Authentication Azure

on:
workflow_dispatch:
push:
branches: [ main ]
paths: ['authentication/go/azure/**', '.github/workflows/**']
pull_request:
paths: ['authentication/go/azure/**', '.github/workflows/**']

jobs:
build:
runs-on: ubuntu-latest
env:
relativePath: ./authentication/go/azure
steps:
- uses: actions/checkout@v2.3.4
- uses: actions/setup-go@v2
with:
go-version: '^1.17.2'
- name: Install dependencies
run: go install
working-directory: ${{ env.relativePath }}
- name: Build SDK project
run: go build
working-directory: ${{ env.relativePath }}
2 changes: 1 addition & 1 deletion .github/workflows/http-dotnet-httpclient.yml
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ jobs:
name: drop
path: |
${{ env.relativePath }}/src/bin/Release/*.nupkg
- run: git checkout ${{ env.relativePath }}/nuget.config
- run: rm ${{ env.relativePath }}/nuget.config
if: always()
deploy:
if: ${{ github.event_name == 'push' && github.ref == 'refs/heads/main' }}
Expand Down
26 changes: 26 additions & 0 deletions .github/workflows/http-go-nethttp.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
name: Go Http NetHttp

on:
workflow_dispatch:
push:
branches: [ main ]
paths: ['http/go/nethttp/**', '.github/workflows/**']
pull_request:
paths: ['http/go/nethttp/**', '.github/workflows/**']

jobs:
build:
runs-on: ubuntu-latest
env:
relativePath: ./http/go/nethttp
steps:
- uses: actions/checkout@v2.3.4
- uses: actions/setup-go@v2
with:
go-version: '^1.17.2'
- name: Install dependencies
run: go install
working-directory: ${{ env.relativePath }}
- name: Build SDK project
run: go build
working-directory: ${{ env.relativePath }}
2 changes: 1 addition & 1 deletion .github/workflows/serialization-dotnet-json.yml
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ jobs:
name: drop
path: |
${{ env.relativePath }}/src/bin/Release/*.nupkg
- run: git checkout ${{ env.relativePath }}/nuget.config
- run: rm ${{ env.relativePath }}/nuget.config
if: always()
deploy:
if: ${{ github.event_name == 'push' && github.ref == 'refs/heads/main' }}
Expand Down
29 changes: 29 additions & 0 deletions .github/workflows/serialization-go-json.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
name: Go Serialization Json

on:
workflow_dispatch:
push:
branches: [ main ]
paths: ['serialization/go/json/**', '.github/workflows/**']
pull_request:
paths: ['serialization/go/json/**', '.github/workflows/**']

jobs:
build:
runs-on: ubuntu-latest
env:
relativePath: ./serialization/go/json
steps:
- uses: actions/checkout@v2.3.4
- uses: actions/setup-go@v2
with:
go-version: '^1.17.2'
- name: Install dependencies
run: go install
working-directory: ${{ env.relativePath }}
- name: Build SDK project
run: go build
working-directory: ${{ env.relativePath }}
- name: Run unit tests
run: go test
working-directory: ${{ env.relativePath }}
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

### Added

- Adds Go authentication, http and serialization libraries and finalizes the generation #716

### Changed

## [0.0.11] - 2021-10-27
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ The following table provides an overview of the languages supported by Kiota and
| Language | Generation | Abstractions | Serialization | Authentication | HTTP | Required tools & dependencies |
| -------- | ---------- | ------------ | ------------- | -------------- | ---- | -------------- |
| CSharp | [✔](https://github.com/microsoft/kiota/projects/5) | [✔](./abstractions/dotnet) | [JSON](./serialization/dotnet/json) | [Anonymous](./abstractions/dotnet/src/authentication/AnonymousAuthenticationProvider.cs), [Azure](./authentication/dotnet/azure) | [✔](./http/dotnet/httpclient) | [link](./docs/requiredtools/dotnet.md) |
| Go | [✔](https://github.com/microsoft/kiota/projects/8) | [✔](./abstractions/go) | | | | [link](./docs/requiredtools/go.md) |
| Go | [✔](https://github.com/microsoft/kiota/projects/8) | [✔](./abstractions/go) | [Azure](./authentication/go/azure) | [✔](./http/go/nethttp) | [JSON](./serialization/go/json) | [link](./docs/requiredtools/go.md) |
| Java | [✔](https://github.com/microsoft/kiota/projects/7) | [✔](./abstractions/java) | [JSON](./serialization/java/json) | [Anonymous](./abstractions/java/lib/src/main/java/com/microsoft/kiota/authentication/AnonymousAuthenticationProvider.java), [Azure](./authentication/java/azure) | [✔](./http/java/okhttp) | [link](./docs/requiredtools/java.md) |
| PHP | [❌](https://github.com/microsoft/kiota/projects/4) | [▶](https://github.com/microsoft/kiota/pull/321) | ❌ | ❌ | ❌ | |
| Python | [❌](https://github.com/microsoft/kiota/projects/3) | ❌ | ❌ | ❌ | ❌ | |
Expand Down
3 changes: 3 additions & 0 deletions abstractions/go/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@
![Go](https://github.com/microsoft/kiota/actions/workflows/abstractions-go.yml/badge.svg)

- [ ] unit tests
- [ ] move to its own repo and implement [the guidelines](https://golang.org/doc/#developing-modules) to make referencing the module easier
- [ ] add doc.go
- [ ] rename module name, update reference and remove the replace directive

## Using the abstractions

Expand Down
6 changes: 6 additions & 0 deletions abstractions/go/api_client_builder.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@ import (
s "github.com/microsoft/kiota/abstractions/go/serialization"
)

// Registers the default serializer to the registry.
// Parameters:
// metaFactory: the factory function that creates the serialization writer factory.
func RegisterDefaultSerializer(metaFactory func() s.SerializationWriterFactory) {
factory := metaFactory()
contentType, err := factory.GetValidContentType()
Expand All @@ -12,6 +15,9 @@ func RegisterDefaultSerializer(metaFactory func() s.SerializationWriterFactory)
}
}

// Registers the default deserializer to the registry.
// Parameters:
// metaFactory: the factory function that creates the serialization reader factory.
func RegisterDefaultDeserializer(metaFactory func() s.ParseNodeFactory) {
factory := metaFactory()
contentType, err := factory.GetValidContentType()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,15 @@ package authentication

import abs "github.com/microsoft/kiota/abstractions/go"

// This authentication provider does not perform any authentication.
type AnonymousAuthenticationProvider struct {
}

func (provider *AnonymousAuthenticationProvider) Authenticate(request abs.RequestInformation) error {
// Authenticates the Request information instance
// Parameters:
// request: Request information instance
// Returns:
// error: nil if authentication is successful, otherwise an error
func (provider *AnonymousAuthenticationProvider) AuthenticateRequest(request abs.RequestInformation) error {
return nil
}
8 changes: 7 additions & 1 deletion abstractions/go/authentication/authentication_provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,12 @@ import (
abs "github.com/microsoft/kiota/abstractions/go"
)

// Authenticates the application request.
type AuthenticationProvider interface {
Authenticate(request abs.RequestInformation) error
// Authenticates the Request information instance
// Parameters:
// request: Request information instance
// Returns:
// error: nil if authentication is successful, otherwise an error
AuthenticateRequest(request abs.RequestInformation) error
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,28 +8,45 @@ import (

const authorizationHeader = "Authorization"

// Provides a base class for implementing AuthenticationProvider for Bearer token scheme.
type BaseBearerTokenAuthenticationProvider struct {
// This method is called by the BaseBearerTokenAuthenticationProvider class to authenticate the request via the returned access token.
// Parameters:
// request: Request information instance
// Returns:
// string: Access token
// error: nil if authentication is successful, otherwise an error
getAuthorizationToken func(request abs.RequestInformation) (string, error)
}

// Creates a new instance of the BaseBearerTokenAuthenticationProvider class.
// Parameters:
// getAuthorizationToken: This method is called by the BaseBearerTokenAuthenticationProvider class to authenticate the request via the returned access token.
// Returns:
// *BaseBearerTokenAuthenticationProvider: A new instance of the BaseBearerTokenAuthenticationProvider class.
func NewBaseBearerTokenAuthenticationProvider(getAuthorizationToken func(request abs.RequestInformation) (string, error)) *BaseBearerTokenAuthenticationProvider {
return &BaseBearerTokenAuthenticationProvider{getAuthorizationToken}
}

func (provider *BaseBearerTokenAuthenticationProvider) Authenticate(request abs.RequestInformation) error {
// Authenticates the Request information instance
// Parameters:
// request: Request information instance
// Returns:
// error: nil if authentication is successful, otherwise an error
func (provider *BaseBearerTokenAuthenticationProvider) AuthenticateRequest(request abs.RequestInformation) error {
andrueastman marked this conversation as resolved.
Show resolved Hide resolved
if request.Headers == nil {
request.Headers = make(map[string]string)
}
if provider.getAuthorizationToken == nil {
return errors.New("This class is abstract, you need to derive from it and implement the GetAuthorizationToken method.")
return errors.New("this class is abstract, you need to derive from it and implement the GetAuthorizationToken method.")
}
if request.Headers[authorizationHeader] == "" {
token, err := provider.getAuthorizationToken(request)
if err != nil {
return err
}
if token == "" {
return errors.New("Could not get an authorization token")
return errors.New("could not get an authorization token")
}
request.Headers[authorizationHeader] = "Bearer " + token
}
Expand Down
11 changes: 11 additions & 0 deletions abstractions/go/http_method.go
Original file line number Diff line number Diff line change
@@ -1,19 +1,30 @@
package abstractions

// Represents the HTTP method used by a request.
type HttpMethod int

const (
// The HTTP GET method.
GET HttpMethod = iota
// The HTTP POST method.
POST
// The HTTP PATCH method.
PATCH
// The HTTP DELETE method.
DELETE
// The HTTP OPTIONS method.
OPTIONS
// The HTTP CONNECT method.
CONNECT
// The HTTP PUT method.
PUT
// The HTTP TRACE method.
TRACE
// The HTTP HEAD method.
HEAD
)

// Returns the string representation of the HTTP method.
func (m HttpMethod) String() string {
return []string{"GET", "POST", "PATCH", "DELETE", "OPTIONS", "CONNECT", "PUT", "TRACE", "HEAD"}[m]
}
6 changes: 6 additions & 0 deletions abstractions/go/query_parameters_base.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,15 @@ import (
"reflect"
)

// The base implementation of the Query Parameters
type QueryParametersBase struct {
}

// Vanity method to add the query parameters to the request query parameters dictionary.
// Parameters:
// - target: The target map to add the query parameters to.
// Returns:
// - error: An error if the target is nil.
func (p *QueryParametersBase) AddQueryParameters(target map[string]string) error {
if target == nil {
return errors.New("target cannot be nil")
Expand Down
55 changes: 49 additions & 6 deletions abstractions/go/request_adapter.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,55 @@ import (
s "github.com/microsoft/kiota/abstractions/go/serialization"
)

// Service responsible for translating abstract Request Info into concrete native HTTP requests.
type RequestAdapter interface {
SendAsync(requestInfo RequestInformation, constructor func() s.Parsable, responseHandler ResponseHandler) func() (s.Parsable, error)
SendCollectionAsync(requestInfo RequestInformation, constructor func() s.Parsable, responseHandler ResponseHandler) func() ([]s.Parsable, error)
SendPrimitiveAsync(requestInfo RequestInformation, typeName string, responseHandler ResponseHandler) func() (interface{}, error)
SendPrimitiveCollectionAsync(requestInfo RequestInformation, typeName string, responseHandler ResponseHandler) func() ([]interface{}, error)
SendNoContentAsync(requestInfo RequestInformation, responseHandler ResponseHandler) func() error
GetSerializationWriterFactory() (s.SerializationWriterFactory, error)
// Executes the HTTP request specified by the given RequestInformation and returns the deserialized response model.
// Parameters:
// - requestInfo: The RequestInformation object to use for the HTTP request.
// - constuctor: The factory for the result Parsable object
// - responseHandler: The response handler to use for the HTTP request instead of the default handler.
// Returns:
// - The deserialized response model.
// - An error if any.
SendAsync(requestInfo RequestInformation, constructor func() s.Parsable, responseHandler ResponseHandler) (s.Parsable, error)
// Executes the HTTP request specified by the given RequestInformation and returns the deserialized response model collection.
// Parameters:
// - requestInfo: The RequestInformation object to use for the HTTP request.
// - constuctor: The factory for the result Parsable object
// - responseHandler: The response handler to use for the HTTP request instead of the default handler.
// Returns:
// - The deserialized response model collection.
// - An error if any.
SendCollectionAsync(requestInfo RequestInformation, constructor func() s.Parsable, responseHandler ResponseHandler) ([]s.Parsable, error)
// Executes the HTTP request specified by the given RequestInformation and returns the deserialized primitive response model.
// Parameters:
// - requestInfo: The RequestInformation object to use for the HTTP request.
// - typeName: The type name of the response model.
// - responseHandler: The response handler to use for the HTTP request instead of the default handler.
// Returns:
// - The deserialized response model.
// - An error if any.
SendPrimitiveAsync(requestInfo RequestInformation, typeName string, responseHandler ResponseHandler) (interface{}, error)
// Executes the HTTP request specified by the given RequestInformation and returns the deserialized primitive response model collection.
// Parameters:
// - requestInfo: The RequestInformation object to use for the HTTP request.
// - typeName: The type name of the response model.
// - responseHandler: The response handler to use for the HTTP request instead of the default handler.
// Returns:
// - The deserialized response model collection.
// - An error if any.
SendPrimitiveCollectionAsync(requestInfo RequestInformation, typeName string, responseHandler ResponseHandler) ([]interface{}, error)
// Executes the HTTP request specified by the given RequestInformation with no return content.
// Parameters:
// - requestInfo: The RequestInformation object to use for the HTTP request.
// - responseHandler: The response handler to use for the HTTP request instead of the default handler.
// Returns:
// - An error if any.
SendNoContentAsync(requestInfo RequestInformation, responseHandler ResponseHandler) error
// Gets the serialization writer factory currently in use for the request adapter service.
// Returns:
// - The serialization writer factory currently in use for the request adapter service.
GetSerializationWriterFactory() s.SerializationWriterFactory
// Enables the backing store proxies for the SerializationWriters and ParseNodes in use.
EnableBackingStore()
}
Loading