Skip to content
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

Rustcloud Final Pull Request #5

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
173 changes: 19 additions & 154 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ RustCloud is a rust library which hides the difference between different APIs p



<img src="assets/gocloudarchitecture_new.jpg" width="650">
<img src="assets/Rustcloud.png" width="650" height="300">


## Service Types
Expand All @@ -33,160 +33,25 @@ RustCloud is a rust library which hides the difference between different APIs p

### AWS

* EC2 Compute [Link to example](examples/compute/ec2/ec2.md)
* EC2 Compute [Link to example](examples/aws/compute/ec2.md)
* EKS Compute [Link to example](examples/aws/compute/eks.md)
* EC2 Storage [Link to example](examples/storage/aws_storage/aws_storage.md)
* Amazon Elastic Container Service (Container) [Link to example](examples/container/aws_container/aws_container.md)
* Elastic Load Balancing [Link to example](examples/loadbalancer/aws_loadbalancer/aws_loadbalancer.md)
* AWS Route53 (DNS) [Link to example](examples/dns/aws_route53/aws_route53.md)
* Amazon Elastic Container Service (Container) [Link to example](examples/aws/compute/ecs.md)
* Elastic Load Balancing [Link to example](examples/aws/network/loadbalancer.md)
* AWS Route53 (DNS) [Link to example](examples/aws/network/dns.md)
* AWS DynamoDB (Database) [Link to example](examples/aws/database/dynamodb.md)
* AWS CloudWatch (Monitoring) [Link to example](examples/aws/management/monitoring.md)
* AWS IAM [Link to example](examples/aws/security/iam.md)
* AWS Keymanagement [Link to example](examples/aws/security/kms.md)

### Google

* Google Compute [Link to example](examples/compute/gce/gce.md)
* Google Compute Storage [Link to example](examples/storage/google_storage/google_storage.md)
* Google Container Service (Container) [Link to example](examples/container/google_container/google_container.md)
* Google Elastic Load Balancing [Link to example](examples/loadbalancer/google_loadbalancer/google_loadbalancer.md)
* Google DNS [Link to example](examples/dns/google_dns/google_dns.md)

### DigitalOcean

* DigitalOcean Droplet [Link to example](examples/compute/droplet/droplet.md)
* DigitalOcean LoadBalancer [Link to example](examples/loadbalancer/digiocean_loadbalancer/digiocean_loadbalancer.md)
* DigitalOcean Storage [Link to example](examples/storage/digiocean_storage/digiocean_storage.md)
* DigitalOcean DNS [Link to example](examples/dns/digioceandns/digioceandns.md)

### Ali-cloud

* ECS Compute [Link to example](examples/compute/ecs/ecs.md)
* ECS Storage [Link to example](examples/storage/ali_storage/ali_storage.md)
* Alibaba Cloud DNS [Link to example](examples/dns/ali_dns/ali_dns.md)
* Server Load Balancer [Link to example](examples/loadbalancer/ali_loadbalancer/ali_loadbalancer.md)
* Container Service [Link to example](examples/container/ali_container/ali_container.md)

### Vultr

* Server [Link to example](examples/compute/vultr_compute/vultr_compute.md)
* Bare Metal [Link to example](examples/baremetal/vultr_baremetal/vultr_baremetal.md)
* Block Storage [Link to example](examples/storage/vultr_storage/vultr_storage.md)
* DNS [Link to example](examples/dns/vultr_dns/vultr_dns.md)

Currently, implementations for other cloud providers are being worked on.

## Install

### Linux (Ubuntu)

1. Install golang.
```
$ sudo apt-get update -y
$ sudo apt-get install golang -y
```

2. Set GOPATH environment variable. Run `gedit ~/.bashrc`.
Copy the following in your .bashrc file:
```
export GOPATH=$HOME/gopath
export GOBIN=$HOME/gopath/bin
```

3. Test your installation by copying the following piece of code in a file. Save the file as *gotest.go*. Run the file using the command `go run gotest.go`. If that command returns “Hello World!”, then Go is successfully installed and functional.
```golang
package main
import "fmt"
func main() {
fmt.Printf("Hello World!\n")
}
```

4. Now we need to fetch the gocloud repository and other necessary packages. Run the following commands in order:
```
$ go get github.com/cloudlibz/gocloud
$ go get golang.org/x/oauth2
$ go get cloud.google.com/go/compute/metadata
```

