-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #2 from getsynq/feature/examples
lineage example
- Loading branch information
Showing
13 changed files
with
138 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -21,7 +21,7 @@ jobs: | |
if: '!contains(github.event.commits[0].message, ''ci skip'')' | ||
runs-on: ubuntu-latest | ||
env: | ||
CI_COMMIT_MESSAGE: CI generated docs | ||
CI_COMMIT_MESSAGE: Generated API Docs | ||
CI_COMMIT_AUTHOR_NAME: Synqlair | ||
CI_COMMIT_AUTHOR_EMAIL: [email protected] | ||
steps: | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,2 @@ | ||
.vscode | ||
gen |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,118 @@ | ||
package main | ||
|
||
import ( | ||
"context" | ||
"encoding/json" | ||
"fmt" | ||
"log" | ||
"net/http" | ||
"net/url" | ||
"os" | ||
"strings" | ||
|
||
"google.golang.org/grpc" | ||
"google.golang.org/grpc/credentials/insecure" | ||
|
||
corev1 "github.com/getsynq/api/core/v1" | ||
schemasv1 "github.com/getsynq/api/schemas/v1" | ||
) | ||
|
||
const ( | ||
apiUrl = "https://api.synq.io/" | ||
clientId = os.Getenv("SYNQ_CLIENT_ID") | ||
clientSecret = os.Getenv("SYNQ_CLIENT_SECRET") | ||
) | ||
|
||
// Bearer authentication | ||
type bearerAuth struct { | ||
token string | ||
} | ||
|
||
// Convert user credentials to request metadata. | ||
func (b bearerAuth) GetRequestMetadata(ctx context.Context, in ...string) (map[string]string, error) { | ||
return map[string]string{ | ||
"authorization": "Bearer " + b.token, | ||
}, nil | ||
} | ||
|
||
// Specify whether channel security is required to pass these credentials. | ||
func (b bearerAuth) RequireTransportSecurity() bool { | ||
return false | ||
} | ||
|
||
func main() { | ||
// Configure credentials. | ||
token, err := getToken() | ||
if err != nil { | ||
panic(err) | ||
} | ||
fmt.Println(token) | ||
opts := []grpc.DialOption{ | ||
grpc.WithPerRPCCredentials(bearerAuth{ | ||
token: token, | ||
}), | ||
grpc.WithTransportCredentials(insecure.NewCredentials()), | ||
} | ||
|
||
conn, err := grpc.Dial(apiUrl, opts...) | ||
if err != nil { | ||
log.Fatalf("could not connect to server -> %+v", err) | ||
} | ||
|
||
client := schemasv1.NewLineageServiceClient(conn) | ||
|
||
// Fetch lineage. | ||
resp, err := client.GetLineage(context.Background(), &schemasv1.GetLineageRequest{ | ||
StartPoint: &schemasv1.GetLineageStartPoint{ | ||
From: &schemasv1.GetLineageStartPoint_Entities{ | ||
Entities: &schemasv1.EntitiesStartPoint{ | ||
Entities: []*corev1.EntityRef{ | ||
{ | ||
Path: "xxxxxxxxxxxxxxxxxxxxx", // replace with entity path | ||
Type: corev1.EntityType_ENTITY_TYPE_UNSPECIFIED, // replace with entity type | ||
}, | ||
}, | ||
}, | ||
}, | ||
}, | ||
}) | ||
if err != nil { | ||
log.Fatalf("error fetching lineage -> %v", err) | ||
} | ||
|
||
fmt.Printf("Lineage -> %+v", resp.Lineage) | ||
} | ||
|
||
func getToken() (string, error) { | ||
type oauth2Token struct { | ||
AccessToken string `json:"access_token"` | ||
} | ||
|
||
v := &url.Values{} | ||
v.Set("client_id", clientID) | ||
v.Set("client_secret", clientSecret) | ||
v.Set("grant_type", "client_credentials") | ||
|
||
req, err := http.NewRequest("POST", fmt.Sprintf("%soauth2/token", apiUrl), strings.NewReader(v.Encode())) | ||
if err != nil { | ||
return "", err | ||
} | ||
req.Header.Set("Content-Type", "application/x-www-form-urlencoded") | ||
|
||
client := &http.Client{} | ||
res, err := client.Do(req) | ||
if err != nil { | ||
return "", err | ||
} | ||
defer res.Body.Close() | ||
|
||
token := &oauth2Token{} | ||
if err := json.NewDecoder(res.Body).Decode(token); err != nil { | ||
return "", err | ||
} | ||
if res.StatusCode != http.StatusOK { | ||
return "", fmt.Errorf("error fetching token. status code %d", res.StatusCode) | ||
} | ||
|
||
return token.AccessToken, nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters