- 
                Notifications
    You must be signed in to change notification settings 
- Fork 5
Introduce network-group API #80
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
  
     Closed
                    Changes from all commits
      Commits
    
    
  File filter
Filter by extension
Conversations
          Failed to load comments.   
        
        
          
      Loading
        
  Jump to
        
          Jump to file
        
      
      
          Failed to load files.   
        
        
          
      Loading
        
  Diff view
Diff view
There are no files selected for viewing
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
              
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
              
              
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
              | Original file line number | Diff line number | Diff line change | 
|---|---|---|
| @@ -0,0 +1,25 @@ | ||
| use core::{error::Error, fmt}; | ||
|  | ||
| use serde::{Deserialize, Serialize}; | ||
|  | ||
| #[derive(Debug, Clone, Serialize, Deserialize)] | ||
| pub struct ResponseError { | ||
| #[serde(rename = "id")] | ||
| pub id: u32, | ||
| #[serde(rename = "message")] | ||
| pub message: String, | ||
| #[serde(rename = "type")] | ||
| pub kind: String, | ||
| } | ||
|  | ||
| impl fmt::Display for ResponseError { | ||
| fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { | ||
| write!( | ||
| f, | ||
| "got response {} ({}), {}", | ||
| self.kind, self.id, self.message | ||
| ) | ||
| } | ||
| } | ||
|  | ||
| impl Error for ResponseError {} | 
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
              
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
              
              
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
              | Original file line number | Diff line number | Diff line change | 
|---|---|---|
| @@ -0,0 +1,103 @@ | ||
| use oauth10a::client::reqwest::StatusCode; | ||
| use serde::{Deserialize, Serialize}; | ||
|  | ||
| pub type HttpOutput = (StatusCode, HttpError); | ||
|  | ||
| mod http_error_context { | ||
| use std::collections::HashMap; | ||
|  | ||
| use serde::{Deserialize, Serialize}; | ||
|  | ||
| #[derive(Debug, Deserialize, Serialize)] | ||
| pub struct Empty; | ||
|  | ||
| #[derive(Debug, Deserialize, Serialize)] | ||
| pub struct FieldError { | ||
| #[serde(rename = "value")] | ||
| value: String, | ||
| #[serde(rename = "reason")] | ||
| reason: Option<String>, | ||
| } | ||
|  | ||
| #[derive(Debug, Deserialize, Serialize)] | ||
| pub struct Field { | ||
| #[serde(rename = "name")] | ||
| name: String, | ||
| #[serde(rename = "error")] | ||
| error: FieldError, | ||
| } | ||
|  | ||
| #[derive(Debug, Deserialize, Serialize)] | ||
| pub struct GatewayError { | ||
| #[serde(rename = "originalStatus")] | ||
| original_status: i32, | ||
| #[serde(rename = "originalBody")] | ||
| original_body: String, | ||
| } | ||
|  | ||
| #[derive(Debug, Deserialize, Serialize)] | ||
| pub struct Input { | ||
| #[serde(rename = "names")] | ||
| names: Vec<String>, | ||
| } | ||
|  | ||
| type MapFieldError = HashMap<String, FieldError>; | ||
|  | ||
| #[derive(Debug, Deserialize, Serialize)] | ||
| pub struct MultipleFields { | ||
| #[serde(rename = "fields")] | ||
| fields: MapFieldError, | ||
| } | ||
|  | ||
| #[derive(Debug, Deserialize, Serialize)] | ||
| pub struct Resource { | ||
| #[serde(rename = "kind")] | ||
| kind: String, | ||
| #[serde(rename = "name")] | ||
| name: String, | ||
| } | ||
|  | ||
| #[derive(Debug, Deserialize, Serialize)] | ||
| pub struct Operation { | ||
| #[serde(rename = "operation")] | ||
| operation: String, | ||
| #[serde(rename = "kind")] | ||
| kind: String, | ||
| #[serde(rename = "name")] | ||
| name: Option<String>, | ||
| } | ||
|  | ||
| #[derive(Debug, Deserialize, Serialize)] | ||
| pub struct Selector { | ||
| #[serde(rename = "path")] | ||
| path: Vec<String>, | ||
| } | ||
| } | ||
|  | ||
| #[derive(Debug, Deserialize, Serialize)] | ||
| #[serde(untagged)] | ||
| pub enum HttpErrorContext { | ||
| Empty(http_error_context::Empty), | ||
| Field(http_error_context::Field), | ||
| Gateway(http_error_context::GatewayError), | ||
| Input(http_error_context::Input), | ||
| MultipleFields(http_error_context::MultipleFields), | ||
| Operation(http_error_context::Operation), | ||
| Resource(http_error_context::Resource), | ||
| Selector(http_error_context::Selector), | ||
| } | ||
|  | ||
| #[derive(Debug, Deserialize, Serialize)] | ||
| pub struct HttpError { | ||
| #[serde(rename = "apiRequestId")] | ||
| pub api_request_id: String, | ||
| #[serde(rename = "code")] | ||
| pub code: String, | ||
| #[serde(rename = "context")] | ||
| pub context: HttpErrorContext, | ||
| #[serde(rename = "error")] | ||
| pub error: String, | ||
| } | ||
|  | ||
| // TODO: unit tests | ||
| // maybe use https://github.com/Orange-OpenSource/hurl or something | 
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
              
              
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
              | Original file line number | Diff line number | Diff line change | 
|---|---|---|
| @@ -0,0 +1,32 @@ | ||
| use oauth10a::client::{ClientError, RestClient}; | ||
| use tracing::debug; | ||
|  | ||
| use crate::Client; | ||
|  | ||
| use super::{OwnerId, network_group_id::NetworkGroupId, peer::PeerId}; | ||
|  | ||
| #[derive(thiserror::Error, Debug)] | ||
| pub enum Error { | ||
| #[error("failed to delete for owner '{0}', network group '{1}', peer id '{2}', {0}")] | ||
| Delete(String, NetworkGroupId, PeerId, ClientError), | ||
| } | ||
|  | ||
| pub async fn delete( | ||
| client: &Client, | ||
| owner_id: &OwnerId, | ||
| ng_id: &NetworkGroupId, | ||
| peer_id: PeerId, | ||
| ) -> Result<(), Error> { | ||
| let endpoint = format!( | ||
| "{}/v4/networkgroups/organisations/{owner_id}/networkgroups/{ng_id}/external-peers/{peer_id}", | ||
| client.endpoint, | ||
| ); | ||
|  | ||
| #[cfg(feature = "tracing")] | ||
| debug!("execute a request to delete peer from Network Group, endpoint: '{endpoint}'"); | ||
|  | ||
| client | ||
| .delete(&endpoint) | ||
| .await | ||
| .map_err(|e| Error::Delete(owner_id.to_owned(), *ng_id, peer_id, e)) | ||
| } | 
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
              
              | Original file line number | Diff line number | Diff line change | 
|---|---|---|
| @@ -0,0 +1,15 @@ | ||
| //! # Network Group module | ||
| //! | ||
| //! This module provide structures and helpers to interact with Clever Cloud's | ||
| //! Network Group API. | ||
| pub type MemberId = String; | ||
|  | ||
| pub type OwnerId = String; | ||
|  | ||
| pub mod delete; | ||
| pub mod network_group_id; | ||
| pub mod peer; | ||
| pub mod wannabe_external_peer; | ||
| pub mod wireguard; | ||
| pub mod wireguard_configuration; | 
      
      Oops, something went wrong.
        
    
  
      
      Oops, something went wrong.
        
    
  
  Add this suggestion to a batch that can be applied as a single commit.
  This suggestion is invalid because no changes were made to the code.
  Suggestions cannot be applied while the pull request is closed.
  Suggestions cannot be applied while viewing a subset of changes.
  Only one suggestion per line can be applied in a batch.
  Add this suggestion to a batch that can be applied as a single commit.
  Applying suggestions on deleted lines is not supported.
  You must change the existing code in this line in order to create a valid suggestion.
  Outdated suggestions cannot be applied.
  This suggestion has been applied or marked resolved.
  Suggestions cannot be applied from pending reviews.
  Suggestions cannot be applied on multi-line comments.
  Suggestions cannot be applied while the pull request is queued to merge.
  Suggestion cannot be applied right now. Please check back later.
  
    
  
    
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We have to publish a version here