5. Create a directory called <b>.gocloud</b> in your <b>HOME</b> directory. Download your AWS, Google and DigitalOcean access credentials and store them in a file in your <b>.gocloud</b> folder.

#### AWS:
Save your AWS credentials in a file named *amazoncloudconfig.json*.
```js
{
"AWSAccessKeyID": "xxxxxxxxxxxx",
"AWSSecretKey": "xxxxxxxxxxxx"
}
```
#### Google Cloud Services:
Save your Google Cloud credentials in a file named *googlecloudconfig.json*. The file is downloaded in the required format.
#### DigitalOcean:
Save your DigitalOcean credentials in a file named *digioceancloudconfig.json*.
```js
{
"DigiOceanAccessToken": "xxxxxxxxxxxx"
}
```
#### Ali-cloud:
Save your Ali-cloud credentials in a file named *alicloudconfig.json*.
```js
{
"AliAccessKeyID":"xxxxxxxxxxxx",
"AliAccessKeySecret":"xxxxxxxxxxxx"
}
```
#### Vultr:
Save your Vultr credentials in a file named *vultrconfig.json*.
```
{
"VultrAPIKey":"xxxxxxxxxxxx"
}
```

You can also set your credentials as environment variables.
#### AWS:
```
export AWSAccessKeyID = "xxxxxxxxxxxx"
export AWSSecretKey = "xxxxxxxxxxxx"
```
#### Google Cloud Services:
```
export PrivateKey = "xxxxxxxxxxxx"
export Type = "xxxxxxxxxxxx"
export ProjectID = "xxxxxxxxxxxx"
export PrivateKeyID = "xxxxxxxxxxxx"
export ClientEmail = "xxxxxxxxxxxx"
export ClientID = "xxxxxxxxxxxx"
export AuthURI = "xxxxxxxxxxxx"
export TokenURI = "xxxxxxxxxxxx"
export AuthProviderX509CertURL = "xxxxxxxxxxxx"
export ClientX509CertURL = "xxxxxxxxxxxx"
```
#### DigitalOcean:
```
export DigiOceanAccessToken = "xxxxxxxxxxxx"
```
#### Ali-cloud:
```
export AliAccessKeyID = "xxxxxxxxxxxx"
export AliAccessKeySecret = "xxxxxxxxxxxx"
```
#### Vultr:
```
export VultrAPIKey = "xxxxxxxxxxxx"
```

6. You are all set to use gocloud! Check out the following YouTube videos for more information and usage examples:
https://youtu.be/4LxsAeoonlY?list=PLOdfztY25UNnxK_0KRRHSngJIyVLDKZxq&t=3

## Development setup

```
$ git clone https://github.com/cloudlibz/gocloud
$ cd gocloud
```

## Unit tests

```
$ cd gocloud
$ go test -v ./...
```

<b>Please make sure to delete all your instances, storage blocks, load balancers, containers, and DNS settings once you run the tests by visiting the respective web portals of the cloud providers.</b>
* Google Compute [Link to example](examples/gcp/compute/compute_engine.md)
* Google Compute Storage [Link to example](examples/gcp/storage/storage.md)
* Google Kubernetes Service [Link to example](examples/gcp/compute/kubenetes.md)
* Google Elastic Load Balancing [Link to example](examples/gcp/network/loadbalancer.md)
* Google DNS [Link to example](examples/gcp/network/dns.md)
* Google Bigtable [Link to example](examples/gcp/database/bigtable.md)
* Google Notifications [Link to example](examples/gcp/app_services/notifications.md)

Currently, implementations for other cloud providers are being worked on.
Binary file added assets/Rustcloud.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
101 changes: 76 additions & 25 deletions rustcloud/src/gcp/gcp_apis/app_services/gcp_notification_service.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,19 +34,31 @@ impl Googlenotification {
list_topic_request = list_topic_request.query(&[("pageToken", page_token)]);
}

let token = retrieve_token().await?;
let token = retrieve_token().await.map_err(|e| format!("Failed to retrieve token: {}", e))?;
list_topic_request = list_topic_request
.header("Content-Type", "application/json")
.header(AUTHORIZATION, format!("Bearer {}", token));

let response = list_topic_request.send().await?;
let status = response.status().as_u16().to_string();
let body = response.text().await?;

