Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
6 changes: 6 additions & 0 deletions commonutils/logwrapper/logger.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ package logger

import "github.com/sirupsen/logrus"

// Supported log levels.
type LogLevel int

const (
Expand All @@ -24,22 +25,27 @@ func init() {
log.SetLevel(logrus.ErrorLevel)
}

// Internal
func Debug(args ...interface{}) {
log.Debug(args...)
}

// Internal
func Info(args ...interface{}) {
log.Info(args...)
}

// Internal
func Warn(args ...interface{}) {
log.Warn(args...)
}

// Internal
func Error(args ...interface{}) {
log.Error(args...)
}

// Sets the logging level for the application. Defaults to `ERROR`.
func SetLogLevel(level LogLevel) {
switch level {
case INFO:
Expand Down
144 changes: 144 additions & 0 deletions processMarkdown.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,144 @@
package main

import (
"fmt"
"io/ioutil"
"regexp"
"strings"
)

func main() {
// Read the markdown file
files := []string{"client", "common", "logger", "util", "vaultapi"}

for _, filename := range files {
file := "docs/" + filename + ".md"
data, err := ioutil.ReadFile(file)
if err != nil {
fmt.Println("Error reading file:", err)
return
}
// fmt.Println(data)
// Convert byte data to string
markdown := string(data)

markdown = "{% env enable=\"goSdkRef\" %}\n\n" + markdown

// Remove import statement
markdown = removeImportStatement(markdown)

// Remove copyright statement
markdown = removeCopyrightStatement(markdown)

// Remove functions with Deprecated description
markdown = removeDeprecatedOrInternal(markdown)

// Represent type as h2
markdown = changeTypeHeading(markdown)

// Represent functions as h3
markdown = changeFuncHeading(markdown)

// Remove multiple empty lines
markdown = removeMultipleEmptyLines(markdown)

markdown = markdown + "\n{% /env %}"

// Write the modified markdown back to the file
err = ioutil.WriteFile(file, []byte(markdown), 0644)
if err != nil {
fmt.Println("Error writing file:", err)
return
}
}

fmt.Println("Markdown files updated successfully.")

}

func removeImportStatement(markdown string) string {
// Use regex to match and remove import statement
importRegex := regexp.MustCompile(`--\n\s*import\s+"."\n`)
markdown = importRegex.ReplaceAllString(markdown, "")

return markdown
}

func removeCopyrightStatement(markdown string) string {
// Use regex to match and remove copyright statement
copyrightRegex := regexp.MustCompile(`\s*Copyright.*`)
markdown = copyrightRegex.ReplaceAllString(markdown, "")

return markdown
}

// func removeDeprecatedFunctions(markdown string) string {
// // Regular expression pattern to match the deprecated functions
// pattern := regexp.MustCompile(`(?s)(?m)#### func\s*((?!#### func).)*?Deprecated.*?\n\n`)
// return pattern.ReplaceAllString(markdown, "")
// }

func sum(arr []int) int {
sum := 0
for _, valueInt := range arr {
sum += valueInt
}
return sum
}

func removeDeprecatedOrInternal(markdown string) string {
lines := strings.Split(markdown, "\n")
var result []string
var temp []int
startIndex := 0
endIndex := 0
for i, line := range lines {
if strings.HasPrefix(line, "#### func") {
startIndex = i
} else if strings.HasPrefix(line, "#### type") {
startIndex = i
} else if strings.HasPrefix(line, "Deprecated") {
endIndex = i
} else if strings.HasPrefix(line, "Internal") {
endIndex = i
}

result = append(result, line)
if startIndex > 0 && endIndex > 0 {
result = append(result[:startIndex-(sum(temp)+1)])
temp = append(temp, (endIndex-startIndex)+1)
startIndex = 0
endIndex = 0
}
}

return strings.Join(result, "\n")
}

func changeTypeHeading(markdown string) string {
// Regular expression pattern to match type headings (h4)
pattern := regexp.MustCompile(`#### type`)

// Replace type heading (h4) with h2
return pattern.ReplaceAllStringFunc(markdown, func(match string) string {
return strings.Replace(match, "####", "##", 1)
})
}

func changeFuncHeading(markdown string) string {
// Regular expression pattern to match func headings (h4)
pattern := regexp.MustCompile(`#### func`)

// Replace func heading (h4) with h3
return pattern.ReplaceAllStringFunc(markdown, func(match string) string {
return strings.Replace(match, "####", "###", 1)
})
}

func removeMultipleEmptyLines(markdown string) string {
// Regular expression pattern to match multiple empty lines
pattern := regexp.MustCompile(`\n{2,}`)

// Replace multiple empty lines with a single empty line
return pattern.ReplaceAllString(markdown, "\n\n")
}
7 changes: 5 additions & 2 deletions serviceaccount/util/token.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import (
"github.com/skyflowapi/skyflow-go/skyflow/common"
)

// Represents the structure for a response containing an access token and its type.
type ResponseToken struct {
AccessToken string `json:"accessToken"`
TokenType string `json:tokenType`
Expand All @@ -35,7 +36,7 @@ func GenerateToken(filePath string) (*ResponseToken, *errors.SkyflowError) {
return GenerateBearerToken(filePath)
}

// GenerateBearerToken - Generates a Service Account Token from the given Service Account Credential file with a default timeout of 60minutes.
// Generates a service account token from the given service account credential file with a default timeout of 60 minutes.
func GenerateBearerToken(filePath string) (*ResponseToken, *errors.SkyflowError) {
var key map[string]interface{}

Expand Down Expand Up @@ -66,6 +67,7 @@ func GenerateBearerToken(filePath string) (*ResponseToken, *errors.SkyflowError)
return token, nil
}

// Generates a service account token from the given service account credential JSON string.
func GenerateBearerTokenFromCreds(credentials string) (*ResponseToken, *errors.SkyflowError) {

credsMap := make(map[string]interface{})
Expand All @@ -83,7 +85,7 @@ func GenerateBearerTokenFromCreds(credentials string) (*ResponseToken, *errors.S
return token, nil
}

// getSATokenFromCredsFile gets bearer token from service account endpoint
// Gets bearer token from service account credentials file.
func getSATokenFromCredsFile(key map[string]interface{}) (*ResponseToken, *errors.SkyflowError) {

privateKey := key["privateKey"]
Expand Down Expand Up @@ -234,6 +236,7 @@ func IsValid(tokenString string) bool {
return !IsExpired(tokenString)
}

// Checks if the provided service account token has expired.
func IsExpired(tokenString string) bool {
if tokenString == "" {
logger.Info(fmt.Sprintf(messages.EMPTY_BEARER_TOKEN, "ServiceAccountUtil"))
Expand Down
5 changes: 5 additions & 0 deletions skyflow/client/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import (
vaultapi "github.com/skyflowapi/skyflow-go/skyflow/vaultapi"
)

// Represents a client instance that interacts with Skyflow's APIs.
type Client struct {
configuration common.Configuration
}
Expand All @@ -22,6 +23,7 @@ var clientTag = "Client"

var tokenUtils TokenUtils

// Inserts data into the vault.
func (client *Client) Insert(records map[string]interface{}, options ...common.InsertOptions) (common.InsertRecords, *errors.SkyflowError) {
var tempOptions common.InsertOptions
if len(options) == 0 {
Expand Down Expand Up @@ -54,6 +56,7 @@ func (client *Client) Insert(records map[string]interface{}, options ...common.I
return response, nil
}

// Returns values that correspond to the specified tokens.
func (client *Client) Detokenize(records map[string]interface{}) (common.DetokenizeRecords, *errors.SkyflowError) {

if client.configuration.TokenProvider == nil {
Expand Down Expand Up @@ -81,6 +84,7 @@ func (client *Client) Detokenize(records map[string]interface{}) (common.Detoken
return response, nil
}

// Reveals records by Skyflow ID.
func (client *Client) GetById(records map[string]interface{}) (common.GetByIdRecords, *errors.SkyflowError) {

if client.configuration.TokenProvider == nil {
Expand Down Expand Up @@ -108,6 +112,7 @@ func (client *Client) GetById(records map[string]interface{}) (common.GetByIdRec
return response, nil
}

// Invokes a connection to an external service using the provided connection configuration.
func (client *Client) InvokeConnection(connectionConfig common.ConnectionConfig) (common.ResponseBody, *errors.SkyflowError) {

if client.configuration.TokenProvider == nil {
Expand Down
1 change: 1 addition & 0 deletions skyflow/client/init.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import (
"github.com/skyflowapi/skyflow-go/skyflow/common"
)

// Initializes the Skyflow client.
func Init(configuration common.Configuration) Client {
logger.Info(fmt.Sprintf(messages.INITIALIZING_SKYFLOW_CLIENT, clientTag))
return Client{configuration}
Expand Down
1 change: 1 addition & 0 deletions skyflow/client/token_utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import (
"github.com/skyflowapi/skyflow-go/skyflow/common"
)

// Represents a utility structure for handling bearer tokens.
type TokenUtils struct {
Token string
}
Expand Down
Loading