Skip to content

epiHATR/cloudflare-cli

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

62 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

cloudflare-cli

Communicating with Cloudflare API through command line interface

latest release go version download supports issues license

Table of Contents

  1. Introduction
  2. Features
  3. Usages
    1. Downloads
    2. Command usages
  4. Development
    1. Setup environment
    2. Add new sub command
    3. Incoming features
    4. Build with cross-compile options

Introduction

Usages

Download latest binary from github at

Downloads

Download the latest release at Cloudflare CLI release

Download one of following release zip file:

https://github.com/epiHATR/cloudflare-cli/releases/download/v0.x.x/darwin-arm64-v0.x.x.tar.gz
https://github.com/epiHATR/cloudflare-cli/releases/download/v0.x.x/linux-amd64-v0.x.x.tar.gz 
https://github.com/epiHATR/cloudflare-cli/releases/download/v0.x.x/windows-amd64-v0.x.x.zip

Installation

ubuntu/rhel
tar -xf linux-amd64-v0.x.x.tar.gz -C /usr/local/bin
sudo chmod +x /usr/local/bin/cloudflare
darwin/macos
tar -xf darwin-arm64-v0.x.x.tar.gz -C /usr/local/bin
sudo chmod +x /usr/local/bin/cloudflare
windows x64
extract windows-amd64-v0.x.x.zip to a folder
.\cloudflare.exe --help

Command Usages

command descriptions
cloudflare show cli introductions & starter command
cloudflare version display cli version and Cloudflare API version
cloudflare login login into Cloudflare API
cloudflare account manage Cloudflare accounts/organization
cloudflare account list list all Cloudflare accounts/organization
cloudflare account show show details of a cloudflare account/organization
cloudflare account update update information of a cloudflare account/organization
cloudflare account role manage all roles in cloudflare account/organization
cloudflare account role list list all roles in cloudflare account/organization
cloudflare account role show show information details of a role in cloudflare account/organization
cloudflare account user manage users in a Cloudflare account/organization
cloudflare account user add add new user to a Cloudflare account/organization
cloudflare account user list manage users in a Cloudflare account/organization
cloudflare account user show show information details of a user in a Cloudflare account/organization
cloudflare account user delete remove an user from a Cloudflare account/organization
cloudflare zone list list Cloudflare zone in account
cloudflare zone show show Cloudflare zone common information
cloudflare zone create create new Cloudflare zone
cloudflare zone delete delete a Cloudflare zone
cloudflare zone setting pause pause a cloudflare zone
cloudflare zone setting unpause unpause a cloudflare zone
cloudflare zone setting set-type set Cloudflare zone type (parital, full, delegated)
cloudflare zone cache purge control cache behavior on Cloudflare zone
cloudflare zone plan list list all Cloudflare plan for zone
cloudflare zone plan show show a Cloudflare plan details
cloudflare zone plan upgrade upgrade Cloudflare zone to a specified plan
cloudflare zone dns list list DNS records on a Cloudflare zone
cloudflare zone dns add add a DNS records on a Cloudflare zone
cloudflare zone dns show show a DNS records details of a Cloudflare zone
cloudflare zone dns update change/update DNS records value on Cloudflare zone
cloudflare zone dns delete delete a DNS records on a Cloudflare zone

cloudflare

show cli introductions & starter command

cloudflare [ --help | -h ]
           [ --debug ]

cloudflare login

Login into Cloudflare API using API Token (--token | -t) or Email/ApiKey (--email|-e and --key|-k)

cloudflare login [ --token | -t ]
                 [ --email | -e ]
                 [ --key | -k ]

#global flags                                   
                 [ --help | -h ]
                 [ --debug ]

cloudflare version

Show current CLI version and Cloudflare API version

cloudflare version [ --short | -s ]

#global flags                                   
                   [ --help | -h ]
                   [ --debug ]

cloudflare account

Manage Cloudlare managed accounts/organization

cloudflare account

#global flags                                   
                 [ --help | -h ]
                 [ --debug ]

cloudflare account list

List all Cloudlare managed accounts/organization

cloudflare account list [ --name | -n ]

#global flags               
                        [ --query | -q ]                           
                        [ --output |-o ]                    
                        [ --help | -h ]
                        [ --debug ]

cloudflare account show

Show details of a Cloudlare managed account/organization

cloudflare account show [ --account-id ]

#global flags               
                        [ --query | -q ]                           
                        [ --output |-o ]                    
                        [ --help | -h ]
                        [ --debug ]

cloudflare account update

Update information details of a Cloudlare managed account/organization See payload data at https://api.cloudflare.com/#accounts-update-account