let response = list_topic_request.send().await.map_err(|e| format!("Failed to send request: {}", e))?;
let status = response.status();
if !status.is_success() {
let response_text = response.text().await?;
println!("{:?}", response_text);
return Err(format!("Request failed with status: {}", status).into());
}

// Parse the response body
let body = response
.text()
.await
.map_err(|e| format!("Failed to read response body: {}", e))?;

println!("{:?}", body);

let mut list_topic_response = HashMap::new();
list_topic_response.insert("status".to_string(), status);
list_topic_response.insert("status".to_string(), status.as_u16().to_string());
list_topic_response.insert("body".to_string(), body);

println!("{:?}",list_topic_response);
Ok(list_topic_response)
}

Expand All @@ -58,20 +70,33 @@ impl Googlenotification {
let topic = request.get("Topic").expect("Topic is required");
let url = format!("{}/v1/projects/{}/topics/{}", self.base_url, project, topic);

let token = retrieve_token().await?;
let token = retrieve_token().await.map_err(|e| format!("Failed to retrieve token: {}", e))?;
let response = self
.client
.request(Method::GET, &url)
.header("Content-Type", "application/json")
.header(AUTHORIZATION, format!("Bearer {}", token))
.send()
.await?;

let status = response.status().as_u16().to_string();
let body = response.text().await?;
.await
.map_err(|e| format!("Failed to send request: {}", e))?;

let status = response.status();
if !status.is_success() {
let response_text = response.text().await?;
println!("{:?}", response_text);
return Err(format!("Request failed with status: {}", status).into());
}

// Parse the response body
let body = response
.text()
.await
.map_err(|e| format!("Failed to read response body: {}", e))?;

println!("{:?}", body);

let mut get_topic_response = HashMap::new();
get_topic_response.insert("status".to_string(), status);
get_topic_response.insert("status".to_string(), status.as_u16().to_string());
get_topic_response.insert("body".to_string(), body);

Ok(get_topic_response)
Expand All @@ -85,20 +110,33 @@ impl Googlenotification {
let topic = request.get("Topic").expect("Topic is required");
let url = format!("{}/v1/projects/{}/topics/{}", self.base_url, project, topic);

let token = retrieve_token().await?;
let token = retrieve_token().await.map_err(|e| format!("Failed to retrieve token: {}", e))?;
let response = self
.client
.request(Method::DELETE, &url)
.header("Content-Type", "application/json")
.header(AUTHORIZATION, format!("Bearer {}", token))
.send()
.await?;

let status = response.status().as_u16().to_string();
let body = response.text().await?;
.await
.map_err(|e| format!("Failed to send request: {}", e))?;

let status = response.status();
if !status.is_success() {
let response_text = response.text().await?;
println!("{:?}", response_text);
return Err(format!("Request failed with status: {}", status).into());
}

// Parse the response body
let body = response
.text()
.await
.map_err(|e| format!("Failed to read response body: {}", e))?;

println!("{:?}", body);

let mut delete_topic_response = HashMap::new();
delete_topic_response.insert("status".to_string(), status);
delete_topic_response.insert("status".to_string(), status.as_u16().to_string());
delete_topic_response.insert("body".to_string(), body);

Ok(delete_topic_response)
Expand All @@ -115,21 +153,34 @@ impl Googlenotification {
let create_topic_json_map: HashMap<String, String> = HashMap::new();
let create_topic_json = json!(create_topic_json_map).to_string();

let token = retrieve_token().await?;
let token = retrieve_token().await.map_err(|e| format!("Failed to retrieve token: {}", e))?;
let response = self
.client
.request(Method::PUT, &url)
.header("Content-Type", "application/json")
.header(AUTHORIZATION, format!("Bearer {}", token))
.body(create_topic_json)
.send()
.await?;

let status = response.status().as_u16().to_string();
let body = response.text().await?;
.await
.map_err(|e| format!("Failed to send request: {}", e))?;

let status = response.status();
if !status.is_success() {
let response_text = response.text().await?;
println!("{:?}", response_text);
return Err(format!("Request failed with status: {}", status).into());
}

// Parse the response body
let body = response
.text()
.await
.map_err(|e| format!("Failed to read response body: {}", e))?;

println!("{:?}", body);

let mut create_topic_response = HashMap::new();
create_topic_response.insert("status".to_string(), status);
create_topic_response.insert("status".to_string(), status.as_u16().to_string());
create_topic_response.insert("body".to_string(), body);

Ok(create_topic_response)
Expand Down
Loading