OVHSDK 0.3.6

There is a newer version of this package available.
See the version list below for details.
dotnet add package OVHSDK --version 0.3.6                
NuGet\Install-Package OVHSDK -Version 0.3.6                
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="OVHSDK" Version="0.3.6" />                
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add OVHSDK --version 0.3.6                
#r "nuget: OVHSDK, 0.3.6"                
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
// Install OVHSDK as a Cake Addin
#addin nuget:?package=OVHSDK&version=0.3.6

// Install OVHSDK as a Cake Tool
#tool nuget:?package=OVHSDK&version=0.3.6                

NuGet Version

Authentication

There are three ways to authenticate with OVH:

  • Application key, application secret, and consumer key
  • Client ID and Client Secret
  • Token

There is an authentication implementation for each method:

  • Ovh.Sdk.Net.AuthProviders.Application
  • Ovh.Sdk.Net.AuthProviders.OAuth2
  • Ovh.Sdk.Net.AuthProviders.Token

Refer to the examples for usage.

Samples

SA creation, attach policy and SA login

using _iam_policy;
using _oauth2;
using Ovh.Sdk.Net;
using Ovh.Sdk.Net.AuthProviders;
using Action = _iam_policy.Action;

// Login with an application

// Fetch credentials from environment variables (OVH_APPLICATION_KEY, OVH_APPLICATION_SECRET, OVH_CONSUMER_KEY)
var applicationProvider = new Application();

// Uncomment this line to log all requests and responses
//var handler = new LogHandler(new HttpClientHandler());
var handler = new HttpClientHandler();

var adminClient = new Client(new HttpClient(handler)
{
    BaseAddress = new Uri("https://eu.api.ovh.com"),
}, applicationProvider);

// Create a service account

var serviceAccount = await adminClient.PostV1MeApiOauth2ClientAsync(new clientRequest
{
    Name = "ProjectViewer",
    Description = "Service account to view all projects",
    CallbackUrls = [],
    Flow = ClientFlowEnum.CLIENT_CREDENTIALS,
});
var saInfos = await adminClient.GetV1MeApiOauth2ClientClientIdAsync(serviceAccount.ClientId);

// Upsert the policy for the service account

var activePolicies = await adminClient.GetV2IamPolicyAsync();
var policy = activePolicies.FirstOrDefault(x => x.Name == "OvhSdkNet_Sample");
if (policy == null)
{
    policy = await adminClient.PostV2IamPolicyAsync(new Creation
    {
        Description = "View all projects",
        Identities = [saInfos.Identity],
        Name = "OvhSdkNet_Sample",
        Permissions = new Permissions
        {
            Allow =
            [
                new Action
                {
                    _Action = "publicCloudProject:apiovh:get"
                }
            ]
        },
        Resources = [new Resource { Urn = "urn:v1:eu:resource:publicCloudProject:*" }]
    });
}
else
{
    await adminClient.PutV2IamPolicyPolicyIdAsync(new Update
    {
        Description = "View all projects",
        Identities = [saInfos.Identity],
        Name = "OvhSdkNet_Sample",
        Permissions = new Permissions
        {
            Allow =
            [
                new Action
                {
                    _Action = "publicCloudProject:apiovh:get"
                }
            ]
        },
        Resources = [new Resource { Urn = "urn:v1:eu:resource:publicCloudProject:*" }]
    }, policy.Id);
}

// Login with the service account

var oauthProvider = new OAuth2(serviceAccount.ClientId, serviceAccount._ClientSecret, "https://www.ovh.com/auth/oauth2/token");

var serviceAccountClient = new Client(new HttpClient(handler)
{
    BaseAddress = new Uri("https://eu.api.ovh.com"),
}, oauthProvider);

// Get all projects with our new service account

var projects = await serviceAccountClient.GetV1CloudProjectAsync();
foreach (var project in projects)
{
    var projectInfo = await serviceAccountClient.GetV1CloudProjectServiceNameAsync(project);
    Console.WriteLine($"{project}: {projectInfo.Description}");
}

// Cleanup the service account and policy

await adminClient.DeleteV2IamPolicyPolicyIdAsync(policy.Id);
await adminClient.DeleteV1MeApiOauth2ClientClientIdAsync(serviceAccount.ClientId);
Product Compatible and additional computed target framework versions.
.NET net8.0 is compatible.  net8.0-android was computed.  net8.0-browser was computed.  net8.0-ios was computed.  net8.0-maccatalyst was computed.  net8.0-macos was computed.  net8.0-tvos was computed.  net8.0-windows was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.
  • net8.0

    • No dependencies.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last updated
0.3.42 36 11/28/2024
0.3.41 64 11/27/2024
0.3.40 68 11/26/2024
0.3.39 77 11/23/2024
0.3.38 79 11/22/2024
0.3.37 64 11/21/2024
0.3.36 66 11/20/2024
0.3.35 70 11/19/2024
0.3.34 73 11/16/2024
0.3.33 74 11/14/2024
0.3.32 69 11/13/2024
0.3.31 79 11/8/2024
0.3.30 74 11/7/2024
0.3.29 70 11/6/2024
0.3.28 73 11/5/2024
0.3.27 84 11/2/2024
0.3.26 76 11/1/2024
0.3.25 70 10/31/2024
0.3.24 65 10/30/2024
0.3.23 72 10/29/2024
0.3.22 80 10/28/2024
0.3.21 78 10/27/2024
0.3.20 70 10/26/2024
0.3.19 69 10/25/2024
0.3.18 75 10/23/2024
0.3.17 75 10/22/2024
0.3.16 107 10/19/2024
0.3.15 107 10/18/2024
0.3.14 79 10/17/2024
0.3.13 74 10/16/2024
0.3.12 79 10/15/2024
0.3.11 78 10/14/2024
0.3.10 79 10/13/2024
0.3.9 87 10/11/2024
0.3.8 81 10/10/2024
0.3.7 85 10/9/2024
0.3.6 77 10/8/2024
0.3.5 94 10/2/2024
0.3.4 106 10/1/2024
0.3.3 90 10/1/2024
0.3.2 93 9/30/2024
0.3.1 96 9/28/2024