cloudflare account update [ --account-id ]
                          [ --data | -d ]

#global flags               
                          [ --query | -q ]                           
                          [ --output |-o ]                    
                          [ --help | -h ]
                          [ --debug ]

cloudflare account role

Manage roles in a Cloudlare managed accounts/organization

cloudflare account role

#global flags               
                        [ --query | -q ]                           
                        [ --output |-o ]                    
                        [ --help | -h ]
                        [ --debug ]

cloudflare account role list

List al roles in a Cloudlare managed accounts/organization

cloudflare account role list [ --account-id ]

#global flags               
                             [ --query | -q ]                           
                             [ --output |-o ]                    
                             [ --help | -h ]
                             [ --debug ]

cloudflare account role show

Show information details of a role in a Cloudlare managed accounts/organization

cloudflare account role show [ --account-id ]
                             [ --role-id ]

#global flags               
                             [ --query | -q ]                           
                             [ --output |-o ]                    
                             [ --help | -h ]
                             [ --debug ]

cloudflare account user

Manage users in a Cloudlare managed accounts/organization

cloudflare account user

#global flags               
                        [ --query | -q ]                           
                        [ --output |-o ]                    
                        [ --help | -h ]
                        [ --debug ]

cloudflare account user list

List all users in a Cloudlare managed accounts/organization

cloudflare account user list [ --account-id ]

#global flags               
                             [ --query | -q ]                           
                             [ --output |-o ]                    
                             [ --help | -h ]
                             [ --debug ]

cloudflare account user add

Add new user to a Cloudlare managed accounts/organization

cloudflare account user add [ --account-id ]
                            [ --email ]
                            [ --status 'accepted', 'pending' ]
                            [ --role-id '--role-id=role1 --role-id=role2' ]

#global flags               
                            [ --query | -q ]                           
                            [ --output |-o ]                    
                            [ --help | -h ]
                            [ --debug ]

cloudflare account user show

Show information details of a user in a Cloudlare managed accounts/organization

cloudflare account user show [ --account-id ]
                             [ --user-id ]

#global flags               
                             [ --query | -q ]                           
                             [ --output |-o ]                    
                             [ --help | -h ]
                             [ --debug ]

cloudflare account user delete

Show information details of a user in a Cloudlare managed accounts/organization

cloudflare account user delete [ --account-id ]
                               [ --user-id ]
                               [ --force]

#global flags               
                               [ --query | -q ]                           
                               [ --output |-o ]                    
                               [ --help | -h ]
                               [ --debug ]

cloudflare zone list

List all Cloudflare zone under account

cloudflare zone list [ --account-id ]
                     [ --account-name | -n ]

#global flags       
                     [ --query | -q ]                           
                     [ --output |-o ]
                     [ --help | -h ]
                     [ --debug ]

cloudflare zone create

Create a Cloudflare zone under account

cloudflare zone create [ --name | -n ]
                       [ --account-id ]
                       [ --type | -t ]
                       [ --plan-name ]
                       [--fetch-existing-dns]
#global flags       
                       [ --query | -q ]                           
                       [ --output |-o ]
                       [ --help | -h ]
                       [ --debug ]

cloudflare zone delete

Delete a Cloudflare zone under account

cloudflare zone delete [ --zone-id ]
                       [ --force | -f ]
#global flags       
                       [ --query | -q ]                           
                       [ --output |-o ]
                       [ --help | -h ]
                       [ --debug ]

cloudflare zone show

List all Cloudflare zone under account

cloudflare zone show [ --id | -i]
                     [ --name | -n ]

#global flags       
                    [ --query | -q ]                           
                    [ --output |-o ]
                    [ --help | -h ]
                    [ --debug ]

cloudflare zone dns list

List all DNS records in a Cloudflare zone

cloudflare zone dns list [ --zone-id | -i]
                         [ --type | -t ]

#global flags       
                         [ --query | -q ]                           
                         [ --output |-o ]
                         [ --help | -h ]
                         [ --debug ]

cloudflare zone dns show

Show details of a Cloudflare DNS record

cloudflare zone dns show [ --id | -i ]
                         [ --zone-id | -i]

#global flags       
                         [ --query | -q ]                           
                         [ --output |-o ]
                         [ --help | -h ]
                         [ --debug ]

cloudflare zone dns add

Add a Cloudflare DNS record and return its result

