Code Monkey home page Code Monkey logo

gocloak-retry-channels's Introduction

go-http-poller

Run app

Export envs

export CLIENT_ID=xxx
export [email protected]
export PASSWORD=strongPassword
export AUTH_URL=https://keycloak.url
export REALM=master
go mod tidy

go run main.go consumer.go producer.go
# or build
go build -o .app

Keycloak module

classDiagram

TokenJWT "1" *-- "0..1" JWT: Contains

class TokenJWT{
    <<struct>>
    +chan[int] RenewRequest
    -timeTime lastRenewRequest
    -gocloakGoCloak client
    -contextContext ctx
    -syncMutex mu
    -client_id string
    -realm string
    -username string
    -password string

    +New(ctx context.Context, auth_url string, client_id string, realm string, username string, password string) (*TokenJWT, error)
    -login() error
    -refresh() error
    +GetToken() *JWT
    -getRenewTime() timeDuration
    +RenewToken(wg *sync.WaitGroup)
    -renewTokenWithRetry() error
}

example usage

func main() {
	// Set up cancellation context and waitgroup
	ctx, cancelFunc := context.WithCancel(context.Background())
	wg := &sync.WaitGroup{}

	token, err := keycloak.New(
		ctx,
		os.Getenv("AUTH_URL"),
		os.Getenv("CLIENT_ID"),
		os.Getenv("REALM"),
		os.Getenv("USERNAME"),
		os.Getenv("PASSWORD"))
	if err != nil {
		panic(err)
	}
	// // Start keycloak token control and Add [workerPoolSize] to WaitGroup
	wg.Add(1)
	go token.RenewToken(wg)

    // Handle sigterm and await termChan signal
	termChan := make(chan os.Signal)
	signal.Notify(termChan, syscall.SIGINT, syscall.SIGTERM)

	<-termChan // Blocks here until interrupted

	// Handle shutdown
	fmt.Println("*********************************\nShutdown signal received\n*********************************")
	cancelFunc() // Signal cancellation to context.Context
	wg.Wait()    // Block here until are workers are done

	fmt.Println("All workers done, shutting down!")
}

Data completeness validator

Conception

classDiagram

class OdataInput{
    Load()
}

class CSVInput{
    Load()
}

class PsqlInput{
    Load()
}

class LoadInputData{
    <<interface>>
    Load()
}

class DataCompletenessValidator{
    
    
}


class OutputFactory {
    
}

class PsqlStore{
    <<interface>>
}

class FileStore{
    <<interface>>
}
DataCompletenessValidator ..> LoadInputData
LoadInputData ..> OdataInput
LoadInputData ..> CSVInput
LoadInputData ..> PsqlInput
DataCompletenessValidator ..> OutputFactory
OutputFactory ..> PsqlStore
OutputFactory ..> FileStore

Output

Continuous monitoring

graph TD
    A[Start] --> B{"if object <IDENTIFIER> is assigned to sourceA?"};
    B -- Yes --> C[Done];
    B -- No ----> D{if source == A};
    D -- Yes --> E[Assign sourceA to <IDENTIFIER>];
    E --> F[Mark <IDENTIFIER> as assigned];
    F --> C;
    D -- No --> G[Assign sourceB to <IDENTIFIER>];
    G --> C;

Simple solution

  • set(SourceA) - set(SourceA)

Bibliography

Helpful websites used during the work on this project

gocloak-retry-channels's People

Contributors

pawelmarkowski avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.