ktor-client-chef

Ktor-client feature for Chef Client Authentication

License

License

Categories

Categories

CLI User Interface
GroupId

GroupId

id.jasoet
ArtifactId

ArtifactId

ktor-client-chef
Last Version

Last Version

1.0.1
Release Date

Release Date

Type

Type

jar
Description

Description

ktor-client-chef
Ktor-client feature for Chef Client Authentication
Project URL

Project URL

https://github.com/jasoet/ktor-client-chef
Source Code Management

Source Code Management

https://github.com/jasoet/ktor-client-chef

Download ktor-client-chef

How to add to project

<!-- https://jarcasting.com/artifacts/id.jasoet/ktor-client-chef/ -->
<dependency>
    <groupId>id.jasoet</groupId>
    <artifactId>ktor-client-chef</artifactId>
    <version>1.0.1</version>
</dependency>
// https://jarcasting.com/artifacts/id.jasoet/ktor-client-chef/
implementation 'id.jasoet:ktor-client-chef:1.0.1'
// https://jarcasting.com/artifacts/id.jasoet/ktor-client-chef/
implementation ("id.jasoet:ktor-client-chef:1.0.1")
'id.jasoet:ktor-client-chef:jar:1.0.1'
<dependency org="id.jasoet" name="ktor-client-chef" rev="1.0.1">
  <artifact name="ktor-client-chef" type="jar" />
</dependency>
@Grapes(
@Grab(group='id.jasoet', module='ktor-client-chef', version='1.0.1')
)
libraryDependencies += "id.jasoet" % "ktor-client-chef" % "1.0.1"
[id.jasoet/ktor-client-chef "1.0.1"]

Dependencies

compile (5)

Group / Artifact Type Version
org.jetbrains.kotlinx : kotlinx-coroutines-core jar 1.0.0
io.ktor : ktor-client-apache jar 1.0.0
io.ktor : ktor-client-gson jar 1.0.0
org.bouncycastle : bcpkix-jdk15on jar 1.60
org.bouncycastle : bcprov-jdk15on jar 1.60

Project Modules

There are no modules declared in this project.

Ktor Client Chef

Build Status JCenter Maven Central

Ktor Client Feature to enable authentication mechanism to Chef Server API.

Accessing Chef Server API require detailed and complicated auth mechanism. This Kotlin library wrap Chef Server API authentication as Ktor Client Feature.

Gradle

Add Maven Central or JCenter repository

repositories {
    jcenter()
}
repositories {
    mavenCentral()
}

Add dependency

compile 'id.jasoet:ktor-client-chef:<version>'

Maven

Add dependency

<dependency>
  <groupId>id.jasoet</groupId>
  <artifactId>ktor-client-chef</artifactId>
  <version>VERSION</version>
  <type>pom</type>
</dependency>

Usage

Simple Usage

This library provide ChefApiClient object with preconfigured Ktor Client. You can use it directly as Chef Api Client. Requires some parameter, parameter can be supplied from System Properties, file or environment variable and handled by Typesafe Config.

Name Description Type Default Required
USER_ID Chef user id string - yes
USER_PEM_LOCATION Chef user private key location string - yes
CHEF_SERVER_HOST Chef server host string - yes
CHEF_ORGANIZATION Chef organization string - no
CHEF_VERSION Chef server version string 12.22.5 no

If you set CHEF_ORGANIZATION url for request will prefixed by /organizations/<NAME>/ so you don't need to include that on your request.

Example

// Set config
System.setProperty("USER_ID", "chef-client")
System.setProperty("USER_PEM_LOCATION", "/home/chef-client/.chef/client.pem")
System.setProperty("CHEF_SERVER_HOST", "https://chef-server.jasoet.id")
System.setProperty("CHEF_ORGANIZATION", "ktor") // Optional

// HttpClient object will created lazily when invoke `ChefApiClient()`     
val nodes = ChefApiClient().get<ChefResult>("/nodes/p-postgresql-master-01")
// Fetch nested property using dot (.)
println(roles["automatic.filesystem"])

// Format result as Json string 
println(roles["automatic.filesystem"].formatted())

// Will use existing HttpClient object
val cookbooks = ChefApiClient().get<ChefResult>("/cookbooks")
println(cookbooks["apache2"])

As Ktor Client Feature

You can install this as Ktor Client Feature. This Feature will also require JsonFeature to be installed.

val client = HttpClient(HttpClientEngine) {
    install(ChefClientFeature) {
       userId = "<CHEF_USER_ID"
       userPemReader = FileReader("<USER_PEM_LOCATION>") // You can use other java.io.Reader. The reader must be open, and will be closed after use.
       serverHost = "<CHEF_SERVER_HOST>"
       organization = "<CHEF_ORGANIZATION>" // Optional, no default
       chefVersion = "<CHEF_SERVER_VERSION>" // Optional, default "12.22.5" 
    }
}

See ChefApiClient.kt as reference.

Versions

Version
1.0.1