See data payload format at [Cloudflare API documentation - create DNS record](https://api.cloudflare.com/#dns-records-for-a-zone-create-dns-record)
cloudflare zone dns add [ --zone-id ]
                        [ --data|-d ]
#global flags       
                        [ --query | -q ]                           
                        [ --output |-o ]
                        [ --help | -h ]
                        [ --debug ]

cloudflare zone dns update

Update a Cloudflare DNS record

See data payload format at [Cloudflare API documentation - create DNS record](https://api.cloudflare.com/#dns-records-for-a-zone-update-dns-record)
cloudflare zone dns delete [ --zone-id ]
                           [ --id | -i ]
                           [ --data | -d ]
                           [ --force | -f]
#global flags       
                           [ --query | -q ]                           
                           [ --output |-o ]
                           [ --help | -h ]
                           [ --debug ]

cloudflare zone dns delete

Delete a Cloudflare DNS record

cloudflare zone dns delete [ --zone-id ]
                           [ --id | -i ]
                           [ --force | -f]
#global flags       
                           [ --query | -q ]                           
                           [ --output |-o ]
                           [ --help | -h ]
                           [ --debug ]

cloudflare zone setting pause

Pause a Cloudfalre zone

cloudflare zone setting pause [ --zone-id ]

#global flags       
                              [ --query | -q ]                           
                              [ --output |-o ]
                              [ --help | -h ]
                              [ --debug ]

cloudflare zone setting unpause

UnPause a Cloudfalre zone

cloudflare zone setting unpause [ --zone-id]

#global flags       
                                [ --query | -q ]                           
                                [ --output |-o ]
                                [ --help | -h ]
                                [ --debug ]

cloudflare zone cache purge

Control cache behaviors on Cloudflare zone

cloudflare zone cache purge [ --zone-id]
                            [ --purge-everything | -A]

#global flags       
                            [ --query | -q ]                           
                            [ --output |-o ]
                            [ --help | -h ]
                            [ --debug ]

cloudflare zone setting set-type

Change Cloudflare zone type (full, partial)

cloudflare zone setting set-type [ --zone-id]
                                 [ --type| -t ]

#global flags       
                                 [ --query | -q ]                           
                                 [ --output |-o ]
                                 [ --help | -h ]
                                 [ --debug ]

cloudflare zone plan list

List all Cloudflare zone's plan

cloudflare zone zone plan list [ --zone-id]
                               [ --all-available|-a ]
                               [ --rate-plan-only ]
#global flags       
                               [ --query | -q ]                           
                               [ --output |-o ]
                               [ --help | -h ]
                               [ --debug ]

cloudflare zone plan show

Show details of a zone's plan

cloudflare zone zone plan show [ --zone-id ]
                               [ --id | -i]
#global flags       
                               [ --query | -q ]                           
                               [ --output |-o ]
                               [ --help | -h ]
                               [ --debug ]

cloudflare zone plan upgrade

Upgrade a Clouddflare zone plan

cloudflare zone zone plan upgrade [ --zone-id ]
                                  [ --plan-id | -i]
                                  [ --plan-name | -n]
#global flags       
                                  [ --query | -q ]                           
                                  [ --output |-o ]
                                  [ --help | -h ]
                                  [ --debug ]

Development

Setup development environment

  • Install Go 1.18.5
  • Install Cobra for GO
  • Install Viper

Add sub commands

On the root folder (cloudflare-cli), type following command to generate new command

$> cobra add <command name> -p <parent command name> -a <author information>

Run command locally

On the local environment, run following command to start cli

$> go run main.go <sub command> --help

Build

Following command running on MACOS M1 which will create a release version of cloudflare-cli, targeting for: Windows exe

version="v0.x.x"
GOOS=windows GOARCH=amd64 go build -ldflags "-X cloudflare/cmd.version=$version" -o "release/windows-amd64-$version/cloudflare.exe" cloudflare
cd release/windows-amd64-$version
./cloudflare version -s
tar -cvf windows-amd64-$version.zip cloudflare.exe

For Linux 64 binary

version="v0.1.0"
GOOS=linux GOARCH=amd64 go build -ldflags "-X cloudflare/cmd.version=$version" -o "release/linux-amd64-$version/cloudflare" cloudflare
cd release/linux-amd64-$version
./cloudflare version -s
tar -czvf linux-amd64-$version.tar.gz cloudflare

For MacOS binary

version="v0.1.0"
GOOS=darwin GOARCH=arm64 go build -ldflags "-X cloudflare/cmd.version=$version" -o "release/darwin-arm64-$version/cloudflare" cloudflare
cd release/darwin-arm64-$version
./cloudflare version -s
tar -czvf darwin-arm64-$version.tar.gz cloudflare

Sponsors

This repository is sponsored by CloudCLI.io