Giter Site home page Giter Site logo

apache / airflow-client-go Goto Github PK

View Code? Open in Web Editor NEW
159.0 23.0 18.0 550 KB

Apache Airflow - OpenApi Client for Go

Home Page: https://airflow.apache.org/

License: Apache License 2.0

Go 61.09% Shell 38.91%
airflow apache apache-airflow apache-airflow-client go

airflow-client-go's Introduction

Airflow Go client

Go Airflow OpenAPI client generated from openapi spec.

Install

go get github.com/apache/airflow-client-go/airflow@latest

Usage

package main

import (
	"context"
	"fmt"
	"github.com/apache/airflow-client-go/airflow"
)

func main() {
	conf := airflow.NewConfiguration()
	conf.Host = "localhost:8080"
	conf.Scheme = "http"
	cli := airflow.NewAPIClient(conf)

	cred := airflow.BasicAuth{
		UserName: "username",
		Password: "password",
	}
	ctx := context.WithValue(context.Background(), airflow.ContextBasicAuth, cred)

	variable, _, err := cli.VariableApi.GetVariable(ctx, "foo").Execute()
	if err != nil {
		fmt.Println(err)
	} else {
		fmt.Println(variable)
	}
}

See README for full client API documentation.

airflow-client-go's People

Contributors

ajbosco avatar ashb avatar drfaust92 avatar ephraimbuddy avatar houqp avatar jedcunningham avatar mik-laj avatar pierrejeambrun avatar potiuk avatar senthilkumarkj avatar xd-deng avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

airflow-client-go's Issues

Release versions?

Could you please specify release versions?
It would be great if they can match Airflow version

Request.Execute() return `undefined response type` error

➜  ~ curl -i -X GET 'https://airflow.xxx.com/api/v1/dags/xx/dagRuns/xxx' \
-H 'Content-Type: application/json' -H 'Accept: application/json' \
--user "xxx:xxx" \
-d '{}'
HTTP/2 404
date: Wed, 01 Feb 2023 07:42:55 GMT
content-type: application/problem+json
content-length: 263
server: gunicorn
x-robots-tag: noindex, nofollow

{
  "detail": "DAGRun with DAG ID: 'xxx' and DagRun ID: 'xxx' not found",
  "status": 404,
  "title": "DAGRun not found",
  "type": "https://airflow.apache.org/docs/apache-airflow/2.5.0/stable-rest-api-ref.html#section/Errors/NotFound"
}

In airflow version 2.5.0, Content-type header in error response is application/problem+json, but in this repo the json content-type is check by regexp

jsonCheck = regexp.MustCompile(`(?i:(?:application|text)/(?:vnd\.[^;]+\+)?json)`)

The regexp can't match application/problem+json, I guess that's the problem.

About problem+json

How to set variable

Background

Currently, I am using this package for interacting with airflow. I see variable component. It has the Get method. But, I didn't see the Set method for the variable.

Proprosal Solution

  • Provide Set method for variable

Parsing of Schedule Interval fails (possibly always)

https://github.com/apache/airflow-client-go/blob/main/airflow/model_schedule_interval.go#L60-L114

This function tries to parse the data such as

{
  "__type": "CronExpression",
  "value": "0 * * * *"
}

But it always matches more than 1. This is because of two things

  1. __type is a common field all 3 structs and parsing will never result in '{}'
  2. There are other fields that are common between TimeDelta and RelativeDelta like hours, seconds etc. And rest of the fields end up being 0.

I'm sending a PR to fix this.

`go get github.com/apache/airflow-client-go@latest` yields outdated `github.com/apache/airflow-client-go/airflow` subpackage

I want to use the current version (v2.5.0), but using go get github.com/apache/airflow-client-go@latest as of today gives me v0.0.0-20230203175943-7af9875e7d4c. It definitely appears out of sync with the latest version as NewClearTaskInstance() function is missing and in addition the fields for theClearInstance struct appear out of sync with those of the current version.

go version: go1.19.5 darwin/arm64

Add tag v1.0.0 for the release version

Airflow API version is 1.0.0 (https://airflow.apache.org/docs/apache-airflow/stable/stable-rest-api-ref.html)

AFAIK, all we have to do is make a tag v1.0.0 on the repo. This should set the client version for the Go module (official docs)

Of course, before that, there should be some kind of client versioning strategy in place. One simple strategy is to follow the API version, so every time when you bump the API version, you rebuild the client. However, sometimes generated library needs an update (e.g due to a bug in the client generation). If this happens often, you might simply have independent versioning of the client, while you maintain at least the major version. In that case you must have a mapping table that indicates client version to api version matching.

Either way, the first version tag should be added :)

Trigger dag_run response: Property is read-only - 'dag_id' - 400

func workoutDagTask(workout_id int64, workout_path string) {
	cli := airflow.NewAPIClient(&airflow.Configuration{
		Scheme:   "http",
		Host:     "localhost:8080",
		BasePath: "/api/v1",
	})
	cred := airflow.BasicAuth{
		UserName: "admin",
		Password: "admin",
	}
	ctx := context.WithValue(context.Background(), airflow.ContextBasicAuth, cred)
	var dagRunRequest airflow.DagRun
	var dagRunResponse airflow.DagRun
	dagRunRequest = airflow.DagRun{
		Conf: map[string]interface{}{
			"workout_id": workout_id,
			"workout_path": workout_path,
		},
	}
	dagRunResponse, httpResponse, err := cli.DAGRunApi.PostDagRun(ctx, "workout_dag", dagRunRequest)
	if err != nil {
		fmt.Println(err, httpResponse)
	} else {
		fmt.Println(dagRunResponse)
	}
}

httpResponse: 400 Bad Request

{
"detail": "Property is read-only - 'dag_id'",
"status": 400,
"title": "Bad Request",
"type": "https://airflow.apache.org/docs/2.0.1/stable-rest-api-ref.html#section/Errors/BadRequest"
}

Model DagRun : dag_id default "", but rest-api can not receive dag_id argument ?

Add LICENSE file to the repo

Currently the repo has no license file and pkg.go.dev isn't displaying the documentation for the package. Clarifying the license would also encourage the usage of the client.

The individual files say the file is available under Apache 2.0 license, so I presume this is the license we'd want to add to the repo as well.

(I've created a PR for this. I'm unsure how to notify, so creating an issue and linking it to resolve.)

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.